Giter Site home page Giter Site logo

getgrav / grav-plugin-login Goto Github PK

View Code? Open in Web Editor NEW
44.0 9.0 54.0 2.81 MB

Grav Login Plugin

Home Page: http://getgrav.org

License: MIT License

PHP 89.46% CSS 0.85% JavaScript 0.65% Twig 9.04%
grav grav-plugin login login-system user-registration authentication

grav-plugin-login's Introduction

Grav Login Plugin

The login plugin for Grav adds login, basic ACL, and session wide messages to Grav. It is designed to provide a way to secure front-end and admin content throughout Grav.

Installation

The login plugin actually requires the help of the email and form plugins. The email plugin is needed to ensure that you can recover a password via email if required. The form plugin is used to generate the forms required.

These are available via GPM, and because the plugin has dependencies you just need to proceed and install the login plugin, and agree when prompted to install the others:

$ bin/gpm install login

Changes in version 3.2

New events:

  • onUserLoginAuthorized Allows plugins to include their own logic when user gets authorized (usually after 2FA challenge).

Changes in version 3.1

New events:

  • onUserActivated Allows plugins to hook into user activation, when user has clicked on confirmation email.

Changes in version 2.6

  • User registration is now disabled by default. If you were relying on it being activated, you need to manually enable it in your user/config/plugins/login.yaml:

    user_registration:
      enabled: true 
    
  • login_after_registration has also been changed to a default value of false for security purposes.

Changes in version 2.5

Added new $grav['login']->login() and $grav['login']->logout() functions for you to use.

They use following events which can be hooked by plugins:

  • onUserLoginAuthenticate Allows plugins to include their own authentication methods.
  • onUserLoginAuthorize Allows plugins to block user from being logged in.
  • onUserLoginFailure Allows plugins to include their own logic when user authentication failed.
  • onUserLogin Allows plugins to include their own logic when user logs in.
  • onUserLogout Allows plugins to include their own logic when user logs out.
  • onUserLoginRegisterData Allows plugins to include their own data to be added to the user object during registration.
  • onUserLoginRegistered Allows plugins to hook into user registration just before the redirect.

All the events use UserLoginEvent with some useful methods to see what is going on.

New Plugin options have been added for:

  • dynamic_page_visibility - Integrate access into page visibility so things can be shown or hidden in the menu

Changes in version 2.0

  • OAuth has been separated to its own plugin, needs to be installed separately and configured. The users account filename format has changed too, to fix an issue that involved people with the same name on a service.
  • The redirect option has been changed to redirect_after_login.
  • The Remember Me session minimum length is now 1 week.
  • Removed the option to login from oauth without creating the corresponding user file under user/accounts/.

Messages Output

There is not a guaranteed way to display system messages including those added by the Login plugin, so in order to see messages you will need to make sure your theme has a method to output the messages. This is done by adding a simple Twig include, and the best place to do this to ensure it's visible in all your pages, is to add it to the partials/base.html.twig (or whatever your base Twig template is called):

    {% block messages %}
        {% include 'partials/messages.html.twig' ignore missing %}
    {% endblock %}

A good location is probably to add this right above where your content is going to be output.

Creating Users

You can either use the built-in CLI capabilities, or you create a user manually by creating a new YAML file in your user/accounts folder.

CLI Usage

The simplest way to create a new user is to simply run the bin/plugin login new-user command. This will take you through a few questions to gather information with which to create your user. You can also use inline arguments to avoid the interactive questions.

Commands

Command Arguments Explination
new-user Creates a new user (creates file in user/accounts/)
[ -u, --user=USER ] The username.
[ -p, --password=PASSWORD ] The password. Ensure the password respects Grav's password policy. Note that this option is not recommended because the password will be visible by users listing the processes.
[ -e, --email=EMAIL ] The user email address.
[ -P, --permissions=PERMISSIONS ] The user permissions. It can be either a for Admin access only, s for Site access only and b for both Admin and Site access.
[ -N, --fullname=FULLNAME ] The user full name
[ -t, --title=TITLE ] The title of the user. Usually used as a subtext. Example: Admin, Collaborator, Developer
[ -s, --state=STATE ] The state of the account. Either enabled (default) or disabled
change-pass Changes password of the specified user (User file must exist)
[ -u, --user=USER ] The username.
[ -p, --password=PASSWORD ] The new password. Ensure the password respects Grav's password policy. Note that this option is not recommended because the password will be visible by users listing the processes.

