Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
UserRecoveryForm.php
1 <?php
2 
3 /**
4  * UserRecoveryForm class.
5  * UserRecoveryForm is the data structure for keeping
6  * user recovery form data. It is used by the 'recovery' action of 'UserController'.
7  */
8 class UserRecoveryForm extends CFormModel {
9  public $login_or_email, $user_id;
10 
11  /**
12  * Declares the validation rules.
13  * The rules state that username and password are required,
14  * and password needs to be authenticated.
15  */
16  public function rules()
17  {
18  return array(
19  // username and password are required
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  // password needs to be authenticated
23  array('login_or_email', 'checkexists'),
24  );
25  }
26  /**
27  * Declares attribute labels.
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()) // we only want to authenticate when no input errors
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 }