HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
UserLogin.php
Go to the documentation of this file.
1 <?php
2 
8 class UserLogin extends CFormModel
9 {
10  public $username;
11  public $password;
12  public $rememberMe;
13 
19  public function rules()
20  {
21  return array(
22  // username and password are required
23  array('username, password', 'required'),
24  // rememberMe needs to be a boolean
25  array('rememberMe', 'boolean'),
26  // password needs to be authenticated
27  array('password', 'authenticate'),
28  );
29  }
30 
34  public function attributeLabels()
35  {
36  return array(
37  'rememberMe' => UserModule::t("Remember me next time"),
38  'username' => UserModule::t("username or email"),
39  'password' => UserModule::t("password"),
40  );
41  }
42 
47  public function authenticate($attribute, $params)
48  {
49  if (!$this->hasErrors()) {
50  // we only want to authenticate when no input errors
51 
52  $identity = new UserIdentity($this->username, $this->password);
53  $identity->authenticate();
54  switch ($identity->errorCode) {
55  case UserIdentity::ERROR_NONE:
56  $duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
57  Yii::app()->user->login($identity, $duration);
58  break;
60  $this->addError("username", UserModule::t("Email is incorrect."));
61  break;
62  case UserIdentity::ERROR_USERNAME_INVALID:
63  $this->addError("username", UserModule::t("Username is incorrect."));
64  break;
66  $this->addError("status", UserModule::t("You account is not activated."));
67  break;
69  $this->addError("status", UserModule::t("You account is blocked."));
70  break;
71  case UserIdentity::ERROR_PASSWORD_INVALID:
72  $this->addError("password", UserModule::t("Password is incorrect."));
73  break;
74  }
75  }
76  }
77 }