예제 #1
0
 public function login($username = null, $password = null, $verify = null)
 {
     $error = '';
     if (IS_POST && check_verify($verify)) {
         $Man = D('Manage');
         $mid = $Man->login($username, $password);
         if ($mid > 0) {
             session('user_auth', $mid);
             session('user_auth_sign', data_auth_sign($mid));
             $this->success('登录成功!', U('Index/index'));
         } else {
             switch ($mid) {
                 case -1:
                     $error = '用户不存在或被禁用!';
                     break;
                 case -2:
                     $error = '密码错误!';
                     break;
                 default:
                     $error = '未知错误!';
                     break;
             }
         }
     } elseif (IS_POST) {
         $error = '验证码输入错误!';
     }
     $this->assign("error", $error);
     $this->display();
 }
예제 #2
0
 public function login()
 {
     if (!$this->create('', 4)) {
         return false;
     } else {
         $password = I('password');
         $user = $this->where(array('username' => I('username')))->field(true)->find();
         if (!$user['status']) {
             $this->error = '该管理员已被禁用!';
             return false;
         }
         if ($user['password'] !== password_md5($password)) {
             $this->error = '密码错误!';
             return false;
         } else {
             /* 更新登录信息 */
             $data = array('user_id' => $user['user_id'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
             //print_r($data); exit;
             $this->save($data);
             /* 记录登录SESSION和COOKIES */
             $auth = array('uid' => $user['user_id'], 'username' => $user['username'], 'last_login_time' => $user['last_login_time']);
             session('user_auth', $auth);
             session('user_auth_sign', data_auth_sign($auth));
             return true;
         }
     }
 }
예제 #3
0
 public function signin()
 {
     if (IS_POST) {
         $username = $this->_post('username');
         $password = $this->_post('password');
         $verify = $this->_post('verify');
         if (!$username || !$password || !$verify) {
             $this->error('参数错误!');
         }
         /* 检测验证码 TODO: */
         if (!Verify::check(@$verify)) {
             $this->error('验证码输入错误!');
         }
         $db = M('admins');
         $map['username'] = $username;
         $map['status'] = 1;
         $user = $db->where($map)->find();
         if (!$user) {
             $this->error('帐号不存在或被禁用');
         }
         if ($user['password'] != user_md5($password . $user['salt'])) {
             $this->error('密码错误');
         }
         $data = array('id' => $user['id'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip());
         $db->save($data);
         /* 记录登录SESSION和COOKIES */
         $auth = array('uid' => $user['id'], 'username' => $user['username'], 'last_login_time' => $data['last_login_time']);
         session('admins', $auth);
         session('admins_sign', data_auth_sign($auth));
         $this->success('登录成功,正在进入...', U('index/index'));
     } else {
         $this->redirect('index');
         exit;
     }
 }
예제 #4
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();
         }
     }
 }
예제 #5
0
 /**
  * 修改昵称提交
  * @author huajie <*****@*****.**>
  */
 public function submitNickname()
 {
     //获取参数
     $nickname = I('post.nickname');
     $password = I('post.password');
     empty($nickname) && $this->error('请输入昵称');
     empty($password) && $this->error('请输入密码');
     // 需要验证  密码
     $Member = D('Member');
     if (!$Member->verifyUser(UID, $password)) {
         $this->error('原密码不符!');
     }
     $data = $Member->create(array('nickname' => $nickname, 'password' => $password));
     if (!$data) {
         $this->error($Member->getError());
     }
     $res = $Member->where(array('uid' => UID))->save($data);
     if ($res) {
         $user = session('user_auth');
         $user['username'] = $data['nickname'];
         session('user_auth', $user);
         session('user_auth_sign', data_auth_sign($user));
         $this->success('修改昵称成功!');
     } else {
         $this->error('修改昵称失败!');
     }
 }
