Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
UserLogin.php
1 <?php
2 /**
3  *
4  */
5 class UserLogin extends CFormModel
6 {
7  public $service;
8  public $authField;
9  public $password;
10  public $rememberMe;
11 
12  public function rules()
13  {
14  return array(
15  array('service', 'required'),
16  array('rememberMe', 'boolean'),
17  array('authField, password', 'length', 'max' => 255)
18  );
19  }
20 
21  public function attributeLabels()
22  {
23  return array(
24  'rememberMe' => UserModule::t("Remember me next time"),
25  'authField' => UserModule::t(ucfirst(Yii::app()->getModule('user')->authField)),
26  'password' => UserModule::t("Password"),
27  );
28  }
29 
30  public function applyErrors($userIdentity)
31  {
32  if (!$userIdentity->errorCode) return;
33  if ($userIdentity instanceof UserIdentity) {
34  switch ($userIdentity->errorCode) {
35  case UserIdentity::ERROR_AUTH_FIELD_INVALID:
36  $this->addError('authField', ucfirst(Yii::app()->getModule('user')->authField) . ' invalid');
37  break;
38  case UserIdentity::ERROR_PASSWORD_INVALID:
39  $this->addError('password', UserModule::t('Password invalid'));
40  break;
41  case UserIdentity::ERROR_STATUS_NOTACTIV:
42  $this->addError("status", UserModule::t("Your account is not activated."));
43  break;
44  case UserIdentity::ERROR_STATUS_BAN:
45  $this->addError("status", UserModule::t("Your account is blocked."));
46  break;
47  default:
48  break;
49  }
50  } else {
51  $this->addError('service', UserModule::t('Service error'));
52  }
53  }
54 
55  public function getAjaxErrors()
56  {
57  $result = array();
58  foreach ($this->getErrors() as $attribute => $errors)
59  $result[CHtml::activeId($this, $attribute)] = $errors;
60 
61  return CJSON::encode($result);
62  }
63 }