/** * Sends recovery message. */ public function recoverPassword() { $user = User::findOne(['email' => $this->email]); if ($user != NULL) { $user->password_reset_token = Yii::$app->getSecurity()->generateRandomString() . '_' . time(); $user->save(FALSE); } // Sends recovery mail Mailer::sendRecoveryMessage($user); Yii::$app->session->setFlash('info', 'You will receive an email with instructions on how to reset your password in a few minutes.'); }
/** * @param integer $id User Id * @param string $code Password Reset Token * * @return string * @throws \yii\web\NotFoundHttpException */ public function actionReset($id, $code) { $model = User::findOne(['id' => $id, 'password_reset_token' => $code, 'status' => User::STATUS_ACTIVE]); if ($model == NULL) { throw new NotFoundHttpException(); } $model->scenario = 'reset'; if (!empty($model)) { if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $model->password_reset_token = NULL; $model->save(); Yii::$app->session->setFlash('success', Yii::t('user', 'Your password has successfully been changed. Now you can login with your new password.')); return $this->redirect(['//user/auth/login']); } } } return $this->render('reset', ['model' => $model]); }