Passed
Push — master ( 3596af...da6412 )
by Wilmer
02:03
created

ResetPasswordForm   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 5 1
A resetPassword() 0 8 1
A attributeLabels() 0 4 1
1
<?php
2
3
namespace app\basic\forms;
4
5
use app\basic\models\UserModels;
6
use yii\base\Model;
7
use yii\helpers\Yii;
8
9
/**
10
 * ResetPasswordForm is the model behind the reset password form Web Application Basic.
11
 **/
12
class ResetPasswordForm extends Model
13
{
14
	public $password;
15
16
    private $_User;
17
18
	/**
19
     * rules
20
     *
21
	 * @return array the validation rules.
22
	 **/
23
	public function rules()
24
	{
25
		return [
26
			['password', 'required'],
27
			['password', 'string', 'min' => 6],
28
		];
29
	}
30
31
	/**
32
	 * atributeLabels
33
	 * Translate Atribute Labels.
34
     *
35
	 * @return array customized attribute labels.
36
	 **/
37
	public function attributeLabels()
38
	{
39
		return [
40
			'password' => Yii::t('basic', 'Password'),
41
		];
42
	}
43
44
	/**
45
     * resetPassword
46
	 * Resets password.
47
	 *
48
     * @param string $token.
49
     * @param int $passwordResetTokenExpire password reset token.
50
	 * @return bool if password was reset.
51
	 **/
52
	public function resetPassword($token, int $passwordResetTokenExpire)
53
	{
54
        $this->_User = new UserModels();
55
        $this->_User = $this->_User->findByPasswordResetToken($token, $passwordResetTokenExpire);
56
		$this->_User->setPassword($this->password);
57
		$this->_User->removePasswordResetToken();
58
59
		return $this->_User->save(false);
60
	}
61
}
62