public function actionForgotPassword($code = false) { if (!empty($code)) { $user = Users::model()->getUserByMaintenanceUrl($code); if (empty($user)) { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } $user->url_maintenance = false; $user->save(); Yii::app()->session['forgot-password'] = 1; Yii::app()->session['user-model'] = $user; $this->setFlashSuccess('Now you can change your password'); $this->redirect(array('changePassword')); } if (isset($_POST['credentials'])) { $user = Users::model()->getUserByEmail($_POST['credentials']); if (empty($user)) { $user = Users::model()->getUserByUsername($_POST['credentials']); } if (empty($user)) { $this->setFlashError('Username / Email is invalid'); } else { $url_maintenance = $user->getMaintenanceUrl(); $user->save(); MailHelper::sendForgotPasswordMail($user->email, $url_maintenance); $this->setFlashSuccess('Instructions were sent to your e-mail. Please follow them for password change.'); $this->redirect(array('login')); } } $this->render('forgot_password'); }