Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
RWebUser.php
1 <?php
2 /**
3 * Rights web user class file.
4 *
5 * @author Christoffer Niska <cniska@live.com>
6 * @copyright Copyright &copy; 2010 Christoffer Niska
7 * @since 0.5
8 */
9 class RWebUser extends CWebUser
10 {
11  /**
12  * Actions to be taken after logging in.
13  * Overloads the parent method in order to mark superusers.
14  * @param boolean $fromCookie whether the login is based on cookie.
15  */
16  public function afterLogin($fromCookie)
17  {
18  parent::afterLogin($fromCookie);
19 
20  // Mark the user as a superuser if necessary.
21  if( Rights::getAuthorizer()->isSuperuser($this->getId())===true )
22  $this->isSuperuser = true;
23  }
24 
25  /**
26  * Performs access check for this user.
27  * Overloads the parent method in order to allow superusers access implicitly.
28  * @param string $operation the name of the operation that need access check.
29  * @param array $params name-value pairs that would be passed to business rules associated
30  * with the tasks and roles assigned to the user.
31  * @param boolean $allowCaching whether to allow caching the result of access checki.
32  * This parameter has been available since version 1.0.5. When this parameter
33  * is true (default), if the access check of an operation was performed before,
34  * its result will be directly returned when calling this method to check the same operation.
35  * If this parameter is false, this method will always call {@link CAuthManager::checkAccess}
36  * to obtain the up-to-date access result. Note that this caching is effective
37  * only within the same request.
38  * @return boolean whether the operations can be performed by this user.
39  */
40  public function checkAccess($operation, $params=array(), $allowCaching=true)
41  {
42  // Allow superusers access implicitly and do CWebUser::checkAccess for others.
43  return $this->isSuperuser===true ? true : parent::checkAccess($operation, $params, $allowCaching);
44  }
45 
46  /**
47  * @param boolean $value whether the user is a superuser.
48  */
49  public function setIsSuperuser($value)
50  {
51  $this->setState('Rights_isSuperuser', $value);
52  }
53 
54  /**
55  * @return boolean whether the user is a superuser.
56  */
57  public function getIsSuperuser()
58  {
59  return $this->getState('Rights_isSuperuser');
60  }
61 
62  /**
63  * @param array $value return url.
64  */
65  public function setRightsReturnUrl($value)
66  {
67  $this->setState('Rights_returnUrl', $value);
68  }
69 
70  /**
71  * Returns the URL that the user should be redirected to
72  * after updating an authorization item.
73  * @param string $defaultUrl the default return URL in case it was not set previously. If this is null,
74  * the application entry URL will be considered as the default return URL.
75  * @return string the URL that the user should be redirected to
76  * after updating an authorization item.
77  */
78  public function getRightsReturnUrl($defaultUrl=null)
79  {
80  if( ($returnUrl = $this->getState('Rights_returnUrl'))!==null )
81  $this->returnUrl = null;
82 
83  return $returnUrl!==null ? CHtml::normalizeUrl($returnUrl) : CHtml::normalizeUrl($defaultUrl);
84  }
85 
86  public function getEmail()
87  {
88  return $this->getState('email');
89  }
90 }