-
Notifications
You must be signed in to change notification settings - Fork 0
/
exclude_cwl_users_from_redirect.patch
28 lines (28 loc) · 1.48 KB
/
exclude_cwl_users_from_redirect.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
diff --git a/redirect_after_login.module b/redirect_after_login.module
index 5949b65..77f815a 100644
--- a/redirect_after_login.module
+++ b/redirect_after_login.module
@@ -93,6 +93,23 @@ function redirect_after_login_user_login($account) {
// We want to redirect user on login.
$current_user = Drupal::currentUser();
$username = $current_user->getRoles();
+
+ $roles = $username;
+ // if there are only two roles 'CWL' (and 'authenticated') roles then exclude from redirection
+ // as we want user to be returned to requested URL as per ReturnTo param
+ \Drupal::logger('redirect_on_login')->notice("roles: " . print_r($roles, TRUE));
+ if(2 == count($roles)
+ && in_array('cwl', $roles)
+ && in_array('authenticated', $roles)) {
+ \drupal::logger('redirect_on_login')->notice("Don't redirect - CWL and authenticated role only");
+ \drupal::logger('redirect_on_login')->notice("ReturnTo param: " . \Drupal::request()->query->get('ReturnTo'));
+ \drupal::logger('redirect_on_login')->notice("URI: " . \Drupal::request()->getRequestUri());
+ \drupal::logger('redirect_on_login')->notice("referer: " . $request->headers->get('referer'));
+ return;
+ } else {
+ \Drupal::logger('redirect_on_login')->notice("Redirect - not CWL user and/or has multiple roles");
+ }
+
$login_redirection = Drupal::config('redirect_after_login.settings')
->get('login_redirection');
if (isset($login_redirection[array_reverse($username)[0]])) {