HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UserRecoveryForm.php
Go to the documentation of this file.
1 <?php
2 
8 class UserRecoveryForm extends CFormModel
9 {
11 
17  public function rules()
18  {
19  return array(
20  // username and password are required
21  array('login_or_email', 'required'),
22  array('login_or_email', 'match', 'pattern' => '/^[A-Za-z0-9@.-\s,]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),
23  // password needs to be authenticated
24  array('login_or_email', 'checkexists'),
25  );
26  }
30  public function attributeLabels()
31  {
32  return array(
33  'login_or_email' => UserModule::t("username or email"),
34  );
35  }
36 
37  public function checkexists($attribute, $params)
38  {
39  if (!$this->hasErrors()) {
40  // we only want to authenticate when no input errors
41 
42  if (strpos($this->login_or_email, "@")) {
43  $user = User::model()->findByAttributes(array('email' => $this->login_or_email));
44  if ($user) {
45  $this->user_id = $user->id;
46  }
47  } else {
48  $user = User::model()->findByAttributes(array('username' => $this->login_or_email));
49  if ($user) {
50  $this->user_id = $user->id;
51  }
52  }
53 
54  if ($user === null) {
55  if (strpos($this->login_or_email, "@")) {
56  $this->addError("login_or_email", UserModule::t("Email is incorrect."));
57  } else {
58  $this->addError("login_or_email", UserModule::t("Username is incorrect."));
59  }
60  }
61  }
62  }
63 }