1 | <?php |
||
10 | class ChangePasswordForm extends CFormModel |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * @var string the user's current password |
||
15 | */ |
||
16 | public $currentPassword; |
||
17 | |||
18 | /** |
||
19 | * @var string the new password |
||
20 | */ |
||
21 | public $newPassword; |
||
22 | |||
23 | /** |
||
24 | * @var string the new password (repeated) |
||
25 | */ |
||
26 | public $newPasswordRepeat; |
||
27 | |||
28 | /** |
||
29 | * @var User the user model |
||
30 | */ |
||
31 | private $_user; |
||
32 | |||
33 | /** |
||
34 | * @return array the attribute labels for this model |
||
35 | */ |
||
36 | public function attributeLabels() |
||
37 | { |
||
38 | return array( |
||
39 | 'currentPassword'=>Yii::t('Password', 'Current password'), |
||
40 | 'newPassword'=>Yii::t('Password', 'New password'), |
||
41 | 'newPasswordRepeat'=>Yii::t('Password', 'New password (repeat)'), |
||
42 | ); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * @return array the validation rules for this controller |
||
47 | */ |
||
48 | public function rules() |
||
49 | { |
||
50 | return array( |
||
51 | array('currentPassword, newPassword, newPasswordRepeat', 'required'), |
||
52 | array('currentPassword', 'checkCurrentPassword'), |
||
53 | array('newPassword', 'compare', 'compareAttribute'=>'newPasswordRepeat'), |
||
54 | array('newPassword', 'compare', 'compareAttribute'=>'currentPassword', |
||
55 | 'operator'=>'!=', 'message'=>Yii::t('Password', 'New password cannot be the same as the old one')), |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Loads the user model |
||
61 | * @return boolean whether validation should continue |
||
62 | */ |
||
63 | protected function beforeValidate() |
||
69 | |||
70 | /** |
||
71 | * Checks that currentPassword matches the user's current password |
||
72 | * @param string $attribute the attribute being validated |
||
73 | */ |
||
74 | public function checkCurrentPassword($attribute) |
||
79 | |||
80 | } |
||
81 |