/**
  * 提供修改密码功能
  */
 public function pwd()
 {
     if (IS_POST) {
         $oldpwd = Util::getSafeText(trim(I('post.oldpwd')));
         $pwd = Util::getSafeText(trim(I('post.pwd')));
         $repwd = Util::getSafeText(trim(I('post.repwd')));
         if ($pwd != $repwd) {
             exit(Util::response(self::__ERROR__1, '两次输入密码不相同,请重新输入'));
         }
         //检查旧密码
         $userAdminModel = D('Useradmin');
         $row = $userAdminModel->getRow(array("id = {$this->userId}"));
         if ($row) {
             if (Util::genMd5Pwd($oldpwd) !== $row['passwd']) {
                 exit(Util::response(self::__ERROR__2, '原密码校验错误'));
             }
             $res = $userAdminModel->updatePwd($pwd);
             $this->logWriter = $this->logWriter->action(LogsModel::ACT_UPDATE)->called(ltrim(__CLASS__, __NAMESPACE__) . '::' . __FUNCTION__)->exec($userAdminModel->_sql());
             if ($res) {
                 $this->logWriter->ok();
                 //注销
                 Util::setCookie('u', '', -1);
                 exit(Util::response(self::__OK__, '更新密码成功,请重新登录'));
             } else {
                 $this->logWriter->fail();
                 exit(Util::response(self::__ERROR__4, '更新密码失败'));
             }
         } else {
             exit(Util::response(self::__ERROR__3, '该用户不存在'));
         }
     } else {
         $this->pageTitle('修改密码');
         $this->display();
     }
 }
 /**
  * 退出
  */
 public function index()
 {
     //记录日志
     D('Logs')->action(LogsModel::ACT_LOGOUT)->called(ltrim(__CLASS__, __NAMESPACE__) . '::' . __FUNCTION__)->ok();
     Util::setCookie('u', '', -1);
     $this->assign('waitSecond', 0);
     //exit($this->success('退出成功!', U('/Admin/Login')));
     exit($this->redirect(U('/Admin/System/Login'), null, 0, '退出成功!'));
 }
 /**
  *
  * @param $uname 用户登录名可能为用户名、手机号或邮件地址。
  * @param $upasswd 密码
  * @param int $time Cookie过期时间
  * @return bool|int 成功:array,cookies; 密码错误, 用户名错误:1; 数据库查询错误2;
  */
 public function userLogin($uname, $upasswd, $time = 86400000)
 {
     $user = $this->getUserByName($uname);
     if ($user) {
         if (Util::genMd5Pwd($upasswd) == $user['passwd']) {
             //检查账号是否禁用或者过期
             if ($user['blocked'] == 1) {
                 return -3;
             }
             //echo $user['expirtime'],'===',time();exit;
             //账户已过期
             if ($user['expirtime'] != 0 && time() - $user['expirtime'] > 0) {
                 return -4;
             }
             //纪录登录IP,纪录登录积分等处理
             //$loginip = Util::getIntIp();
             //$this->changeUser($user['id'],array('ltime'=>date('Y-m-d H:i:s'),'loginip'=>$loginip,));
             $_user = array();
             $_user['uid'] = $user['id'];
             $_user['uname'] = $user['uname'];
             $_user['nickname'] = $user['nickname'];
             $_user['email'] = $user['email'];
             $u = base64_encode(json_encode($_user));
             $res = Util::setCookie('u', $u, $time);
             if ($res) {
                 return $user['id'];
             }
         } else {
             return -2;
         }
     } else {
         return -1;
     }
     return false;
 }