Login
Last updated Feb 13th, 2024 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$311 per month—let's make that $500!
Learn moreWhat 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 |
loginViaEmail | (1.9.4-pl+) Accept logins either via username (from modUser) or email address (from modUserProfile). Built in protection: If an email address exists more than once, the corresponding users can't login via email address! | false |
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. | modChunk |
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 | 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 |
Optional Properties (non Login)¶
Helpful parameters which can facilitate Login.
Name | Description | Default |
---|---|---|
recaptchaHeight | Can be used to modify the ReCaptcha iframe Height attribute size. | 300 |
recaptchaTheme | Can be used to modify the ReCaptcha theme to 'red', 'white', 'blackglass', 'clean', or others as they are introduced by Google. | clean |
recaptchaWidth | Can be used to modify the ReCaptcha iframe Width attribute size. | 500 |
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.
See See Optional Properties for ReCaptcha specific settings
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¶
- Login.Login
- Login.Profile
- Login.UpdateProfile
- Login.Register
- Login.ConfirmRegister
- Login.ForgotPassword
- Login.ResetPassword
- Login.ChangePassword
- Login.Tutorials
See also the documentation on Making Member-Only Pages