Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
EmailService.php
1 <?php
2 /**
3  *
4  */
6 {
7  /**
8  * Everything is OK.
9  */
10  const ERROR_NONE = 0;
11  /**
12  * Failed to authenticate authentication identity (email-password mismatch).
13  */
14  const ERROR_AUTH_FAILED = 1;
15  /**
16  * No errors occured. Activation mail to user was sent and user will be registered
17  * as soon as he will click the activation url in the email message body.
18  */
20  /**
21  * Error occured while trying to send activation mail.
22  */
24 
25  protected $name = 'email';
26  protected $title = 'E-mail';
27  protected $type = 'email';
28 
29 
30 
31  /**
32  * @var string email field, put here email address, you want to authenticate
33  */
34  public $username;
35  /**
36  * @var string password field, put here password, with which you want to authenticate
37  */
38  public $password;
39  /**
40  * @var string email field
41  */
42  public $email;
43 
44  /**
45  * @var integer code of the error, that occured, ERROR_NONE will be set if no errors occured
46  */
47  public $errorCode;
48 
49  /**
50  * @var LUser user-owner of the email account, specified on bind process
51  * (null means that we're trying to authenticate, not bind an account to already existing user)
52  */
53  public $user = null;
54 
55  /**
56  * This function simply tries to authenticate auth identity (see docs about user authenticating behaviour)
57  * @return bool is user identity authenticated or authentication failed
58  */
59  public function authenticate()
60  {
61  $email = $this->email;
62  $username = $this->username;
63  $password = $this->password;
64  $password_hash = Yii::app()->getModule('user')->encrypting($password);
65  $this->authenticated = false;
66 
67  if ($this->authField == 'email') {
68  $user = User::model()->findByAttributes(array('email' => $email, 'password' => $password_hash));
69  } else if ($this->authField == 'username') {
70  $user = User::model()->findByAttributes(array('username' => $username, 'password' => $password_hash));
71  } else
72  return false;
73 
74  if ($user) {
75  $this->attributes['id'] = $this->attributes['email'] = $this->attributes['displayId'] = $username;
76  $this->authenticated = true;
77  $this->errorCode = self::ERROR_NONE;
78  } else {
79  $this->errorCode = self::ERROR_AUTH_FAILED;
80  }
81  Yii::log("EmailService auth resulted with code $this->errorCode.", CLogger::LEVEL_INFO);
82  return $this->authenticated;
83  }
84 
85  /**
86  * Simply redirects user to the specified url (if not specified, redirectUrl property will be used instead)
87  *
88  * We have to override this function, because email authentication doesn't require popup.
89  * @param string $url
90  */
91  public function redirect($url = null)
92  {
93  Yii::app()->request->redirect(isset($url) ? $url : $this->getRedirectUrl(), true);
94  }
95 
96  /**
97  * Simply redirects user to the specified url (if not specified, cancelUrl property will be used instead)
98  *
99  * We have to override this function, because email authentication doesn't require popup.
100  * @param string $url
101  */
102  public function cancel($url = null)
103  {
104  Yii::app()->request->redirect(isset($url) ? $url : $this->getCancelUrl(), false);
105  }
106 
107  public function getEmail()
108  {
109 
110  }
111 
112  public function getName()
113  {
114  return $this->username;
115  }
116 
117  public function getError()
118  {
119  return UserModule::t('Not correct username or password');
120  }
121 }