# Front-end user plugin Front-end user management for October CMS. ## Requirements This plugin requires the [Ajax Framework](https://octobercms.com/docs/cms/ajax) to be included in your layout/page in order to handle form requests. ## Managing users Users are managed on the Users tab found in the back-end. Each user provides minimal data fields - **Name**, **Surname**, **Email** and **Password**. The Name can represent either the person's first name or their full name, making the Surname field optional, depending on the complexity of your site. Below the **Email** field is an checkbox to block all outgoing mail sent to the user. This is a useful feature for accounts with an email address that is bouncing mail or has reported spam. When checked, no mail will ever be sent to this address, except for the mail template used for resetting the password. ## Plugin settings This plugin creates a Settings menu item, found by navigating to **Settings > Users > User settings**. This page allows the setting of common features, described in more detail below. #### Registration Registration to the site is allowed by default. If you are running a closed site, or need to temporarily disable registration, you may disable this feature by switching **Allow user registration** to the OFF setting. #### Activation Activation is a process of vetting a user who joins the site. By default, users are activated automatically when they register and an activated account is required to sign in. The **Activation mode** specifies the activation workflow: - **Automatic**: This mode will automatically activate a user when they first register. This is the same as disabling activation entirely and is the default setting. - **User**: The user can activate their account by responding to a confirmation message sent to their nominated email address. - **Administrator**: The user can only be activated by an administrator via the back-end area. You can allow users to sign in without activating by switching **Sign in requires activation** to the OFF setting. This is useful for minimising friction when registering, however with this approach it is often a good idea to disable any "identity sensitive" features until the user has been activated, such as posting content. Alternatively, you could implement a grace period that deletes users (with sufficient warning!) who have not activated within a given period of time. Users have the ability to resend the activation email by clicking **Send the verification email again** found in the Account component. #### Sign in By default a User will sign in to the site using their email address as a unique identifier. You may use a unique login name instead by changing the **Login attribute** value to Username. This will introduce a new field called **Username** for each user, allowing them to specify their own short name or alias for identification. Both the Email address and Username must be unique to the user. If a user experiences too many failed sign in attempts, their account will be temporarily suspended for a period of time. This feature is enabled by default and will suspend an account for 15 minutes after 5 failed sign in attempts, for a given IP address. You may disable this feature by switching **Throttle attempts** to the OFF setting. As a security precaution, you may restrict users from having sessions across multiple devices at the same time. Enable the **Prevent concurrent sessions** setting to use this feature. When a user signs in to their account, it will automatically sign out the user for all other sessions. #### Notifications This feature is implemented by the Notify plugin. How to use this feature: - Install the **RainLab.Notify** plugin - Navigate to **Settings > Notification** rules - Click **New notification rule** - Select **User > Activated** - Click **Add action** - Select **Compose a mail message** - Select **User email address** for the **Send to** field - Here you may select the Mail template previously defined in the user settings. - Click **Save** ## Extended features For extra functionality, consider also installing the [User Plus+ plugin](http://octobercms.com/plugin/rainlab-userplus) (`RainLab.UserPlus`). ## Session component The session component should be added to a layout that has registered users. It has no default markup. ### User variable You can check the logged in user by accessing the **{{ user }}** Twig variable: {% if user %}
Hello {{ user.name }}
{% else %}Nobody is logged in
{% endif %} ### Signing out The Session component allows a user to sign out of their session. Sign out ### Page restriction The Session component allows the restriction of a page or layout by allowing only signed in users, only guests or no restriction. This example shows how to restrict a page to users only: title = "Restricted page" url = "/users-only" [session] security = "user" redirect = "home" The `security` property can be user, guest or all. The `redirect` property refers to a page name to redirect to when access is restricted. ### Route restriction Access to routes can be restricted by applying the `AuthMiddleware`. Route::group(['middleware' => 'RainLab\User\Classes\AuthMiddleware'], function () { // All routes here will require authentication }); ## Account component The account component provides a user sign in form, registration form, activation form and update form. To display the form: title = "Account" url = "/account/:code?" [account] redirect = "home" paramCode = "code" == {% component 'account' %} If the user is logged out, this will display a sign in and registration form. Otherwise, it will display an update form. The `redirect` property is the page name to redirect to after the submit process is complete. The `paramCode` is the URL routing code used for activating the user, only used if the feature is enabled. ## Reset Password component The reset password component allows a user to reset their password if they have forgotten it. title = "Forgotten your password?" url = "/forgot-password/:code?" [resetPassword] paramCode = "code" == {% component 'resetPassword' %} This will display the initial restoration request form and also the password reset form used after the verification email has been received by the user. The `paramCode` is the URL routing code used for resetting the password. ## Using a login name By default the User plugin will use the email address as the login name. To switch to using a user defined login name, navigate to the backend under System > Users > User Settings and change the Login attribute under the Sign in tab to be **Username**. Then simply ask for a username upon registration by adding the username field: We can add any other additional fields here too, such as `phone`, `company`, etc. ## Password length requirements By default, the User plugin requires a minimum password length of 8 characters for all users when registering or changing their password. You can change this length requirement by going to backend and navigating to System > Users > User Settings. Inside the Registration tab, a **Minimum password length** field is provided, allowing you to increase or decrease this limit to your preferred length. ## Error handling ### Flash messages This plugin makes use of October's [`Flash API`](http://octobercms.com/docs/markup/tag-flash). In order to display the error messages, you need to place the following snippet in your layout or page. {% flash %}