UsersController

Type
Class
Namespace
Craft
Inherits
Craft\UsersController » Craft\BaseController » CController » CBaseController » CComponent
Since
1.0

The UsersController class is a controller that handles various user account related tasks such as logging-in, impersonating a user, logging out, forgetting passwords, setting passwords, validating accounts, activating accounts, creating users, saving users, processing user avatars, deleting, suspending and un-suspending users.

Note that all actions in the controller, except {@link actionLogin}, {@link actionLogout}, {@link actionGetAuthTimeout}, {@link actionSendPasswordResetEmail}, {@link actionSetPassword}, {@link actionVerifyEmail} and {@link actionSaveUser} require an authenticated Craft session via {@link BaseController::allowAnonymous}.

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$defaultActionstring – The name of the default action.
$layoutmixed – The name of the layout to be applied to this controller's views.

Protected Properties

PropertyDescription
$allowAnonymousboolean

$allowAnonymous

Signature

protected boolean $allowAnonymous = ['actionLogin', 'actionLogout', 'actionGetAuthTimeout', 'actionForgotPassword', 'actionSendPasswordResetEmail', 'actionSendActivationEmail', 'actionSaveUser', 'actionSetPassword', 'actionVerifyEmail']

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__construct()
__get()Returns a property value, an event handler list or a behavior based on its name.
__isset()Checks if a property value is null.
__set()Sets value of a component property.
__unset()Sets a component property to be null.
accessRules()Returns the access rules for this controller.
actionActivateUser()Manually activates a user account. Only admins have access.
actionCropUserPhoto()Crop user photo.
actionDeleteUser()Deletes a user.
actionDeleteUserPhoto()Delete all the photos for current user.
actionEditUser()Edit a user account.
actionForgotPassword()Sends a Forgot Password email.
actionGetAuthTimeout()Returns how many seconds are left in the current user session.
actionGetElevatedSessionTimeout()Returns how many seconds are left in the current elevated user session.
actionGetPasswordResetUrl()Generates a new verification code for a given user, and returns its URL.
actionImpersonate()Logs a user in for impersonation. Requires you to be an administrator.
actionLogin()Displays the login template, and handles login post requests.
actionLogout()
actionSaveFieldLayout()Saves the user field layout.
actionSaveProfile()Saves a user's profile.
actionSaveUser()Provides an endpoint for saving a user account.
actionSendActivationEmail()Sends a new activation email to a user.
actionSendPasswordResetEmail()Sends a password reset email.
actionSetPassword()Sets a user's password once they've verified they have access to their email.
actionStartElevatedSession()Starts an elevated user session.
actionSuspendUser()Suspends a user.
actionUnlockUser()Unlocks a user, bypassing the cooldown phase.
actionUnsuspendUser()Unsuspends a user.
actionUploadUserPhoto()Upload a user photo.
actionValidate()Verifies that a user has access to an email address.
actionVerifyEmail()Verifies that a user has access to an email address.
actionVerifyPassword()Verifies a password for a user.
actions()Returns a list of external action classes.
asa()Returns the named behavior object.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
attachEventHandler()Attaches an event handler to an event.
beforeAction()Checks if a controller has overridden allowAnonymous either as an array with actions to allow anonymous access to or as a bool that applies to all actions.
beginCache()Begins fragment caching.
beginClip()Begins recording a clip.
beginContent()Begins the rendering of content that is to be decorated by the specified view.
beginWidget()Creates a widget and executes it.
behaviors()Returns a list of behaviors that this controller should behave as.
canGetProperty()Determines whether a property can be read.
canSetProperty()Determines whether a property can be set.
clearPageStates()Removes all page states.
createAbsoluteUrl()Creates an absolute URL for the specified action defined in this controller.
createAction()Creates the action instance based on the action name.
createUrl()Creates a relative URL for the specified action defined in this controller.
createWidget()Creates a widget and initializes it.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
detachEventHandler()Detaches an existing event handler.
disableBehavior()Disables an attached behavior.
disableBehaviors()Disables all behaviors attached to this component.
enableBehavior()Enables an attached behavior.
enableBehaviors()Enables all behaviors attached to this component.
endCache()Ends fragment caching.
endClip()Ends recording a clip.
endContent()Ends the rendering of content.
endWidget()Ends the execution of the named widget.
evaluateExpression()Evaluates a PHP expression or callback under the context of this component.
filterAccessControl()The filter method for 'accessControl' filter.
filterAjaxOnly()The filter method for 'ajaxOnly' filter.
filterPostOnly()The filter method for 'postOnly' filter.
filters()Returns the filter configurations.
forward()Processes the request using another controller action.
getAction()
getActionParams()Returns the request parameters that will be used for action parameter binding.
getCachingStack()
getClips()Returns the list of clips.
getEventHandlers()Returns the list of attached event handlers for an event.
getId()
getLayoutFile()Looks for the layout view script based on the layout name.
getModule()
getPageState()Returns a persistent page state value.
getPageTitle()
getRoute()
getUniqueId()
getViewFile()Returns the view script file according to the specified view name.
getViewPath()Returns the directory containing view files for this controller.
hasEvent()Determines whether an event is defined.
hasEventHandler()Checks whether the named event has attached handlers.
hasProperty()Determines whether a property is defined.
init()Initializes the controller.
invalidActionParams()This method is invoked when the request parameters do not satisfy the requirement of the specified action.
isCachingStackEmpty()Returns whether the caching stack is empty.
missingAction()Handles the request whose action is not recognized.
processDynamicOutput()Postprocesses the dynamic output.
processOutput()Postprocesses the output generated by {@link render()}.
raiseEvent()Raises an event.
recordCachingAction()Records a method call when an output cache is in effect.
redirect()Redirects the browser to a given URL.
redirectToPostedUrl()Redirects to the URI specified in the POST.
refresh()Refreshes the current page.
render()Renders a view with a layout.
renderClip()Renders a named clip with the supplied parameters.
renderDynamic()Renders dynamic content returned by the specified callback.
renderDynamicInternal()This method is internally used.
renderFile()Renders a view file.
renderInternal()Renders a view file.
renderPartial()Renders a view.
renderTemplate()Renders a template, and either outputs or returns it.
renderText()Renders a static text string.
requireAdmin()Throws a 403 error if the current user is not an admin.
requireAjaxRequest()Throws a 400 error if this isn’t an Ajax request.
requireElevatedSession()Requires that the user has an elevated session.
requireLogin()Redirects the user to the login template if they're not logged in.
requirePostRequest()Throws a 400 error if this isn’t a POST request
requireToken()Throws a 400 error if the current request doesn’t have a valid token.
resolveViewFile()Finds a view file based on its name.
returnErrorJson()Responds to the request with a JSON error message.
returnJson()Responds to the request with JSON.
run()Runs the named action.
runAction()Runs the action after passing through all filters.
runActionWithFilters()Runs an action with the specified filters.
setAction()
setPageState()Saves a persistent page state value.
setPageTitle()
widget()Creates a widget and executes it.

