|
- <?php
-
-
-
- namespace frontend\forms;
-
- use domain\User\User\User;
- use domain\User\User\UserModule;
- use domain\User\User\UserRepository;
- use yii\base\Model;
-
-
- class PasswordResetRequestForm extends Model
- {
- public $email;
-
-
-
- public function rules()
- {
- return [
- ['email', 'filter', 'filter' => 'trim'],
- ['email', 'required'],
- ['email', 'email'],
- ['email', 'exist',
- 'targetClass' => 'domain\User\User\User',
- 'message' => 'There is no user with such email.'
- ],
- ];
- }
-
-
-
- public function sendEmail()
- {
- $userModule = UserModule::getInstance();
- $user = $userModule->getRepository()->findOneUserByEmail($this->email);
-
- if ($user) {
- if (!$userModule->isPasswordResetTokenValid($user->password_reset_token)) {
- $userModule->generatePasswordResetToken($user);
- }
-
- if ($user->save()) {
- return \Yii::$app->mailerService->sendFromSite(
- 'Mot de passe oublié',
- 'passwordResetToken',
- ['user' => $user],
- $this->email
- );
- }
- }
-
- return false;
- }
-
- }
|