Skip to content

Commit

Permalink
Merge branch 'release/3.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Apr 27, 2020
2 parents 407bb3f + 73da6f2 commit cd7820e
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 125 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 3.2.0
## 04/27/2020

1. [](#new)
* CHANGE: `redirect_to_login` and `redirect_after_logout` are now boolean, with accompanying `route_after_login` and `route_after_logout` options. NOTE: Compatibility is maintained with existing config.
* [](#improved)
* Improved configuration layout
* Better handling of login route when that page doesn't exist
1. [](#bugfix)
* Fixed guest only pages requiring login
* Fixed issue when logging out, not redirecting, and attempting to log right back in

# 3.1.0
## 03/05/2020

Expand Down
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,21 @@ access:
```yaml
enabled: true # Enable the plugin
built_in_css: true # Use built-in CSS
route: # Specific route for Login page (default is '/login')
redirect_to_login: true # If you try to access a page you don't have access to, should you redirect to login route
redirect_after_login: # Path to redirect to after a successful login (eg '/user_profile')
redirect_after_logout: '/' # Path to redirect to after a successful logout (eg '/')
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
Expand All @@ -169,6 +173,7 @@ max_pw_resets_count: 2 # Number of password resets in a spe
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
Expand All @@ -180,6 +185,7 @@ user_registration:
- '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
Expand All @@ -189,6 +195,7 @@ user_registration:
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)
Expand Down Expand Up @@ -225,7 +232,7 @@ Enabling the setting "Use parent access rules" (`parent_acl` in login.yaml) allo

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 setttings in the admin plugin).
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
Expand Down
203 changes: 123 additions & 80 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Login
version: 3.1.0
version: 3.2.0
testing: false
description: Enables user authentication and login screen.
icon: sign-in
Expand Down Expand Up @@ -27,9 +27,9 @@ form:
class: subtle

fields:
login:
options:
type: tab
title: PLUGIN_LOGIN.BTN_LOGIN
title: PLUGIN_LOGIN.OPTIONS

fields:

Expand All @@ -56,42 +56,40 @@ form:
validate:
type: bool

route:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE
help: PLUGIN_LOGIN.ROUTE_HELP
placeholder: "/my-custom-login"
redirect_to_login:
type: toggle
label: PLUGIN_LOGIN.REDIRECT_TO_LOGIN
help: PLUGIN_LOGIN.REDIRECT_TO_LOGIN_HELP
default: 1
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

redirect_after_login:
type: text
type: toggle
label: PLUGIN_LOGIN.REDIRECT_AFTER_LOGIN
help: PLUGIN_LOGIN.REDIRECT_AFTER_LOGIN_HELP
placeholder: "/my-page"
force_bool: true
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

redirect_after_logout:
type: text
type: toggle
label: PLUGIN_LOGIN.REDIRECT_AFTER_LOGOUT
help: PLUGIN_LOGIN.REDIRECT_AFTER_LOGOUT_HELP
placeholder: "/"

route_forgot:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_FORGOT
placeholder: "/forgot_password"

route_reset:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_RESET
placeholder: "/reset_password"

route_profile:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_PROFILE
placeholder: "/user_profile"
force_bool: true
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

parent_acl:
type: toggle
Expand Down Expand Up @@ -141,55 +139,6 @@ form:
validate:
type: bool

routes:
type: section
title: PLUGIN_LOGIN.ROUTES

fields:

route_activate:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_ACTIVATE
placeholder: '/activate_user'

route_forgot:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_FORGOT
placeholder: '/forgot_password'

route_reset:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_RESET
placeholder: '/reset_password'

route_profile:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_PROFILE
placeholder: '/user_profile'

route_register:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_REGISTER
help: PLUGIN_LOGIN.ROUTE_REGISTER_HELP
placeholder: "/register"

user_registration.redirect_after_registration:
type: text
label: PLUGIN_LOGIN.REDIRECT_AFTER_REGISTRATION
help: PLUGIN_LOGIN.REDIRECT_AFTER_REGISTRATION_HELP
placeholder: "/page-to-show-after-registration"

user_registration.redirect_after_activation:
type: text
label: PLUGIN_LOGIN.REDIRECT_AFTER_ACTIVATION
help: PLUGIN_LOGIN.REDIRECT_AFTER_ACTIVATION_HELP
placeholder: "/page-to-show-after-activation"

rememberme:
type: section
title: PLUGIN_LOGIN.REMEMBER_ME
Expand Down Expand Up @@ -222,6 +171,100 @@ form:
label: PLUGIN_ADMIN.NAME
help: PLUGIN_ADMIN.SESSION_NAME_HELP

routes:
type: tab
title: PLUGIN_LOGIN.ROUTES

fields:

route:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE
help: PLUGIN_LOGIN.ROUTE_HELP
placeholder: "/login"

route_after_login:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_AFTER_LOGIN
help: PLUGIN_LOGIN.ROUTE_AFTER_LOGIN_HELP
data-default@: '\Grav\Plugin\LoginPlugin::defaultRedirectAfterLogin'
placeholder: "/user_profile"

route_after_logout:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_AFTER_LOGOUT
help: PLUGIN_LOGIN.ROUTE_AFTER_LOGOUT_HELP
data-default@: '\Grav\Plugin\LoginPlugin::defaultRedirectAfterLogout'
placeholder: "/"

route_forgot:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_FORGOT
placeholder: "/forgot_password"

route_reset:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_RESET
placeholder: "/reset_password"

route_profile:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_PROFILE
placeholder: "/user_profile"

route_activate:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_ACTIVATE
placeholder: '/activate_user'

user_registration.redirect_after_activation:
type: text
size: medium
label: PLUGIN_LOGIN.REDIRECT_AFTER_ACTIVATION
help: PLUGIN_LOGIN.REDIRECT_AFTER_ACTIVATION_HELP
placeholder: "/page-to-show-after-activation"

route_forgot:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_FORGOT
placeholder: '/forgot_password'

route_reset:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_RESET
placeholder: '/reset_password'

route_profile:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_PROFILE
placeholder: '/user_profile'

route_register:
type: text
size: medium
label: PLUGIN_LOGIN.ROUTE_REGISTER
help: PLUGIN_LOGIN.ROUTE_REGISTER_HELP
placeholder: "/register"

user_registration.redirect_after_registration:
type: text
size: medium
label: PLUGIN_LOGIN.REDIRECT_AFTER_REGISTRATION
help: PLUGIN_LOGIN.REDIRECT_AFTER_REGISTRATION_HELP
placeholder: "/page-to-show-after-registration"



registration:
type: tab
title: PLUGIN_LOGIN.USER_REGISTRATION
Expand Down
33 changes: 26 additions & 7 deletions classes/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,19 +153,26 @@ public function taskLogin()
$event = $this->login->login($form, ['remember_me' => true, 'twofa' => $twofa], ['return_event' => true]);
$user = $event->getUser();

/* Support old string-based $redirect_after_login + new bool approach */
$redirect_after_login = $this->grav['config']->get('plugins.login.redirect_after_login');
$route_after_login = $this->grav['config']->get('plugins.login.route_after_login');
$login_redirect = is_bool($redirect_after_login) && $redirect_after_login == true ? $route_after_login : $redirect_after_login;


if ($user->authenticated) {
$rateLimiter->resetRateLimit($ipKey, 'ip')->resetRateLimit($userKey);
if ($user->authorized) {
$event->defMessage('PLUGIN_LOGIN.LOGIN_SUCCESSFUL', 'info');

$event->defRedirect(
$this->grav['session']->redirect_after_login ?:
$this->grav['config']->get('plugins.login.redirect_after_login') ?:
$this->grav['uri']->referrer('/')
$login_redirect ?: $this->grav['uri']->referrer('/')
);
} else {
$redirect_to_login = $this->grav['config']->get('plugins.login.redirect_to_login');
$login_route = $this->grav['config']->get('plugins.login.route');
$event->defRedirect($login_route ?: $this->grav['uri']->referrer('/'));
$redirect_route = $redirect_to_login && $login_route ? $login_route : false;
$event->defRedirect($redirect_route ?: $this->grav['uri']->referrer('/'));
}
} else {
if ($user->authorized) {
Expand Down Expand Up @@ -210,9 +217,11 @@ public function taskTwoFa()

$user->authenticated = false;

$redirect_to_login = $this->grav['config']->get('plugins.login.route_to_login');
$login_route = $this->grav['config']->get('plugins.login.route');
if ($login_route) {
$this->setRedirect($login_route, 303);
$redirect_route = $redirect_to_login && $login_route ? $login_route : false;
if ($redirect_route) {
$this->setRedirect($redirect_route, 303);
}

return true;
Expand All @@ -222,9 +231,14 @@ public function taskTwoFa()

$user->authorized = true;

/* Support old string-based $redirect_after_login + new bool approach */
$redirect_after_login = $this->grav['config']->get('plugins.login.redirect_after_login');
$route_after_login = $this->grav['config']->get('plugins.login.route_after_login');
$login_redirect = is_bool($redirect_after_login) && $redirect_after_login == true ? $route_after_login : $redirect_after_login;

$this->setRedirect(
$this->grav['session']->redirect_after_login
?: $this->grav['config']->get('plugins.login.redirect_after_login')
?: $login_redirect
?: $this->grav['uri']->referrer('/')
);

Expand All @@ -249,7 +263,12 @@ public function taskLogout()
$messages->add($t->translate($message), $event->getMessageType());
}

$redirect = $event->getRedirect() ?: $this->grav['config']->get('plugins.login.redirect_after_logout');
/* Support old string-based $redirect_after_logout + new bool approach */
$redirect_after_logout = $this->grav['config']->get('plugins.login.redirect_after_logout');
$route_after_logout = $this->grav['config']->get('plugins.login.route_after_logout');
$logout_redirect = is_bool($redirect_after_logout) && $redirect_after_logout == true ? $route_after_logout : $redirect_after_logout;

$redirect = $event->getRedirect() ?: $logout_redirect;
if ($redirect) {
$this->setRedirect($redirect, $event->getRedirectCode());
}
Expand Down
Loading

0 comments on commit cd7820e

Please sign in to comment.