/** * load user, read cookie login */ public function loadUser() { //read cookie $userCookie = $this->getUserCookie(); if (!empty($userCookie)) { //decrept cookie $encryptModel = new BaseModelEncrypt(); $userCookieSerialStr = $encryptModel->rsa_private_decode($userCookie); $userCookieArr = unserialize($userCookieSerialStr); //print_r($userCookieArr); if (!empty($userCookieArr['uid'])) { $userModelDb = new UserModelDB(); //fetch db to validate register user $user = $userModelDb->getUserByUid($userCookieArr['uid']); } if (!empty($user)) { $this->uid = $user['id']; $this->email = $user['email']; $this->role = 'member'; } } return array('uid' => $this->uid, 'email' => $this->email, 'ip' => $this->ip, 'ua' => $this->ua, 'role' => $this->role); }
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'); }