HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
LoginForm.php
Go to the documentation of this file.
1 <?php
2 
8 class LoginForm extends CFormModel
9 {
10  public $username;
11  public $password;
12  public $rememberMe;
13 
14  private $_identity;
15 
21  public function rules()
22  {
23  return array(
24  // username and password are required
25  array('username, password', 'required'),
26  // rememberMe needs to be a boolean
27  array('rememberMe', 'boolean'),
28  // password needs to be authenticated
29  array('password', 'authenticate'),
30  );
31  }
32 
36  public function attributeLabels()
37  {
38  return array(
39  'rememberMe' => 'Remember me next time',
40  );
41  }
42 
47  public function authenticate($attribute, $params)
48  {
49  if (!$this->hasErrors()) {
50  $this->_identity = new UserIdentity($this->username, $this->password);
51  if (!$this->_identity->authenticate())
52  $this->addError('password', 'Incorrect username or password.');
53  }
54  }
55 
60  public function login()
61  {
62  if ($this->_identity === null) {
63  $this->_identity = new UserIdentity($this->username, $this->password);
64  $this->_identity->authenticate();
65  }
66  if ($this->_identity->errorCode === UserIdentity::ERROR_NONE) {
67  $duration = $this->rememberMe ? 3600 * 24 * 30 : 0; // 30 days
68  Yii::app()->user->login($this->_identity, $duration);
69  return true;
70  } else
71  return false;
72  }
73 }