Passed
Push — master ( 65662a...ffc20a )
by Wilmer
02:42
created

ResetPasswordForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

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