public function authenticate() { $users = User::findLoginUser($this->username); $isUserExist = $users != null; if (!$isUserExist) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($users->password != $this->password) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { /* authentication success! */ //override the original id property $this->_id = $users->id; //set other information to store in persistent storage // remark: // if we want to add more properties, // we should use $this->setState('lastLoginTime', $user->lastLoginTime); // such that we can get the value with something like: // $lastLoginTime=Yii::app()->user->lastLoginTime; $this->setState('user_name', $users->user_name); $this->setState('show_r18', $users->show_r18); $this->setState('show_bl', $users->show_bl); $this->setState('icon_src', $users->icon_src); $this->errorCode = self::ERROR_NONE; } } return !$this->errorCode; }
public function actionForgetPassword() { if (isset($_POST['username'])) { $username = $_POST['username']; $users = User::findLoginUser($username); $isUserExist = $users != null; if (!$isUserExist) { Yii::app()->user->setFlash(FlashMsg::ERROR, "沒有" . $username . ""); $this->redirect(array('forgetPassword')); } $newPassword = RandomHelper::generateRandomString(); $users->resetPasswordAs($newPassword); $userEmail = $users->email; if ($users->save()) { //Yii::app()->user->setFlash(FlashMsg::SUCCESS, "".$username."的新密碼: ".$newPassword); $this->render('resettedPassword', array('model' => $newPassword)); //$this->redirect(Yii::app()->request->urlReferrer); } } $this->render('forgetPassword'); }