public function actionRequest() { $model = new ResetRequest(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = User::findOne(['email' => $model->email]); $user->generateCode(); if ($user->save()) { $url = Url::to(['password', 'code' => $user->code], true); if ($user->sendEmail('html', ['subject' => Yii::$app->params['site']['name'] . ' ' . Yii::t('app', ' password reset'), 'content' => "Для восстановления пароля ерейдите по <a href='{$url}'>ссылке</a>"])) { Yii::$app->session->setFlash('info', Yii::t('app', 'Check your email')); return $this->redirect(['site/index']); } else { Yii::$app->session->setFlash('error', Yii::t('app', 'Email send error')); } } } return $this->render('request', ['model' => $model]); }
public function actionRequest() { /** @var User $user */ $model = new ResetRequest(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = User::findOne(['email' => $model->email]); $user->generateCode(); if ($user->save()) { $url = Url::to(['password', 'code' => $user->code], true); if ($user->sendEmail(['subject' => Yii::$app->params['site']['name'] . ' ' . Yii::t('app', 'Password reset'), 'content' => Yii::t('app', 'To recover your password, open <a href="{url}">this link</a>', ['url' => $url])])) { Yii::$app->session->setFlash('info', Yii::t('app', 'Check your email')); return $this->redirect(['home/index']); } else { Yii::$app->session->setFlash('error', Yii::t('app', 'Failed to send mail')); } } else { Yii::$app->session->setFlash('error', json_encode($user->errors)); } } return $this->render('request', ['model' => $model]); }