1 <?php
2
3 4 5 6 7
8 class UserRecoveryForm extends CFormModel {
9 public $login_or_email, $user_id;
10
11 12 13 14 15
16 public function rules()
17 {
18 return array(
19
20 array('login_or_email', 'required'),
21 array('login_or_email', 'match', 'pattern' => '/^[A-Za-z0-9@.-\s,]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),
22
23 array('login_or_email', 'checkexists'),
24 );
25 }
26 27 28
29 public function attributeLabels()
30 {
31 return array(
32 'login_or_email'=>UserModule::t("username or email"),
33 );
34 }
35
36 public function checkexists($attribute,$params) {
37 if(!$this->hasErrors())
38 {
39 if (strpos($this->login_or_email,"@")) {
40 $user=User::model()->findByAttributes(array('email'=>$this->login_or_email));
41 if ($user)
42 $this->user_id=$user->id;
43 } else {
44 $user=User::model()->findByAttributes(array('username'=>$this->login_or_email));
45 if ($user)
46 $this->user_id=$user->id;
47 }
48
49 if($user===null)
50 if (strpos($this->login_or_email,"@")) {
51 $this->addError("login_or_email",UserModule::t("Email is incorrect."));
52 } else {
53 $this->addError("login_or_email",UserModule::t("Username is incorrect."));
54 }
55 }
56 }
57
58 }