CLI Example

> bin/plugin login new-user -u joeuser -p 8c9sRCeBExAiwk -e [email protected] -P b -N "Joe User" -t "Site Administrator"
Creating new user


Success! User joeuser created.

Interactive Example

> bin/plugin login new-user
Creating new user

Enter a username: joeuser
Enter a password: 8c9sRCeBExAiwk
Enter an email:   [email protected]
Please choose a set of permissions:
  [a] admin access
  [s] site access
  [b] admin and site access
 > b
Enter a fullname: Joe User
Enter a title:    Site Administrator
Please choose the state for the account:
  [enabled ] Enabled
  [disabled] Disabled
 > enabled

Success! User joeuser created.

Manual User Creation

Here is example user defined in user/accounts/admin.yaml:

password: password
email: [email protected]
fullname: Johnny Appleseed
title: Site Administrator
access:
  admin:
    login: true
    super: true

Note: the username is based on the name of the YAML file.

Default Configuration

enabled: true                               # Enable the plugin
built_in_css: true                          # Use built-in CSS
redirect_to_login: false                    # If you try to access a page you don't have access to, should you redirect to login route
redirect_after_login: true                  # Path to redirect to after a successful login
redirect_after_logout: true                 # Path to redirect to after a successful logout

route: '/login'                             # Specific route for Login page (default is '/login')
route_after_login:                          # Route to go to after login if enabled
route_after_logout:                         # Route to logout to if enabled
route_activate: '/activate_user'            # Route for the user activation process
route_forgot: '/forgot_password'            # Route for the forgot password process
route_reset: '/reset_password'              # Route for the reset password process
route_profile: '/user_profile'              # Route for the user profile page
route_register: '/user_register'            # Route for the user registration page
route_unauthorized: '/user_unauthorized'    # Route for a page to display if user is unauthorized

twofa_enabled: false                        # Two factor authentication enabled
dynamic_page_visibility: false              # Integrate access into page visibility so things can be shown or hidden in the menu
parent_acl: false                           # Look to parent `access` rules for access requirements
protect_protected_page_media: false         # Take `access` rules into account when directly accessing a page's media

rememberme:
  enabled: true                             # Enable 'remember me' functionality
  timeout: 604800                           # Timeout in seconds. Defaults to 1 week
  name: grav-rememberme                     # Name prefix of the session cookie

max_pw_resets_count: 2                      # Number of password resets in a specific time frame (0 = unlimited)
max_pw_resets_interval: 60                  # Time in minutes to track password resets
max_login_count: 5                          # Number of failed login attempts in a specific time frame (0 = unlimited)
max_login_interval: 10                      # Time in minutes to track login attempts
ipv6_subnet_size: 64                        # Size of IPv6 block to track login attempts

user_registration:
  enabled: false                            # Enable User Registration Process

  fields:                                   # List of fields to validate and store during user registration
    - 'username'                            # This should match up with your registration form definition
    - 'password'
    - 'email'
    - 'fullname'
    - 'title'
    - 'level'
    - 'twofa_enabled'

  default_values:                           # Any default values for fields you would like to set
    level: Newbie                           # Here the 'level' field will be pre-populated with 'Newbie' text

  access:                                   # Default access to set for users created during registration
    site:
      login: 'true'

  redirect_after_registration: ''           # Route to redirect to after registration
  redirect_after_activation: ''             # Route to redirect to after activation

  options:
    validate_password1_and_password2: true  # Ensure that password1 and password2 match during registration (allows you to have just 1 pw field or 2)
    set_user_disabled: false                # Set this `true` if you want a user to activate their account via email
    login_after_registration: false         # Automatically login after registration
    send_activation_email: false            # Send an email that requires a special link to be clicked in order to activate the account
    manually_enable: false                  # When using activation email, don't enable until an admin does it manually
    send_notification_email: false          # Send an email to the site administrator to indicate a user has registered
    send_welcome_email: false               # Send a welcome email to the user (probably should not be used with `send_activation_email`

