|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
-
-
-
- namespace frontend\forms;
-
- use domain\User\User\UserModule;
- use yii\base\InvalidParamException;
- use yii\base\Model;
-
-
- class ResetPasswordForm extends Model
- {
- public $password;
-
-
-
- private $_user;
-
-
-
- public function __construct($token, $config = [])
- {
- $userModule = UserModule::getInstance();
- if (empty($token) || !is_string($token)) {
- throw new InvalidParamException('Password reset token cannot be blank.');
- }
- $this->_user = $userModule->findOneUserByPasswordResetToken($token);
- if (!$this->_user) {
- throw new InvalidParamException('Wrong password reset token.');
- }
- parent::__construct($config);
- }
-
-
-
- public function rules()
- {
- return [
- ['password', 'required'],
- ['password', 'string', 'min' => 6],
- ];
- }
-
-
-
- public function resetPassword()
- {
- $userModule = UserModule::getInstance();
-
- $user = $this->_user;
- $userModule->setPassword($user, $this->password);
- $userModule->removePasswordResetToken($user);
-
- return $user->save();
- }
-
- public function attributeLabels()
- {
- return [
- 'password' => 'Mot de passe',
- ];
- }
-
- }
|