actionActivateUser()

Manually activates a user account. Only admins have access.

View source

Returns

null

Signature

public null actionActivateUser ( )

actionCropUserPhoto()

Crop user photo.

View source

Returns

null

Signature

public null actionCropUserPhoto ( )

actionDeleteUser()

Signature

public null actionDeleteUser ( )

actionDeleteUserPhoto()

Delete all the photos for current user.

View source

Returns

null

Signature

public null actionDeleteUserPhoto ( )

actionEditUser()

Edit a user account.

View source

Arguments

Returns

null

Throws

Signature

public null actionEditUser ( array $variables = [], $account = null )

actionForgotPassword()

DEPRECATED

Deprecated Deprecated in 2.3. Use {@link actionSendPasswordResetEmail()} instead.

Sends a Forgot Password email.

View source

Returns

null

Signature

public null actionForgotPassword ( )

actionGetAuthTimeout()

Returns how many seconds are left in the current user session.

View source

Returns

null

Signature

public null actionGetAuthTimeout ( )

actionGetElevatedSessionTimeout()

Returns how many seconds are left in the current elevated user session.

View source

Returns

null

Signature

public null actionGetElevatedSessionTimeout ( )

actionGetPasswordResetUrl()

Generates a new verification code for a given user, and returns its URL.

