登录功能求指导

浏览:624 发布日期:2018/09/13 分类:求助交流
登录功能求指导

求助前辈门 看看是否有逻辑问题<?php
namespace app\admin\controller;
use think\Validate;
use think\facade\Cache;
use think\facade\Session;
use think\facade\Cookie;
use think\facade\Request;
use app\common\model\AdminModel;
class ApiController extends AdminBase
{
    public function __construct(){
        parent::__construct();
        if(!Request::isAjax()){
            $this->error('请勿非法操作');
        }
    }

    public function post_login_check(){
        $email = Request::post('email');
        $password = Request::post('password');
        $validate = Validate::make(['email' =>  'email|token','captcha|验证码'=>'require|captcha'],['email.token' => '请勿恶意重复提交!']);
        if (!$validate->check(Request::post())) {
            return json(['code'=>1,'data'=>$validate->getError()]);
        }
        if(!$user = AdminModel::get_UserInfo_Find(['email'=>$email])){
            return json(['code'=>1,'data'=>'账号错误']);
        }
        if(empty($user['state'])){
            return json(['code'=>1,'data'=>'您的账号已被禁用!']);
        }
        if (password_verify($password, $user['password'])) {
            $data = array('lastip'=>Request::ip(),'lasttime'=>time());
            $info = AdminModel::where('userid',$user['userid'])->inc('num')->update($data);
            if($info){
                Session::set('adminLogin',$user,'serviceAdmin');
                Cookie::forever('adminLogin',$user);
                return json(['code'=>0,'data'=>'登陆成功','time'=>1500,'url'=>URL('/admin/')]);
            }else{
                return json(['code'=>1,'data'=>'登录失败']);
            }
        } else {
            return json(['code'=>1,'data'=>'密码错误']);
        }
    }
}
最佳答案
评论( 相关
后面还有条评论,点击查看>>