Usage

You can add ACL to any page by typing something like below into the page header:

access:
  site.login: true
  admin.login: true

Users who have any of the listed ACL roles enabled will have access to the page. Others will be forwarded to login screen.

Because the admin user contains an admin.login: true reference he will be able to login to the secured page because that is one of the conditions defined in the page header. You are free to create any specific set of ACL rules you like. Your user account must simply contain those same rules if you wish the user to have access.

Create Private Areas

Enabling the setting "Use parent access rules" (parent_acl in login.yaml) allows you to create private areas where you set the access level on the parent page, and all the subpages inherit that requirement.

Login Page

Note: the frontend site and admin plugin use different sessions so you need to explicitly provide a login on the frontend.

The login plugin can automatically generate a login page for you when you try to access a page that your user (or guest account) does not have access to.

Alternatively, you can also provide a specific login route if you wish to forward users to a specific login page. To do this you need to create a copy of the login.yaml from the plugin in your user/config/plugins folder and provide a specific route (or just edit the plugin settings in the admin plugin).

route: /user-login

You would then need to provide a suitable login form, probably based on the one that is provided with the plugin.

Redirection after Login

By default Grav will redirect to the prior page visited before entering the login process. Any page is fair game unless you manually set:

login_redirect_here: false

In the page's header. If you set this value to false, this page will not be a valid redirect page, and the page visited prior to this page will be considered.

You can override this default behavior by forcing a standard location by specifying an explicit option in your Login configuration YAML:

redirect_after_login: '/profile'

This will always take you to the /profile route after a successful login.

Logout

The login plugin comes with a simple Twig partial to provide a logout link (login-status.html.twig). You will need to include it in your theme however. An example of this can be found in the Antimatter theme's partials/navigation.html.twig file:

{% if config.plugins.login.enabled and grav.user.username %}
    <li><i class="fa fa-lock"></i> {% include 'partials/login-status.html.twig' %}</li>
{% endif %}

You can also copy this login-status.html.twig file into your theme and modify it as you see fit.

Allow User Registration

The Login plugin handles user registration. To enable the built-in registration form, in the Login Plugin configuration enable user registration and just add a value to the "Registration path" field.

Then just open your browser on that page, and you'll be presented a registration form.

Adding the registration page to the menu

Here are two ways you can do it, but of course Grav is flexible and you can come up with other ways too.

The first and easiest way is to add a page with the same slug (route) as the registration form. So for example if in the Login Plugin settings you set /register as the registration form path, then create a 04.register page (the 04 number is just an example, use your own ordering), with no content. The Login plugin will "override" that page, serving the registration page form when the user clicks on that menu item.

A second way is to add a custom menu item that points to the registration page, by editing site.yaml with this code, that will append a "Register" menu item:

menu:
  -
    url: 'register'
    text: Register

This works in most themes, Antimatter included, but it's not guaranteed to work in all themes, as it's something that must be added to the navigation twig code.

Customizing the registration form

The provided registration form is just a quick way to start using it. You might however need different fields on the registration form, or you want to add more content. Here's how to do it.

First, create a registration form page.

Create a folder 04.registration/form.md. The folder name is just an example. Pick the one that suits you. The important part is the file name: since we're building a form, we need a form.md file.

Also, your theme needs to implement forms. Use Antimatter or another form-compatible theme if yours does not work, then once you're setup with the form you can migrate the forms files and make it work on your theme too.

Add the following content to your registration form page:

