示例#1
0
 /**
  * 用户登录认证
  * @param  string  $username 用户名
  * @param  string  $password 用户密码
  * @param  integer $type     用户名类型 (1-用户名,2-邮箱,3-手机,4-UID)
  * @return integer           登录成功-用户ID,登录失败-错误编号
  */
 public function login($username, $password, $type = 1)
 {
     $map = array();
     switch ($type) {
         case 1:
             $map['username'] = $username;
             break;
         case 2:
             $map['email'] = $username;
             break;
         case 3:
             $map['mobile'] = $username;
             break;
         case 4:
             $map['id'] = $username;
             break;
         default:
             return 0;
             //参数错误
     }
     /* 获取用户数据 */
     $user = $this->where($map)->find();
     /* 获取用户组数据 */
     $group = $this->getUserGroup($user['id']);
     if (empty($group) || $group['status'] != 1) {
         return -3;
     }
     if (is_array($user) && $user['status']) {
         /* 验证用户密码 */
         if (think_md5($password, C('UC_AUTH_KEY')) === $user['password']) {
             /* 记录登录SESSION和COOKIES */
             $auth = array('uid' => $user['id'], 'username' => $user['username'], 'loginTime' => $user['loginTime'], 'group' => $group['title'], 'groupId' => $group['id']);
             session('user_auth', $auth);
             session('user_auth_sign', data_auth_sign($auth));
             $this->updateLogin($user['id']);
             //更新用户登录信息
             return $user['id'];
             //登录成功,返回用户ID
         } else {
             return -2;
             //密码错误
         }
     } else {
         return -1;
         //用户不存在或被禁用
     }
 }
示例#2
0
 public function editHandle()
 {
     $id = I('id', '0', 'int');
     $data['username'] = I('username', '', 'trim');
     $data['mobile'] = I('mobile', '', 'trim');
     $data['email'] = I('email', '', 'trim');
     $data['status'] = I('status', '0', 'int');
     $group = I('group', '0', 'int');
     if (empty($data['username'])) {
         $this->wrong('请填写账号');
     }
     if (!empty($_POST['password'])) {
         $data['password'] = think_md5($_POST['password'], C('UC_AUTH_KEY'));
     }
     if ($group == 0) {
         $this->wrong('请选择分组');
     }
     if (!check_mobile($data['mobile'])) {
         $this->wrong('手机格式不正确');
     }
     if (!check_email($data['email'])) {
         $this->wrong('邮箱格式不正确');
     }
     if ($this->checkName($data['username']) && $id != $this->checkName($data['username'])) {
         $this->wrong('该账号已存在');
     }
     $data['updateTime'] = time();
     if (M('auth_group_access')->where(array('uid' => $id))->find()) {
         $rel = M('auth_group_access')->where(array('uid' => $id))->setfield('group_id', $group);
     } else {
         $rel = M('auth_group_access')->add(array('uid' => $id, 'group_id' => $group));
     }
     if ($rel || M('users')->where(array('id' => $id))->save($data)) {
         $this->ok('修改成功');
     } else {
         $this->wrong('没有任何修改');
     }
 }
示例#3
0
 public function resetpwd($id)
 {
     $status = $this->where(array('id' => $id))->save(array('pwd' => think_md5('1234'), 'update_at' => NOW_TIME));
     return array('status' => $status ? 1 : 0, 'info' => $status ? '成功' : '失败');
 }