Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
EAuthUserIdentity.php
1 <?php
2 /**
3  * EAuthUserIdentity class file.
4  *
5  * @author Maxim Zemskov <nodge@yandex.ru>
6  * @link http://code.google.com/p/yii-eauth/
7  * @license http://www.opensource.org/licenses/bsd-license.php
8  */
9 
10 /**
11  * EAuthUserIdentity is a base User Identity class to authenticate with EAuth.
12  * @package application.extensions.eauth
13  */
14 class EAuthUserIdentity extends CBaseUserIdentity {
15  const ERROR_NOT_AUTHENTICATED = 3;
16 
17  /**
18  * @var EAuthServiceBase the authorization service instance.
19  */
20  protected $service;
21 
22  /**
23  * @var string the unique identifier for the identity.
24  */
25  protected $id;
26 
27  /**
28  * @var string the display name for the identity.
29  */
30  protected $name;
31 
32  /**
33  * Constructor.
34  * @param EAuthServiceBase $service the authorization service instance.
35  */
36  public function __construct($service) {
37  $this->service = $service;
38  }
39 
40  /**
41  * Authenticates a user based on {@link service}.
42  * This method is required by {@link IUserIdentity}.
43  * @return boolean whether authentication succeeds.
44  */
45  public function authenticate() {
46  if ($this->service->isAuthenticated) {
47  $this->id = $this->service->id;
48  $this->name = $this->service->getAttribute('name');
49 
50  $this->setState('id', $this->id);
51  $this->setState('name', $this->name);
52  $this->setState('service', $this->service->serviceName);
53 
54  $this->errorCode = self::ERROR_NONE;
55  }
56  else {
57  $this->errorCode = self::ERROR_NOT_AUTHENTICATED;
58  }
59  return !$this->errorCode;
60  }
61 
62  /**
63  * Returns the unique identifier for the identity.
64  * This method is required by {@link IUserIdentity}.
65  * @return string the unique identifier for the identity.
66  */
67  public function getId() {
68  return $this->id;
69  }
70 
71  /**
72  * Returns the display name for the identity.
73  * This method is required by {@link IUserIdentity}.
74  * @return string the display name for the identity.
75  */
76  public function getName() {
77  return $this->name;
78  }
79 }