(Thinkphp3.2)TP3.2登录验证

public function check_login($code='',$password='',$account='')

{

$account = I('account');

$pw = I('password');

// $verify=I('verify');

if ($account =='' || $pw == '') {

$this->error('请输入用户名或密码');

return;

}

$verify = new \Think\Verify();

$ckcode = $verify->check($code, '');

if (!$ckcode) {

$this->error('验证码错误!');

}

$User = D('User');

$map['account'] = $account;

$map['password'] = md5($pw);

$u = $User->where($map)->find();

//检查用户的角色组是否禁用

$role_where['rid'] = $u['rid'];

$roleData = D('Role')->where($role_where)->find();

if($roleData['status'] == 0) {

$this->error($roleData['name'].'已被禁止访问');

}

if ($u) {

if (!$u['status']) {

$this->error('该用户已被锁定!');

}

unset($map);

unset($data);

$map['id'] = $u['id'];

$data['last_login_ip'] = get_client_ip();

$data['last_login_time'] = time();

$data['login_count'] = $u['login_count'] + 1;

$User->where($map)->save($data);

session('login_time',$data['last_login_time']);

session('login_ip',$data['last_login_ip']);

session('uid',$u['id']);

session('nickname',$u['name']);

session('account',$u['account']);

session('rid',$u['rid']);

session('area',$u['area']);

session('area_code',$u['area_code']);

if ($u['user_type'] == 'admin') {

$this->success('登陆成功',U('Admin/Index/index'));

}

}else{

$this->error('用户名或密码错误');

}

}

你可能感兴趣的:((Thinkphp3.2)TP3.2登录验证)