1 <?php
2 3 4 5 6
7 class UserChangePassword extends CFormModel {
8 public $oldPassword;
9 public $password;
10 public $verifyPassword;
11
12 public function rules() {
13 return Yii::app()->controller->id == 'recovery' ? array(
14 array('password, verifyPassword', 'required'),
15 array('password, verifyPassword', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
16 array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")),
17 ) : array(
18 array('oldPassword, password, verifyPassword', 'required'),
19 array('oldPassword, password, verifyPassword', 'length', 'max'=>128, 'min' => 4,'message' => UserModule::t("Incorrect password (minimal length 4 symbols).")),
20 array('verifyPassword', 'compare', 'compareAttribute'=>'password', 'message' => UserModule::t("Retype Password is incorrect.")),
21 array('oldPassword', 'verifyOldPassword'),
22 );
23 }
24
25 26 27
28 public function attributeLabels()
29 {
30 return array(
31 'oldPassword'=>UserModule::t("Old Password"),
32 'password'=>UserModule::t("password"),
33 'verifyPassword'=>UserModule::t("Retype Password"),
34 );
35 }
36
37 38 39
40 public function verifyOldPassword($attribute, $params)
41 {
42 if (User::model()->notsafe()->findByPk(Yii::app()->user->id)->password != Yii::app()->getModule('user')->encrypting($this->$attribute))
43 $this->addError($attribute, UserModule::t("Old Password is incorrect."));
44 }
45 }