You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

74 lines
2.1 KiB

<?php
namespace frontend\controllers\auth;
use core\services\auth\PasswordResetService;
use Yii;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use core\forms\auth\PasswordResetRequestForm;
use core\forms\auth\ResetPasswordForm;
class ResetController extends Controller
{
public $layout = 'auth';
private $service;
public function __construct($id, $module, PasswordResetService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
}
/**
* @return mixed
*/
public function actionRequest()
{
$form = new PasswordResetRequestForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->request($form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'Check your email for further instructions.'));
return $this->goHome();
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
}
return $this->render('request', [
'model' => $form,
]);
}
/**
* @param $token
* @return mixed
* @throws BadRequestHttpException
*/
public function actionConfirm($token)
{
try {
$this->service->validateToken($token);
} catch (\DomainException $e) {
throw new BadRequestHttpException($e->getMessage());
}
$form = new ResetPasswordForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->reset($token, $form);
Yii::$app->session->setFlash('success', Yii::t('auth', 'New password saved.'));
} catch (\DomainException $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', $e->getMessage());
}
return $this->goHome();
}
return $this->render('confirm', [
'model' => $form,
]);
}
}