---
form:

  fields:
    fullname:
      type: text
      validate:
        required: true

    username:
      type: text
      validate:
        required: true
        message: PLUGIN_LOGIN.USERNAME_NOT_VALID
        config-pattern@: system.username_regex

    email:
      type: email
      validate:
        required: true
        message: PLUGIN_LOGIN.EMAIL_VALIDATION_MESSAGE

    password1:
      type: password
      label: Enter a password
      validate:
        required: true
        message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
        config-pattern@: system.pwd_regex

    password2:
      type: password
      label: Enter the password again
      validate:
        required: true
        message: PLUGIN_LOGIN.PASSWORD_VALIDATION_MESSAGE
        config-pattern@: system.pwd_regex

  buttons:
      -
          type: submit
          value: Submit
      -
          type: reset
          value: Reset

  process:
      register_user: true
      message: "Thanks for registering..."
      reset: true      
---

Registration of Users

Create a new user account by entering all the required fields below:

This is a normal form. The only thing different from a contact form or another form that you might write on your site is the process field register_user, which takes care of processing the user registration.

Once the user is registered, Grav redirects the user to the display page with the message message.

The only field strictly required by Grav is username. Then the other fields can be added as needed.

For example in this case we added

  • password1
  • password2

to the form. And, in the Login plugin configuration we have by default enable the double password verification with the "Validate double entered password" option. What this does is picking the password1 and password2 fields, validate them, check they are equal and put the content in the password field.

You can avoid having 2 fields for the password, which by the way is a recommended option, and just put a single password field.

Last important thing before the registration is correctly setup: make sure in the Login plugin settings you have the user registration enabled, otherwise the registration will trigger an error, as by default user registration is DISABLED.

Registration Options

There are several options that can be configured when registering users via user/plugins/login.yaml, they are pretty self-explanatory:

user_registration:
  enabled: false                            # Enable User Registration Process

  fields:                                   # List of fields to validate and store during user registration
    - 'username'                            # This should match up with your registration form definition
    - 'password'
    - 'email'
    - 'fullname'
    - 'title'
    - 'level'

  default_values:                           # Any default values for fields you would like to set
    level: Newbie                           # Here the 'level' field will be pre-populated with 'Newbie' text

  access:                                   # Default access to set for users created during registration     
    site:
      login: 'true'

  redirect_after_registration: ''           # Route to redirect to after registration

  options:
    validate_password1_and_password2: true  # Ensure that password1 and password2 match during registration (allows you to have just 1 pw field or 2)
    set_user_disabled: false                # Set this `true` if you want a user to activate their account via email
    login_after_registration: false         # Automatically login after registration
    send_activation_email: false            # Send an email that requires a special link to be clicked in order to activate the account
    send_notification_email: false          # Send an email to the site administrator to indicate a user has registered
    send_welcome_email: false               # Send a welcome email to the user (probably should not be used with `send_activation_email`

Sending an activation email

By default the registration process adds a new user, and sets it as enabled. Grav allows disabled user accounts, so we can take advantage of this functionality and add a new user, but with a disabled state. Then we can send an email to the user, asking to validate the email address.

That validation email will contain a link to set the user account to enabled. To do this, just enable "Set the user as disabled" and "Send activation email" in the Login Plugin options.

Send a welcome email

Enable "Send welcome email" in the options.

The content of the welcome email is defined in the language file, strings PLUGIN_LOGIN.WELCOME_EMAIL_SUBJECT and PLUGIN_LOGIN.WELCOME_EMAIL_BODY. Customize them as needed in your language file override.

Note: if the activation email is enabled, the welcome email to be sent upon the account activation action (when the user clicks the link to activate the account)

Send a notification email to the site owner

Enable "Send notification email" in the options.

The content of the notification email is defined in the language file, strings PLUGIN_LOGIN.NOTIFICATION_EMAIL_SUBJECT and PLUGIN_LOGIN.NOTIFICATION_EMAIL_BODY. Customize them as needed in your language file override.

Note: if the activation email is enabled, the notification email to be sent upon the account activation action (when the user clicks the link to activate the account)

Default Access

To control what access your users have upon registering you can edit the user_registration.access: attribute in the user/plugins/login.yaml. The default is simply site.login: true:

user_registration:
  access:
    site:
      login: 'true'

Adding your own fields

If you want to add your own custom fields to the registration form, just add fields to the form like you would with any other form.

Then, to let the Login plugin add those fields to the user yaml file, you also need to add it to the "Registration fields" option in the Login Plugin configuration.

