示例#1
0
 /**
  * 跳到重置密码
  */
 public function toResetPass()
 {
     $key = I('key');
     $keyFactory = new \Think\Crypt();
     $key = $keyFactory->decrypt($key, C('SESSION_PREFIX'));
     $key = explode('_', $key);
     if (time() > floatval($key[2]) + 30 * 60) {
         $this->error('连接已失效!');
     }
     if (intval($key[1]) == 0) {
         $this->error('无效的用户!');
     }
     session('REST_userId', $key[1]);
     session('REST_Time', $key[2]);
     session('REST_success', '1');
     $this->display('default/forget_pass3');
 }
 public function login()
 {
     if (IS_AJAX) {
         if (check_verify(I('post.verify'), 1)) {
             $Member = M('Member');
             $is_email = $Member->regex(I('post.username'), 'email');
             if ($is_email) {
                 $resuser = $Member->where('email=\'' . I('post.username') . '\'')->find();
             } else {
                 $resuser = $Member->where('username=\'' . I('post.username') . '\'')->find();
             }
             if (sys_md5(I('post.password')) == $resuser['password']) {
                 if (!$resuser['status']) {
                     $this->error(L('USER_STOP'));
                 }
                 $data = array('login_ip' => get_client_ip(), 'last_login_time' => time());
                 $saveres = $Member->where(array('id' => $resuser['id']))->save($data);
                 if ($saveres) {
                     $Member->where(array('id' => $resuser['id']))->setInc('login_count');
                 }
                 if (I('post.keep') == 'on') {
                     $crypt = new \Think\Crypt();
                     $userinfo = array('username' => $crypt->encrypt($resuser['username'], sys_md5(C('DATA_AUTH_KEY'), 'isky71'), 3600 * 24 * 15), 'password' => $crypt->encrypt($resuser['password'], sys_md5(C('DATA_AUTH_KEY'), 'CMS'), 3600 * 24 * 15));
                     $str = $crypt->encrypt(json_encode($userinfo), C('DATA_AUTH_KEY') . $__SERVER["HTTP_USER_AGENT"]);
                     cookie('member', $str, 3600 * 24 * 15);
                 }
                 session(C('USER_AUTH_KEY'), $resuser['id']);
                 session('uname', $resuser['username']);
                 $this->success(L('LOGIN_SUCCESS'), U('Index/index', $this->vl));
             } else {
                 $this->error(L('LOGIN_ERROR'));
             }
         } else {
             $this->error(L('VERIFY_ERROR'));
         }
     } else {
         if (session(C('USER_AUTH_KEY'))) {
             $this->redirect('Index/index');
         } elseif (cookie('member')) {
             $crypt = new \Think\Crypt();
             $userjson = $crypt->decrypt(cookie('member'), C('DATA_AUTH_KEY') . $__SERVER["HTTP_USER_AGENT"]);
             $userarr = json_decode($userjson, TRUE);
             foreach ($userarr as $key => $value) {
                 if ($key == 'username') {
                     $uname = $crypt->decrypt($value, sys_md5(C('DATA_AUTH_KEY'), 'isky71'));
                 }
                 if ($key == 'password') {
                     $pwd = $crypt->decrypt($value, sys_md5(C('DATA_AUTH_KEY'), 'CMS'));
                 }
             }
             $Member = M('Member');
             $ures = $Member->where('username=\'' . $uname . '\'')->find();
             if ($ures && $ures['password'] == $pwd) {
                 session(C('USER_AUTH_KEY'), $ures['id']);
                 session('uname', $ures['username']);
                 $this->redirect('Index/index');
             } else {
                 cookie(NULL);
                 $this->display();
             }
         } else {
             $this->display();
         }
     }
 }