/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::findByEmail($this->username); } return $this->_user; }
/** * Reset the password for a user. */ public function actionReset() { if (null === Yii::$app->request->post()) { throw new BadRequestHttpException(); } $post = Yii::$app->request->post(); if (!isset($post['User']) || !isset($post['ResetPassword']) || !isset($post['User']['email']) || !isset($post['ResetPassword']['reset_token']) || !isset($post['password']) || !isset($post['password_confirm'])) { throw new BadRequestHttpException(); } $user = User::findByEmail($post['User']['email']); if (null === $user) { throw new NotFoundHttpException(); } $request = ResetPassword::findOne(['reset_token' => $post['ResetPassword']['reset_token'], 'userid' => $user->getId()]); if (null == $request) { throw new NotFoundHttpException(); } if ($post['password'] != $post['password_confirm']) { Yii::$app->getSession()->setFlash('error', Yii::t('ica_auth', 'Passwords do not match.')); $this->redirect(Yii::$app->request->getReferrer()); return; } $user->setPassword($post['password']); if ($user->save(true, array('password_hash'))) { $request->delete(); return $this->render('@icalab/auth/views/password-reset/success'); } Yii::$app->getSession()->setFlash('error', Yii::t('ica_auth', 'Unable to update password. Please try again or contact support..')); $this->redirect(Yii::$app->request->getReferrer()); }