Example #1
0
 public function resetPasswordManually()
 {
     if ($this->user['role'] == 'member') {
         if ($this->isPost()) {
             $old_password = trim($_POST['old_password']);
             $uid = $this->user['uid'];
             $userModelDB = new UserModelDB();
             $userInfo = $userModelDB->getUserByUid($uid);
             if (empty($old_password)) {
                 Message::showError('您输入的旧密码不能为空');
             }
             if (!preg_match('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/', $old_password)) {
                 $this->putErrorMsg('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/');
                 Message::showError('你输入的密码不符合正则');
             }
             if (sha1($old_password) != $userInfo['password']) {
                 Message::showError('您的旧密码输入有误');
             }
             $password = trim($_POST['password']);
             $password_repeat = trim($_POST['password_repeat']);
             if (empty($password) || empty($password_repeat)) {
                 Message::showError('新输入的密码不能为空');
             }
             if (!preg_match('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/', $password)) {
                 $this->putErrorMsg('/[0-9a-zA-Z_\\.\\@\\#\\$\\%]{6,18}/');
                 Message::showError('你输入的密码不符合正则');
             }
             if ($password_repeat != $password) {
                 Message::showError('两次输入的密码不一致');
             }
             //save db
             $success = $userModelDB->updatePassword($uid, sha1($password_repeat));
             if (!$success) {
                 Message::showError('failed');
             }
             Message::showSucc('Modify password success!');
         }
     } else {
         Message::showError('请登陆');
     }
     $this->display('reset_password_manually.html');
 }
Example #2
0
 /**
  * login model
  * @param $email
  * @param $password
  */
 public function login($email, $password)
 {
     if (empty($email) || empty($password)) {
         return false;
     }
     $userModelDb = new UserModelDB();
     //fetch db to validate register user
     $user = $userModelDb->getUser($email, sha1($password));
     if (!empty($user)) {
         $this->email = $user['email'];
         $this->role = 'member';
         $this->uid = $user['id'];
         $this->setUserCookie();
         return true;
         //login success
     } else {
         //no register user, login failed
         return false;
     }
 }