By default we have

user_registration:
  fields:
    - 'username'
    - 'password'
    - 'email'
    - 'fullname'
    - 'title'

Add your own as you prefer, to build any custom registration form you can think of.

Specifying a default value for a field

If you want to pre-fill a field, without showing it to the user in the form, you could set it as an hidden field. But the user could see it - and modify it via the browser dev tools.

To add a field and make sure the user cannot modify it, add it to "default_values" list:

user_registration:
    default_values:
        title: "Newbie User"

Login users directly after the registration

Just enable "Login the user after registration"

If the user activation email is enabled, the user will be logged in as soon as the activation link is clicked.

Add captcha to the user registration

Add a captcha like you would with any form:

Add

        - name: g-recaptcha-response
          label: Captcha
          type: captcha
          recaptcha_site_key: aeio43kdk3idko3k4ikd4
          recaptcha_not_validated: 'Captcha not valid!'
          validate:
            required: true

to the form field, and

process:
  - captcha

to validate it server-side. Put this process action before all the other actions, so it's processed first and the user is not created if the captcha is not valid.

Redirect to another page after login

You can set the "Redirect after registration" option in the Login plugin, or as with any form, use the process.display property, and set it to the destination page route:

  process:
     -
       display: /welcome

Dynamic Page Visibility

You can control whether or not a page is visible to a user by first enabling the option in the login configuration:

dynamic_page_visibility: true

With this activated you can put the following option into the header of each page:

login:
    visibility_requires_access: true

This will ensure the access: options on the page are satisfied in order for this page to be visible and therefore displayed in the menu structure.

Known issues

When updating from an older version, pre-october 2015, you might have an error Class 'Grav\Login\Controller' Not Found. The problem is during the update, since a file name was changed from lowercase to capitalized. Solution: reinstall the Login plugin, or change the file name user/plugins/login/classes/controller.php to user/plugins/login/classes/Controller.php (notice the capital C).

grav-plugin-login's People

Contributors

akoebbe avatar all-sd avatar beneva52 avatar bitstarr avatar codebee-fr avatar diomed avatar flaviocopes avatar hughbris avatar jgonyea avatar karmalakas avatar kvanderloock-site-works avatar lauroguedes avatar lucasvieites avatar lufog avatar mahagr avatar makarygo avatar masetto avatar matsxm avatar mibux avatar newbthenewbd avatar nketchum avatar pgrimaud avatar rhukster avatar rotzbua avatar sebastianbaumann avatar sommerregen avatar tcsizmadia avatar viliuss avatar vivalldi avatar w00fz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grav-plugin-login's Issues

Editing the registration and login pages.