View source

Returns

null

Throws

  • \Craft\HttpException|\Craft\Exception

Signature

public null actionGetPasswordResetUrl ( )

actionImpersonate()

Logs a user in for impersonation. Requires you to be an administrator.

View source

Returns

null

Signature

public null actionImpersonate ( )

actionLogin()

Displays the login template, and handles login post requests.

View source

Returns

null

Signature

public null actionLogin ( )

actionLogout()

Signature

public null actionLogout ( )

actionSaveFieldLayout()

Saves the user field layout.

View source

Returns

null

Signature

public null actionSaveFieldLayout ( )

actionSaveProfile()

DEPRECATED

Deprecated Deprecated in 2.0. Use {@link UsersController::saveUser()} instead.

Saves a user's profile.

View source

Returns

null

Signature

public null actionSaveProfile ( )

actionSaveUser()

Provides an endpoint for saving a user account. This action accounts for the following scenarios:

  • An admin registering a new user account.
  • An admin editing an existing user account.
  • A normal user with user-administration permissions registering a new user account.
  • A normal user with user-administration permissions editing an existing user account.
  • A guest registering a new user account ("public registration").

This action behaves the same regardless of whether it was requested from the Control Panel or the front-end site.

View source

Returns

null

Throws

  • \Craft\HttpException|\Craft\Exception

Signature

public null actionSaveUser ( )

actionSendActivationEmail()

Sends a new activation email to a user.

View source

Returns

null

Throws

Signature

public null actionSendActivationEmail ( )

actionSendPasswordResetEmail()

Sends a password reset email.

View source

Returns

null

Throws

Signature

public null actionSendPasswordResetEmail ( )

actionSetPassword()

Sets a user's password once they've verified they have access to their email.

View source

Returns

null

Throws

  • \Craft\HttpException|\Craft\Exception

Signature

public null actionSetPassword ( )

actionStartElevatedSession()

Starts an elevated user session.

View source

Returns

null

Signature

public null actionStartElevatedSession ( )

actionSuspendUser()

Suspends a user.

View source

Returns

null

Throws

Signature

public null actionSuspendUser ( )

actionUnlockUser()

Unlocks a user, bypassing the cooldown phase.

View source

Returns

null

Throws

Signature

public null actionUnlockUser ( )

actionUnsuspendUser()

Unsuspends a user.

View source

Returns

null

Throws

Signature

public null actionUnsuspendUser ( )

actionUploadUserPhoto()

Upload a user photo.

View source

Returns

null

Signature

public null actionUploadUserPhoto ( )

actionValidate()

DEPRECATED

Deprecated Deprecated in 2.3. Use {@link UsersController::actionVerifyEmail()} instead.

Verifies that a user has access to an email address.

View source

Returns

null

Signature

public null actionValidate ( )

actionVerifyEmail()

Verifies that a user has access to an email address.

View source

Returns

null

Signature

public null actionVerifyEmail ( )

actionVerifyPassword()

Verifies a password for a user.

View source

Returns

boolean

Signature

public boolean actionVerifyPassword ( )

Protected Methods

MethodDescription
afterAction()This method is invoked right after an action is executed.
afterRender()This method is invoked after the specified view is rendered by calling {@link render()}.
beforeRender()This method is invoked at the beginning of {@link render()}.
createActionFromMap()Creates the action instance based on the action map.
loadPageStates()Loads page states from a hidden input.
replaceDynamicOutput()Replaces the dynamic content placeholders with actual content.
savePageStates()Saves page states as a base64 string.

Constants

ConstantDescription
STATE_INPUT_NAMEName of the hidden field storing persistent page states.