Login.php 3.8 KB
<?php


namespace app\index\controller;


use app\admin\model\CommonUser;
use app\common\controller\Frontend;
use think\App;
use think\Request;

class Login extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';
    public function login(){
        if(Request::instance()->isPost()){
            $param=Request::instance()->param();
            if (empty($param['tel'])){
                return self::$model::js("手机号不能为空!",200);
            }
            if (empty($param['user_password'])){
                return self::$model::js("密码不能为空!",200);
            }


            $user=self::$model::checkTel($param['tel']);
            if($user){
                if($user['user_password']==$param["user_password"]){
                    $user->isUpdate(true)->save(['location'=>$param['location']]);
                    session("user",$user);
                    session("login",true);
                    return self::$model::js("登录成功",200);
                }else{
                    return self::$model::js("密码错误",500);
                }
                //手机号码已被绑定
            }else{
                return self::$model::js("该手机号码不存在",500);
            }
        }
        $this->assign("title","登录");
        $this->assign("style",1);
        return view("login/login");
    }
    public function register(){
        if(Request::instance()->isPost()){
            $param=Request::instance()->param();
            if($param['code']!=session("iscode")){
                return self::$model::js("验证码错误",500);
            }
            unset($param['code']);
            $user=self::$model::checkTel($param['tel']);
            if($user){
                //手机号码已被绑定
                return self::$model::js("手机号码已被绑定",500);
            }else{
                CommonUser::create($param);
                return self::$model::js("注册成功",200);
            }
        }
        $this->assign("title","注册");
        $this->assign("style",2);
        return view("login/login");
    }
    public function password(){
        if(Request::instance()->isPost()){
            $param=Request::instance()->param();
            $user=self::$model::checkTel($param['tel']);
            if($user){
                if($param['code']!=session("iscode")){
                    return self::$model::js("验证码错误",500);
                }else{
                    return self::$model::js($user['tel'],200);
                }
            }else{
                return self::$model::js("该手机号码不存在",500);
            }
        }
        $this->assign("title","忘记密码");
        $this->assign("style",3);
        return view("login/login");
    }
    public function next(){
        $param=Request::instance()->param();
        if(Request::instance()->isPost()){
            $user=self::$model::checkTel($param['tel']);
            if($param['password']!=$param['two_password']){
                return self::$model::js("两次密码不一致",500);
            }
            if($user){
                $data=[
                    'user_password'=>$param['password']
                ];
                $user->isUpdate("true")->save($data);
                return self::$model::js("修改成功",200);
            }else{
                return self::$model::js("该手机号吗不存在",500);
            }
        }
        $this->assign("tel",$param['tel']);
        $this->assign("title","忘记密码");
        $this->assign("style",4);
        return view("login/login");
    }
    public function getCode(){
        $post=input("post.");
        Smsset::setSms($post['tel']);
        return self::$model::js("验证码发送成功",200);
    }
}