MODX Cloud

The Most Productive MODX Learning Playground Ever

Claim Free Lab Account

Login.Login

Skip to end of metadata
Go to start of metadata


What is Login?

This component loads a simple login and logout form, and processes User authentication.

Usage

Example for Login:

[[!Login]]

You can also specify the template, however make sure to call the &tplType parameter also:

[[!Login? &tplType=`modChunk` &loginTpl=`myLoginChunk`]]

See the snippet properties for more options.

Properties

Login comes with some configuration properties you can set to adjust the way Login behaves.

Name Description Default
actionKey The REQUEST variable that indicates what action to take. Defaults to 'service'. This is useful to change if you're already using the 'service' REQUEST variable in your website. service
loginKey The login action key. Defaults to 'login'. This tells Login to fire only if the actionKey property is set to this value. For example, if actionKey is set to 'service', and this is set to 'login', then the login processor will only fire if the request '&service=login' is found. login
logoutKey The logout action key. Defaults to 'logout'. This tells Login to fire only if the actionKey property is set to this value. For example, if actionKey is set to 'service', and this is set to 'logout', then the logout processor will only fire if the request '&service=logout' is found. logout
rememberMeKey Optional. The field name of the Remember Me toggle to preserve login state. Defaults to "rememberme". rememberme
tplType The type of tpls being provided by loginTpl or logoutTpl. See the section below for the possible values.
inline
loginTpl The login form tpl. May be the type specified by the tplType property. lgnLoginTpl
logoutTpl The logout form tpl. May be the type specified by the tplType property lgnLogoutTpl
errTpl The error message tpl. May be the type specified by the errTplType property. lgnErrTpl
errTplType The type of tpls being provided by errTpl. modChunk
loginResourceId The resource to direct users to on successful login. 0 will redirect to self. Leave out if using the default unauthorized page. 0
loginResourceParams A JSON object of parameters to append to the login redirection URL. Ex: {"test":123} translates to url.html?test=123  
logoutResourceId Resource ID to redirect to on successful logout. 0 will redirect to self. 0
logoutResourceParams A JSON object of parameters to append to the logout redirection URL. Ex: {"test":123} translates to url.html?test=123  
loginMsg Optional label message for login action. If blank, will default to lexicon string for Login.  
logoutMsg Optional label message for logout action. If blank, will default to lexicon string for Logout.  
redirectToPrior If true, will redirect to the referring page (HTTP_REFERER) on successful login. 0
contexts (Experimental) A comma-separated list of contexts to log in to. Defaults to the current context if not explicitly set.  
preHooks A comma-separated list of 'hooks', or Snippets, that will be executed before the user is registered but after validation. Also can specify 'recaptcha' as a hook.  
postHooks A comma-separated list of 'hooks', or Snippets, that will be executed after the user is registered.  
toPlaceholder If set, will set the output of the login snippet to a placeholder of this name rather than directly outputting the return contents.  
redirectToOnFailedAuth (1.6.4-pl & +) redirects to a separate page on failed logins  

tplType Options

The tplType and errTplType properties have a list of different options to choose from. This can be:

  • modChunk - The tpl provided must be the name of a chunk.
  • file - Must be an absolute path to the tpl file.
  • inline - The content of the tpl will be directly in the tpl property itself.
  • embedded - The tpl is already in the page; just make the error properties be placeholders.

Using reCaptcha

First off, make sure your `recaptcha.public_key` and `recaptcha.private_key` System Settings are set with your reCaptcha API keys. Then, to add it, all you have to do is add the "recaptcha" preHook to your snippet call:

[[!Login? &preHooks=`recaptcha`]]

And make sure that the [[+login.recaptcha_html]] placeholder is in your loginTpl chunk. This will make reCaptcha be required for login.

Logout

How do I log out? You simply call the page containing your Login snippet call and pass specify 'logout' as the service via the URL. In this example, the Login snippet is contained on page 21:

<a href="[[~21? &service=logout]]" title="Logout">Logout</a>
(which automatically appends '&service=logout' to your URL)

See Also

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 18, 2011

    YJ Tso says:

    See also the documentation on Making Member-Only Pages

    See also the documentation on Making Member-Only Pages

  2. Jan 28

    Bert Oost says:

    I have made a second context for a login part.. setupped all necessary things li...

    I have made a second context for a login part.. setupped all necessary things like rights etc.

    I want to have the homepage secured, so bind it to the resource group and in my context I set the "unauthorized_page" to the ID of the resource where the login is located. This doesn't work!! Because the homepage is the "site_start" I think, this one can't be secured (as I think)... What I find out is that I get a 404 header response I added "error_page" setting with the same ID of the unauthorized page and now it works like a charm.

    Besides that, I use a plugin to switch context based on the http_host. Because of this, on the submit Login thinks we're on "web" and don't logs in the user. I need to add &contexts=`web,login` to get that working too.. 

    At the end it all works, but thought I can share this with others ;-)