Exemplo n.º 1
0
 public function login($username = null, $password = null, $verify = null, $autologin = false)
 {
     if (IS_POST || $autologin) {
         /* 检测验证码 TODO: */
         if (!check_verify($verify) && !$autologin) {
             $this->error('验证码输入错误!');
         }
         $uid = D('Member')->login($username, $password);
         if (0 < $uid) {
             //UC登录成功//把用户密码加密保存到cookie中
             if (!$autologin) {
                 $u['u'] = ainiku_encrypt($username);
                 $u['p'] = ainiku_encrypt($password);
                 //如果有验证码的话就再次设置记录时间cookie
                 $a = I('post.remember');
                 $b = 0;
                 switch ($a) {
                     case 1:
                         $b = 24 * 3600;
                         break;
                     case 2:
                         $b = 24 * 3600 * 7;
                         break;
                     case 3:
                         $b = 24 * 3600 * 30;
                         break;
                     default:
                         $b = -1;
                 }
                 cookie('__uid__', $u, $b);
             }
             return $autologin ? $uid : $this->success('登录成功!', U('Index/index'));
         } else {
             //登录失败
             //清空cookie
             cookie('__uid__', null);
             switch ($uid) {
                 case -1:
                     $error = '用户不存在或被禁用!';
                     break;
                     //系统级别禁用
                 //系统级别禁用
                 case -2:
                     $error = '密码错误!';
                     break;
                 default:
                     $error = L('_UNKNOWN_ERROR_');
                     break;
                     // 0-接口参数错误(调试阶段使用)
             }
             return $autologin ? false : $this->error($error);
         }
     } else {
         if (is_login()) {
             redirect(U('Index/index'));
         } else {
             $this->display();
         }
     }
 }
Exemplo n.º 2
0
 public function login($username = null, $password = null, $verify = null, $autologin = false)
 {
     if (IS_POST || $autologin) {
         /* 检测验证码 TODO: */
         if (!check_verify($verify) && !$autologin) {
             $this->error('验证码输入错误!');
         }
         //自动判断用户名是哪个字段的
         $map[get_account_type($username)] = $username;
         $map['password'] = ainiku_ucenter_md5($password);
         $map['status'] = 1;
         //$map['member_group_id']=1;
         $map['is_adminlogin'] = 1;
         $user = D('MemberView')->where($map)->find();
         if (empty($user)) {
             //登录失败
             cookie('__uid__', null);
             return $autologin ? false : $this->error('用户名或密码错误!');
         } else {
             //登陆成功
             /* 记录登录SESSION和COOKIES */
             $auth = array('uid' => $user['member_id'], 'username' => $user['username'], 'last_login_time' => $user['update_time']);
             session('user_auth', $auth);
             session('uinfo', $user);
             session('user_auth_sign', data_auth_sign($auth));
             //更新用户登录信息
             $this->updateLogin($user['member_id']);
             //把用户密码加密保存到cookie中
             if (!$autologin) {
                 $u['u'] = ainiku_encrypt($username);
                 $u['p'] = ainiku_encrypt($password);
                 //如果有验证码的话就再次设置记录时间cookie
                 $a = I('post.remember');
                 $b = 0;
                 switch ($a) {
                     case 1:
                         $b = 24 * 3600;
                         break;
                     case 2:
                         $b = 24 * 3600 * 7;
                         break;
                     case 3:
                         $b = 24 * 3600 * 30;
                         break;
                     default:
                         $b = -1;
                 }
                 cookie('__uid__', $u, $b);
             }
             return $autologin ? $user['member_id'] : $this->success('登录成功!', U($user['admin_index'], array('mainmenu' => 'true')));
         }
     } else {
         if (is_login() || $this->autologin()) {
             $user = session('uinfo');
             redirect(U($user['admin_index'], array('mainmenu' => 'true')));
         } else {
             $this->display();
         }
     }
 }