Class WebUser
CWebUser represents the persistent state for a Web application user.
CWebUser is used as an application component whose ID is 'user'. Therefore,
at any place one can access the user state via
Yii::app()->user
.
CWebUser should be used together with an IUserIdentity identity which implements the actual authentication algorithm.
A typical authentication process using CWebUser is as follows:- The user provides information needed for authentication.
- An IUserIdentity identity instance is created with the user-provided information.
- Call IUserIdentity::authenticate to check if the identity is valid.
- If valid, call CWebUser::login to login the user, and Redirect the user browser to returnUrl.
- If not valid, retrieve the error code or message from the identity instance and display it.
The property id and name are both identifiers for the user. The former is mainly used internally (e.g. primary key), while the latter is for display purpose (e.g. username). The id property is a unique identifier for a user that is persistent during the whole user session. It can be a username, or something else, depending on the implementation of the IUserIdentity identity class.
Both id and name are persistent during the user session.
Besides, an identity may have additional persistent data which can be accessed
by calling CWebUser::getState()
. Note, when allowAutoLogin cookie-based
authentication is enabled, all these persistent data will be stored in cookie.
Therefore, do not store password or other sensitive data in the persistent
storage. Instead, you should store them directly in session on the server side
if needed.
- CComponent
-
CApplicationComponent implements IApplicationComponent
-
CWebUser implements IWebUser
-
WebUser
Author: Qiang Xue <qiang.xue@gmail.com>
Version: $Id$
Since: 1.0
Located at mishamx/yii-user/components/WebUser.php
Methods summary
public
|
|
public
mixed
|
|
protected
|
#
afterLogin( boolean $fromCookie )
This method is called after the user is successfully logged in. You may override this method to do some postprocessing (e.g. log the user login IP and time; load the user permission information). |
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
Methods inherited from CWebUser
__get()
,
__isset()
,
__set()
,
__unset()
,
afterLogout()
,
beforeLogin()
,
beforeLogout()
,
changeIdentity()
,
checkAccess()
,
clearStates()
,
createIdentityCookie()
,
getFlash()
,
getFlashes()
,
getIsGuest()
,
getName()
,
getReturnUrl()
,
getState()
,
getStateKeyPrefix()
,
hasFlash()
,
hasState()
,
init()
,
loadIdentityStates()
,
login()
,
loginRequired()
,
logout()
,
renewCookie()
,
restoreFromCookie()
,
saveIdentityStates()
,
saveToCookie()
,
setFlash()
,
setId()
,
setName()
,
setReturnUrl()
,
setState()
,
setStateKeyPrefix()
,
updateAuthStatus()
,
updateFlash()
Methods inherited from CApplicationComponent
getIsInitialized()
Methods inherited from CComponent
__call()
,
asa()
,
attachBehavior()
,
attachBehaviors()
,
attachEventHandler()
,
canGetProperty()
,
canSetProperty()
,
detachBehavior()
,
detachBehaviors()
,
detachEventHandler()
,
disableBehavior()
,
disableBehaviors()
,
enableBehavior()
,
enableBehaviors()
,
evaluateExpression()
,
getEventHandlers()
,
hasEvent()
,
hasEventHandler()
,
hasProperty()
,
raiseEvent()
Magic methods summary
Constants summary
Constants inherited from CWebUser
AUTH_TIMEOUT_VAR
,
FLASH_COUNTERS
,
FLASH_KEY_PREFIX
,
STATES_VAR
Properties summary
public
boolean
|
$allowAutoLogin |
#
whether to enable cookie-based login. Defaults to false. |
public
string|array
|
$loginUrl |
#
the URL for login. If using array, the first element should be the route to the login action, and the rest name-value pairs are GET parameters to construct the login URL (e.g. array('/site/login')). If this property is null, a 403 HTTP exception will be raised instead. |
Properties inherited from CWebUser
$authTimeout
,
$autoRenewCookie
,
$autoUpdateFlash
,
$guestName
,
$identityCookie
,
$loginRequiredAjaxResponse
Properties inherited from CApplicationComponent
$behaviors
Magic properties inherited from CWebUser
$flashes
,
$id
,
$isGuest
,
$name
,
$returnUrl
,
$stateKeyPrefix
Magic properties inherited from CApplicationComponent
$isInitialized