예제 #6
0
파일: oc.php 프로젝트: nanhuacrab/jhysns
 /**
  * synLogin  同步登陆
  * @param $get
  * @author:xjw129xjt(肖骏涛) xjt@ourstu.com
  */
 function synLogin($get)
 {
     $uid = $get['uid'];
     $username = $get['username'];
     $password = $get['password'];
     header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
     session_start();
     $check_user = $this->db->getOne("SELECT * FROM `" . $this->tablePre . "member` WHERE uid=" . $uid);
     if ($check_user) {
         require_once $this->dirpath . 'OcApi/OCenter/OCenter.php';
         $OCApi = new OCApi();
         $user = $OCApi->ocGetUserInfo("id=" . $uid . " AND password='******'");
         //验证用户
         if ($user) {
             $auth = array('uid' => $user['uid'], 'username' => $user['username'], 'last_login_time' => $user['last_login_time']);
             if ($this->thisConfig['SESSION_PREFIX']) {
                 $_SESSION[$this->thisConfig['SESSION_PREFIX']]['user_auth'] = $auth;
                 $_SESSION[$this->thisConfig['SESSION_PREFIX']]['user_auth_sign'] = data_auth_sign($auth);
             } else {
                 $_SESSION['user_auth'] = $auth;
                 $_SESSION['user_auth_sign'] = data_auth_sign($auth);
             }
         }
     }
 }
예제 #7
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['user_id'], 'username' => $user['user_name']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #8
0
 /**
  * 修改昵称提交
  * @author huajie <*****@*****.**>
  */
 public function submitNickname()
 {
     //获取参数
     $nickname = I('post.nickname');
     $password = I('post.password');
     empty($nickname) && $this->error('请输入昵称');
     empty($password) && $this->error('请输入密码');
     //密码验证
     $User = new UserApi();
     $uid = $User->login(UID, $password, 4);
     $uid == -2 && $this->error('密码不正确');
     $Member = D('Member');
     $data = $Member->create(array('nickname' => $nickname));
     if (!$data) {
         $this->error($Member->getError());
     }
     $res = $Member->where(array('uid' => $uid))->save($data);
     if ($res) {
         $user = session('user_auth');
         $user['username'] = $data['nickname'];
         session('user_auth', $user);
         session('user_auth_sign', data_auth_sign($user));
         $this->success('修改昵称成功!');
     } else {
         $this->error('修改昵称失败!');
     }
 }
예제 #9
0
파일: Auth.class.php 프로젝트: Orchild/mt
 /**
  * 用户登陆
  * @param  string $userName 用户名
  * @param  string $passWord 密码
  * @return int          是否登陆成功
  *         1 	= 用户不存在
  *         2 	= 用户已禁用
  *         3 	= 角色已禁用
  *         4 	= 密码错误
  *         5 	= 登陆成功
  */
 public static function login(string $userName, string $passWord)
 {
     $map['username'] = $userName;
     $pwd = md5($passWord);
     $model = M()->table(C('USER_AUTH_TABLE'));
     $roleTableName = C('USER_AUTH_ROLE');
     $model->alias('A')->join("LEFT JOIN {$roleTableName} B ON B.id = A.role_id");
     $model->field('A.*,B.name as role_name,B.issys as role_issys,B.status as role_status');
     $model->where($map);
     $user = $model->find();
     if (empty($user)) {
         return 1;
     }
     if ($user['status'] == false) {
         return 2;
     }
     if ($user['role_status'] == false) {
         return 3;
     }
     if ($user['password'] != $pwd) {
         return 4;
     }
     self::saveLoginInfo($user['id']);
     $auth = array('id' => $user['id'], 'username' => $user['username'], 'last_login_time' => $user['last_login_time']);
     // 		wlog(auth, $auth);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
     //wlog('session', $_SESSION);
     return 5;
 }
예제 #10
0
/**
 *前台用户判断cookie自动登陆
 */
function autologin()
{
    $user = cookie('token');
    if (empty($user)) {
        return 0;
    } else {
        $username = ainiku_decrypt($user['u']);
        $password = ainiku_ucenter_md5(ainiku_decrypt($user['p']));
        $map['uesrname'] = $username;
        $map['password'] = $password;
        $info = M('Member')->where($map)->find();
        if (empty($info)) {
            return 0;
        } else {
            /* 记录登录SESSION和COOKIES */
            $auth = array('uid' => $info['member_id'], 'username' => $info['username'], 'last_login_time' => $info['last_login_time']);
            session('user_auth', $auth);
            session('uinfo', $info);
            session('user_auth_sign', data_auth_sign($auth));
            define('UID', $info['member_id']);
            $uid = $info['member_id'];
            $ip = get_client_ip();
            $location = get_iplocation($ip);
            $data = array('member_id' => $uid, 'update_time' => NOW_TIME, 'last_login_ip' => $ip, 'last_login_adr' => $location['country'] . $location['area']);
            M('Member')->where("member_id={$uid}")->setInc('login');
            M('Member')->save($data);
            //保存用户登陆日志
            M('MemberLog')->add(array('member_id' => $uid, 'ip' => $Ip, 'adr' => $location['country'] . $location['area'], 'create_time' => NOW_TIME));
            return $uid;
        }
    }
}
예제 #11
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     $data = array('id' => $user['id'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip());
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['id'], 'username' => $user['username']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #12
0
파일: role.php 프로젝트: admpub/OpenCenter
/**
 * 获取当前用户登录的角色的标识(角色功能完成后修改)
 * @return int 角色id
 * @author 郑钟良<*****@*****.**>
 */
function get_login_role_audit()
{
    $user = session('user_auth');
    if (empty($user)) {
        return 0;
    } else {
        return session('user_auth_sign') == data_auth_sign($user) ? $user['audit'] : 0;
    }
}
예제 #13
0
/**
 * 检测用户是否登录
 * @return int
 */
function is_login()
{
    $user = session('user_auth');
    if (empty($user)) {
        return 0;
    } else {
        return session('user_auth_sign') == data_auth_sign($user) ? $user['uid'] : 0;
    }
}
예제 #14
0
/**
 * 检测用户是否登录
 * @return integer 0-未登录,大于0-当前登录用户ID
 */
function is_login()
{
    $user = session('global_user');
    if (empty($user)) {
        return 0;
    } else {
        return session('global_user_sign') == data_auth_sign($user) ? session('uid') : 0;
    }
}
예제 #15
0
 /**
  * 判断session 用户id sha1加密
  * */
 public function islogin()
 {
     $user = session('admin_user');
     if (empty($user)) {
         return FALSE;
     } else {
         return session('admin_user_sign') == data_auth_sign($user) ? $user['user_id'] : FALSE;
     }
 }
예제 #16
0
파일: Login.php 프로젝트: cjango/cwms
 /**
  * 保存登陆信息
  * @param  [type] $user
  */
 private function autoLogin($user)
 {
     $loginData = ['uid' => $user['id'], 'account' => $user['account'], 'login' => $user['login'], 'last_time' => $user['last_time'], 'last_ip' => $user['last_ip']];
     session('user_auth', $loginData);
     session('user_auth_sign', data_auth_sign($loginData));
     // 保存登陆信息
     $saveData = ['last_ip' => get_client_ip(), 'last_time' => NOW_TIME, 'login' => ['exp', '`login`+1']];
     Db::name('Member')->where('id', $user['id'])->update($saveData);
     logs('登陆成功', '', $user['id']);
 }
예제 #17
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function _myLogin($user)
 {
     /* 更新登录信息 */
     $data = array('id' => $user['id'], 'logins' => array('exp', '`logins`+1'), 'last_login' => NOW_TIME, 'last_ip' => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('id' => $user['id'], 'account' => $user['account'], 'logins' => $user['logins'], 'last_ip' => $user['last_ip']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #18
0
 /**
  * 设置登录状态、记录登录日志
  *
  * @param integer $uid
  *        	用户ID
  * @param boolean $is_remember_me
  *        	是否记录登录状态,默认为false
  * @return boolean 操作是否成功
  */
 private function _recordLogin($uid)
 {
     if (!$this->getCookieUid()) {
         cookie('QT_LOGGED_USER', $this->jiami($this->change() . ".{$uid}."));
     }
     $this->setField('last_login_time', NOW_TIME, 'uid=' . $uid);
     $auth = array('uid' => $uid, 'nickname' => get_nickname($uid), 'last_login_time' => NOW_TIME);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
     return true;
 }
예제 #19
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     //缓存增加机构ID和职位
     $auth = array('uid' => $user['uid'], 'username' => $user['nickname'], 'last_login_time' => $user['last_login_time'], 'oid' => $user['oid'], 'position' => $user['position']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #20
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 更新登录信息 */
     $data = array("uid" => $user["uid"], "login" => array("exp", "`login`+1"), "last_login_time" => NOW_TIME, "last_login_ip" => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array("uid" => $user["uid"], "username" => get_username($user["uid"]), "last_login_time" => $user["last_login_time"]);
     session("user_auth", $auth);
     session("uid", $auth["uid"]);
     session("user_auth_sign", data_auth_sign($auth));
 }
예제 #21
0
 /**
  * 自动登录用户
  *
  * @param integer $user
  *            用户信息数组
  */
 public function autoLogin($user)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => $user['nickname'], 'last_login_time' => $user['last_login_time']);
     session('uid', $user['uid']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #22
0
 private function autoLogin($model)
 {
     $last_login_at = $model['update_at'];
     $data = array('id' => $model['id'], 'login_count' => array('exp', '`login_count`+1'), 'update_at' => NOW_TIME);
     $this->save($data);
     $model['last_login_at'] = $last_login_at;
     $model['login_count'] = $model['login_count'] + 1;
     $model['update_at'] = NOW_TIME;
     unset($model['pwd']);
     session('manage_auth', $model);
     session('manage_auth_sign', data_auth_sign($model));
 }
예제 #23
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => $user['nickname'], 'last_login_time' => $user['last_login_time']);
     $auth_group_access = M("Auth_group_access")->where(array("uid" => $user['uid']))->find();
     $auth['group_id'] = $auth_group_access["group_id"];
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #24
0
 public function checklogin()
 {
     if (IS_AJAX) {
         if (empty($_POST['username'])) {
             echo json_encode(array('status' => 1, 'msg' => '账号错误'));
             exit;
         }
         if (empty($_POST['userpwd'])) {
             echo json_encode(array('status' => 1, 'msg' => '密码必须'));
             exit;
         }
         if (empty($_POST['code'])) {
             echo json_encode(array('status' => 1, 'msg' => '验证码必须'));
             exit;
         }
         if (!check_verify($_POST['code'])) {
             echo json_encode(array('status' => 1, 'msg' => '验证码错误'));
             exit;
         }
         $map['account'] = I('post.username');
         $result = D('Member')->where($map)->find();
         $loginErrorTimes = cookie('login_error_times');
         if (is_array($result) and $result['status'] == 1) {
             if ($result['password'] != think_member_md5(I('post.userpwd'), C('DATA_AUTH_KEY'))) {
                 $loginErrorTimes > 0 ? $loginErrorTimes++ : ($loginErrorTimes = 1);
                 cookie('login_error_times', $loginErrorTimes, array('expire' => 180));
                 log_write(I('post.username'), '密码错误', '失败' . get_client_ip());
                 echo json_encode(array('status' => 1, 'msg' => '密码错误'));
                 exit;
             } else {
                 $city = M('store')->field()->find($result['store_id']);
                 $auth = array('uid' => $result['uid'], 'store_id' => $result['store_id'], 'account' => $result['account'], 'username' => $result['nickname'], 'last_login_time' => $result['last_login_time'], 'last_login_ip' => $result['last_login_ip'], 'area_id' => $city['area'], 'city_id' => $city['city']);
                 session('member_auth', $auth);
                 session('member_auth_sign', data_auth_sign($auth));
                 $data = array('uid' => $result['uid'], 'login_count' => $result['login_count'] + 1, 'last_login_time' => time(), 'last_login_ip' => get_client_ip());
                 $res = D('Member')->save($data);
                 log_write(I('post.username'), '登录成功', '成功' . get_client_ip());
                 echo json_encode(array('status' => 2, 'msg' => '登录成功'));
                 exit;
             }
         } else {
             log_write(I('post.username'), '用户名错误', '失败' . get_client_ip());
             $loginErrorTimes > 0 ? $loginErrorTimes++ : ($loginErrorTimes = 1);
             cookie('login_error_times', $loginErrorTimes, array('expire' => 180));
             session('login_error_times', $loginErrorTimes);
             echo json_encode(array('status' => 1, 'msg' => '用户名错误'));
             exit;
         }
     } else {
         exit;
     }
 }
예제 #25
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
     $this->save($data);
     $map['uid'] = $user['uid'];
     $map['public_id'] = $user['token'];
     $info = D('Mpbase/MemberPublic')->where($map)->find();
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => $user['nickname'], 'token' => $user['token'], 'mp_id' => $info['id'], 'public_name' => $info['public_name'], 'last_login_time' => $user['last_login_time']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #26
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user, $remember = true)
 {
     /* 更新登录信息 */
     $data = array('uid' => $user['uid'], 'login' => array('exp', '`login`+1'), 'last_login_time' => NOW_TIME, 'last_login_ip' => get_client_ip(1));
     $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => get_username($user['uid']), 'last_login_time' => $user['last_login_time']);
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
     if (!$this->getCookieUid() && $remember) {
         $expire = 3600 * 24 * 7;
         cookie('QTV1_LOGGED_USER', $this->jiami($this->change() . ".{$user['uid']}"), $expire);
     }
 }
예제 #27
0
 public function checklogin()
 {
     if (empty($_POST['txtusername'])) {
         echo json_encode(array('status' => 1, 'msg' => '账号错误'));
         exit;
     }
     if (empty($_POST['txtuserpwd'])) {
         echo json_encode(array('status' => 1, 'msg' => '密码必须'));
         exit;
     }
     if (empty($_POST['txtcode'])) {
         echo json_encode(array('status' => 1, 'msg' => '验证码必须'));
         exit;
     }
     if (!check_verify($_POST['txtcode'])) {
         echo json_encode(array('status' => 1, 'msg' => '验证码错误'));
         exit;
     }
     $map['account'] = I('post.txtusername');
     $result = D('Manager')->where($map)->find();
     $loginErrorTimes = cookie('login_error_times');
     if (is_array($result) and $result['status'] == 1) {
         if ($result['password'] != think_manager_md5(I('post.txtuserpwd'), C('DATA_AUTH_KEY'))) {
             //if($result['password'] != I('post.txtuserpwd')){
             log_write(I('post.txtusername'), '管理登录', '失败[密码错误]' . get_client_ip());
             $loginErrorTimes > 0 ? $loginErrorTimes++ : ($loginErrorTimes = 1);
             cookie('login_error_times', $loginErrorTimes, array('expire' => 180));
             echo json_encode(array('status' => 1, 'msg' => '密码错误'));
             exit;
         } else {
             $auth_group_access = M('ManagerAuthGroupAccess')->where('uid = ' . $result['uid'])->find();
             $auth = array('uid' => $result['uid'], 'account' => $result['account'], 'username' => $result['nickname'], 'last_login_time' => $result['last_login_time'], 'last_login_ip' => $result['last_login_ip']);
             $result['uid'] == 1 ? session('user_group_id', 0) : session('user_group_id', $auth_group_access['group_id']);
             session('manage_auth', $auth);
             session('manage_auth_sign', data_auth_sign($auth));
             $data = array('uid' => $result['uid'], 'login_count' => $result['login_count'] + 1, 'last_login_time' => time(), 'last_login_ip' => get_client_ip());
             $res = D('Manager')->save($data);
             log_write(I('post.txtusername'), '管理登录', '成功' . get_client_ip());
             echo json_encode(array('status' => 2, 'msg' => '登陆成功'));
             exit;
         }
     } else {
         log_write(I('post.txtusername'), '管理登录', '失败[用户名错误]' . get_client_ip());
         $loginErrorTimes > 0 ? $loginErrorTimes++ : ($loginErrorTimes = 1);
         cookie('login_error_times', $loginErrorTimes, array('expire' => 180));
         echo json_encode(array('status' => 1, 'msg' => '用户名错误'));
         exit;
     }
 }
예제 #28
0
 /**
  * 自动登录用户
  * @param  integer $user 用户信息数组
  */
 private function autoLogin($user)
 {
     /* 更新登录信息 */
     //        $data = array(
     //            'uid'             => $user['uid'],
     //            //'login'           => array('exp', '`login`+1'),
     //            //'last_login_time' => NOW_TIME,
     //            //'last_login_ip'   => get_client_ip(1),
     //        );
     //        $this->save($data);
     /* 记录登录SESSION和COOKIES */
     $auth = array('uid' => $user['uid'], 'username' => $user['nickname'], 'last_login_time' => time());
     session('user_auth', $auth);
     session('user_auth_sign', data_auth_sign($auth));
 }
예제 #29
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;
         //用户不存在或被禁用
     }
 }
예제 #30
0
 protected function auto_login($username, $password)
 {
     $user = new UserApi();
     $uid = $user->login($username, $password);
     if (0 < $uid) {
         //UC登录成功
         $Member = M('Weixinmember')->where(array('ucmember' => $uid))->find();
         if (!empty($Member)) {
             //登录用户
             $auth = array('uid' => $Member['id'], 'username' => $Member['nickname'], 'last_login_time' => time(), 'uidtype' => 'user');
             session('P', $Member);
             session('user_auth', $auth);
             session('user_auth_sign', data_auth_sign($auth));
             return true;
         }
     }
     return false;
 }