Correct me if I'm wrong but as of now the registration page has to be edited outside of the plugin (in my theme's form template), and the login page has to be edited inside the plugin (the plugin's form template). This makes things pretty confusing when you want them both to look the same, and want to be able to use one template for both of them.

Is there a better way for me to go about this? Maybe it's too late to get this in the next release but could we maybe have the registration be included in the plugin as it's own page+template?

Set user redirection in the user profile

In order to differentiate between users more easily and serve them more targeted content it would be a great feature to specify the page to which a user is redirected in the user's account.yaml file, which would overwrite the default route set in the login.yaml

LDAP Support

Is there any current support or planned future support for LDAP Auth? If it's in the plans, has anything been written down about how it may function so I could potentially develop it?

ssl connection

If you access your site via https://www.example.com and you want to login you get the following:

The information you have entered on this page will be sent over an insecure connection and could be read by a third party.

Are you sure you want to send this information?

also plugin redirects not to https:// again after login just to http://

Moving the /user/accounts to a path outside the webroot?

Is there a way to move the /user/accounts directory to another location outside the webroot for security reasons? I'm not seeing a config for that and it seems like user://accounts/ is being used a number of times in the code.

Redirect on login not working.

redirect: /main

is set in the login.yaml file, and reflects under the 'redirect on login' section of the admin dashboard as well. Here's the login function of my LoginController.php:

public function taskLogin()
    {
        $t = $this->grav['language'];
        if ($this->authenticate($this->post)) {
            $this->setMessage($t->translate('PLUGIN_LOGIN.LOGIN_SUCCESSFUL'));
            $referrer = $this->grav['uri']->referrer('/');
            $this->setRedirect($referrer);
        } else {
            $user = $this->grav['user'];
            if ($user->username) {
                $this->setMessage($t->translate('PLUGIN_LOGIN.ACCESS_DENIED'), 'error');
            } else {
                $this->setMessage($t->translate('PLUGIN_LOGIN.LOGIN_FAILED'), 'error');
            }
        }

        return true;
    }

and everything looks kosher to me, but I'm not even sure I'm looking in the right place... and I'm level 0 in the PHP skilltree.

Do I need to be looking in the Controller.php at the redirect functions there instead? Thanks in advance.

ACL Access denied...

Registration and Login are working great. But, I login and try to access a private page, I get Access denied. How can I debug this?

config/plugins/login.yaml

parent_acl: true
protect_protected_page_media: true
user_registration:
  enabled: true
  fields:
    - firstname
    - lastname
    - company
    - 'job title'
    - email
    - username
    - password
  access:
    site:
      login: 'true'

accounts/user.yaml

access:
  site:
    login: 'true'

default.md

access:
  site:
    login: true

Usernames containing dots

Is there a reason why dots are not allowed in usernames?

We use a schema of firstname.lastname throughout our systems to simplify authenticating.

No {{uri.param('user')}} in password reset page

The password reset for the admin account was done on the public side /forgot_password. After clicking the link in the email, here is the password reset page.

Password Reset
Username: {{uri.param('user')}}

protect page and directory content

I have a page with login needed to access, is there a way to make the files in the directory also protected?
Let's have the following structure:
02.private/
├── default.md
└── protected.file.txt

I want to include the 'protected.file.txt' in default.md, but 'protected.file.txt' shouldn't be accesible for non-logged in users.

protect dropdown menu links on procted site

If you're setting up a protected site with subpages and enabling the dropdown menu for those subpages the drop down menu(links to subpages) is also shown when you're not logged in. It would be better if the dropdown menu is also hidden when the parent page is protected.

Server Error for nginx + php-fpm

screen shot 2015-12-04 at 1 57 55 pm

When updating GRAV and the following plugins on an environment (local) that uses apache the error shown above doesn't occur. GRAV version before update is v1.0.0-rc.4 after update is v1.0.0-rc.6

The plugins are...
screen shot 2015-12-04 at 2 02 41 pm

When moving from local to production (using nginx + php-fpm) with these updates this error occurs on Chrome, Firefox, and Safari on first page load. After that this error message occurs intermittently.

Login error should not trigger an error page

I mistyped my password while trying to login to the backoffice but instead of the simple error message Login failed added to the original login page I got this full error page:

…/­system/­src/­Grav/­Common/­Twig/­Twig.php300

Whoops \ Exception \ ErrorException (E_ERROR)

Call to a member function content() on a non-object
Open: /srv/data/web/vhosts/reachcontent.com/htdocs/system/src/Grav/Common/Twig/Twig.php

     */
    public function processSite($format = null)
    {
        // set the page now its been processed
        $this->grav->fireEvent('onTwigSiteVariables');
        $pages = $this->grav['pages'];
        $page = $this->grav['page'];
        $content = $page->content();
        $config = $this->grav['config'];

GET Data empty
POST Data
username _[correct login used]_
password _[wrong password typed; displayed in clear]_
task login
admin-nonce $2y$10$fHaePQnnA37EbUSLASHMyKeUrOhfMJxcjCbiJwefZSLASHSgtMsxLzsWPDc6K
Files empty
Cookies
grav-site-360e8fa-admin na964dfl6opnql30fb8a3oc7q0
Session
user Grav\Common\User\User Object ( [gettersVariable:protected] => items [items:protected] => Array ( ) [blueprints:protected] => [storage:protected] => )
expert
messages RocketTheme\Toolbox\Session\Message Object ( [messages:protected] => Array ( > [5ab00046cc2b8a920d69eba0a5350300] => Array ( [message] => Login failed [scope] => error ) ) )
Server/Request Data
USER hosting-user
HOME /
FCGI_ROLE RESPONDER
REDIRECT_STATUS 200
etc. etc.

Activation does not go to the login page

Clicking the activation link goes to the front page.
It should go to the login page so you can see the User activated successfully message and to login.

Under User Registration>Options, all options are checked except for Login the user after registration.

Also, I don't get the admin notification that a new user has registered.

Using develop and Antimatter theme.

Issue with authenticate method in LoginController.php. It's possible for a user to be authorised but not authenticated after login.

Steps to reproduce:

  1. Type in an incorrect password for a valid username.
  2. Instead of the "login failed" message, the user is redirected back to the login page and the message "you have successfully been logged in" is displayed.
  3. Type in an incorrect username and any password.
  4. The login page displays the "login failed" message as expected for step 2.

Solution:

In LoginController.php, I changed the lines 214-218 to:

                // Authenticate user.
                $user->authenticated = $user->authenticate($form['password']);

                if ($user->authenticated) {
                    $this->grav['session']->user = $user;

and lines 237-238 to:

    // Authorize against user ACL
    $userAuthorized = $user->authorize('site.login');
    $user->authenticated = ($user->authenticated && $userAuthorized);

    return $user->authenticated;

to get the login form to work as expected.

Username already exists

With my custom registration form, I keep getting Username already exists, please pick another username even though there is currently only one user with a different username.

[Question] Login full frontend site ?

Hello, I see it is possible to lock access to frontend pages individually. However, is there a way to lock the full frontend site and ask for the password whatever the page ?

Oauth creates users with faulty user rights

Correct working user rights on user.yaml are
access:
access:
site:
login: true

what oauth generates

access:
site.login: '1'

problem is not weather there is true or '1' but in the formatting which leads to setting rights manually.
@flaviocopes

It is safe to commit the password?

Right now their is no gitignore for the account's config file. That mean it's very easy to commit them by mistake and publicly publish password (encrypted) and account information.

I didn't check your code but I guess you are using strong encryption that is hard to break (not like md5) so it's should not be a problem. But still, I'm not sure it's a good idea to let peoples commit those files by default. Do you feel comfortable with that?

If you feel comfortable to commit those files, I think a short comment in the file explaining it's not a risk to commit those file would be a nice helper. Otherwise adding a gitignore in the account folder to exclude account config is the way to go.

(I'm very new to grav)

protected site still displays content

I want to set a page protected, this works in the way that a "login display" is provided for the site, but there is also the content of the site shown.

theme: antimatter

the file is:

bash-4.1$ cat pages/06.private/default.md

title: Private
access:
site.private: true

admin.login: true

protected stuff

protected stuff

protected stuff

protected stuff

![2016-01-27-201629_1918x1179_scrot](https://cloud.githubusercontent.com/assets/348359/12626251/13b35432-c538-11e5-829f-1d6a3e81aab9.png

Forgot Password page issue: Validation message is not displayed if a blank or invalid username is used

Steps to Reproduce:

  1. On the Forgot Password page, enter a username that does not exist, or leave the username blank.
  2. Press "Send Reset Instructions".
  3. A 404 message is displayed instead of the validation error message.

Solution:

The redirect links for error messages in the taskForgot method of LoginController.php have been hardcoded to the route "/forgot".

In the taskForgot method replace all the lines:
$this->setRedirect('/forgot');
with:
$this->setRedirect($this->grav['config']->get('plugins.login.route_forgot'));

Issues with Access denied and content

So I have found a couple of issues with the login plugin used on the front end. I don't know whether this is something to do with my setup or actually the plugin.

These happen if I try to access a page that my chosen user does not have permission for. After the login form has been completed the user does see the "Access Denied" message for the page, however I am also seeing the actual content of that page to which I am supposed to be denied.

By removing the {{ content }} token form the login-form.html.twig This can be resolved but then content of the login plugin such as its headers has to be manually inserted into the template.

Also once at the access denied screen I am still seeing the login submit button (no other form components), and there is no way to go back to a new login screen whit out doing a hard reload. Ideally I would like there to be a log out and try again button.

Login / Locale / Languages

Dear all,

I have my website in two different languages.
Before you login you choose your language, it sets it's locale based on the url, /fr/home or en/home,
en/home is default, but when choosing fr/home and logging in, it redirect me back to en/home.
Somehow it is working on my localhost, but not on the dev server.

Any ideas?
Thanks!

Reset/Change password from CLI

Now the CLI of this plugin let you create a new user with "bin/plugin login new-user". You can modify account by simply editing the user's files in user/accounts. But it's harder to quickly edit the password.

It would be nice to have a command to change the password something like:
$ bin/plugin login passwd username
$ new password :

Add CSS asset in template code instead

It's cool that there's a setting to control whether login.css is included, but I'm wondering if it'd be possible to include the CSS file through the Twig templates instead. Maybe the setting could still be kept around, but that would automatically exclude the CSS unless the template that it concerns is deliberately included in the theme.

Reset Password Page Issue: Validation message is not displayed if the new password fails validation.

Steps To Reproduce:

  1. Generate a reset password email using the "Forgot Password" page for a user account where you have access to the email.
  2. Click the reset link in the email.
  3. Enter a blank password or one that does not meet the complexity requirements, e.g. "123".
  4. A 404 message is displayed instead of the validation message.

Solution:
The redirect link is not set before the validation is checked, the reset password page needs user and token params in the url to be displayed.
Add the following lines to the taskReset method before $user->validate(); is called
in LoginController.php:

                $param_sep = $this->grav['config']->get('system.param_sep', ':');
                $resetLink = $this->grav['base_url_absolute'] . $this->grav['config']->get('plugins.login.route_reset') . '/task:login.reset/token' . $param_sep . $token . '/user' . $param_sep . $username . '/nonce' . $param_sep . Utils::getNonce('reset-form');
                $this->setRedirect($resetLink);
                $user->validate();

Login Failed on Content Pages Only

I'm attempting to restrict access to some content pages. The login screen is displayed, but attempting to login causes "Login failed..." to display and the login page continues to display.

The same login is able to access the admin dashboard.

My frontmatter:

access:
    site.login: true
    admin.login: true

redirect_after_login does not work?

I have a new installation of grav and added a redirect to the login.yaml like this:

redirect_after_login: '/profile'

But it does not work. Is this a known issue or did I oversee anything?

Thank you & cheers

Call to a member function header() on a non-object

Hi,

After update last update of grav, my website on server throws 500 error.
Inspecting error_log file give notice that there is something wrong with login plugin:

[22-Nov-2015 15:12:11 UTC] PHP Fatal error:  Call to a member function header() on a non-object in ***/public_html/solofront.com/user/plugins/login/login.php on line 206

Login error

Hi everybody,

I had a little problem on login, it happens sometimes only:

I type my username and password, and I get the error "Invalid security token" (or something like that). It happens 2-3 times after submit and then logs in normally.

I checked php logs and nothing, tried to empty cache and delete cookies, no success.
Obviously I have all necessary rights, login is true and admin super also.

This is definitely not a big deal but for some users could be difficult.

Bug input and label Username and Password

Hi,

Two bugs for Username and Password fields

  • translation does not work
  • attributs "for" and "id" are missing respectively for label and input

Those example are from the plugin maintenance...

bug_accessibility
bug_fr

Thanks ^^

Class 'Grav\Plugin\Login\Utils' not found

Hi all,

i get the following error while register :

Class 'Grav\Plugin\Login\Utils' not found

I think its because in /plugins/login/classes/Login.php there is

use Grav\Plugin\Login\Utils as LoginUtils;

but there is no file "Utils.php" ... maybe it should be:

use Grav\Plugin\Email\Utils as LoginUtils;

Greetings,

Chris

Bye the way: Installed everything yesterday. Current Grav and Login Plugin.
Edit: Changed

use Grav\Plugin\Login\Utils as LoginUtils;
to
use Grav\Plugin\Email\Utils as LoginUtils;

and everything seems to work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.