Commit f61734d4 by Qiang Xue

Added $checkSession parameter to User::getIsGuest() and getId().

parent 7960ccdf
...@@ -285,20 +285,26 @@ class User extends Component ...@@ -285,20 +285,26 @@ class User extends Component
/** /**
* Returns a value indicating whether the user is a guest (not authenticated). * Returns a value indicating whether the user is a guest (not authenticated).
* @param boolean $checkSession whether to check the session to determine if the user is a guest.
* Note that if this is false, it is possible that the user may not be a guest while this method still returns
* true. This is because the session is not checked.
* @return boolean whether the current user is a guest. * @return boolean whether the current user is a guest.
*/ */
public function getIsGuest() public function getIsGuest($checkSession = true)
{ {
return $this->getIdentity() === null; return $this->getIdentity($checkSession) === null;
} }
/** /**
* Returns a value that uniquely represents the user. * Returns a value that uniquely represents the user.
* @param boolean $checkSession whether to check the session to determine the user ID.
* Note that if this is false, it is possible that this method returns null although the user may not
* be a guest. This is because the session is not checked.
* @return string|integer the unique identifier for the user. If null, it means the user is a guest. * @return string|integer the unique identifier for the user. If null, it means the user is a guest.
*/ */
public function getId() public function getId($checkSession = true)
{ {
$identity = $this->getIdentity(); $identity = $this->getIdentity($checkSession);
return $identity !== null ? $identity->getId() : null; return $identity !== null ? $identity->getId() : null;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment