0Day Forums
Drupal Rules + one-time-login redirect issue - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: CMS (https://0day.red/Forum-CMS)
+---- Forum: Drupal (https://0day.red/Forum-Drupal)
+---- Thread: Drupal Rules + one-time-login redirect issue (/Thread-Drupal-Rules-one-time-login-redirect-issue)



Drupal Rules + one-time-login redirect issue - cathiecathleen966 - 07-26-2023

Problem is as follows:

I have a rule which redirects users to a landing page after login. It works fine.

However, if a user forgets their password, they are sent a link to the one-time-login page. They click the button and (because of my rule) are sent to their landing page.

The problem of course is that they cannot then change their password because the normal password change (in the user profile) requires you know your password to change it.

So how would I modify my redirect rule to say:

"Redirect to landing page, unless the logging-in user is coming from the one-time-login screen" or "Redirect to the landing page, unless the target URL starts with /user/reset/* (can you wildcard??)"

Thanks in advance for any tips


RE: Drupal Rules + one-time-login redirect issue - salamander809 - 07-26-2023

There is a Path Rules module and Rules Bonus Pack module that could do this nicely in Drupal 6. But unfortunately it looks like this feature/module is not coming for Drupal 7. See

[To see links please register here]

and

[To see links please register here]


However, you still can use PHP condition to check the path.
Try this (add a new condition and use php to add this. You will need php module enabled).
In the Rules that redirects users after logging in,

<?php
if (arg(0) == 'user' && arg(1) == 'reset'){
return FALSE;
}
else{
return TRUE;
}
?>

This will prevent the Rule from continuing if the path us user/reset/*.
Also, probably you will need the same condition with TRUE False exchanged in another Rule that redirects password-change users.


RE: Drupal Rules + one-time-login redirect issue - tonyaniby - 07-26-2023

You can do that with a rule like that:

{ "rules_after_login_redirect_to_news" : {
"LABEL" : "After login redirect to news.",
"PLUGIN" : "reaction rule",
"WEIGHT" : "0",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_login" ],
"IF" : [
{ "NOT text_matches" : {
"text" : [ "site:current-page:path" ],
"match" : "^user\/reset\/",
"operation" : "regex"
}
}
],
"DO" : [ { "redirect" : { "url" : "news" } } ]
}
}


RE: Drupal Rules + one-time-login redirect issue - Sirjyotizr - 07-27-2023

In the project I'm currently working on I encountered the same problem.
We solved it by using the Context module (

[To see links please register here]

).

Install and enable the Context module.
Create a context with the condition :
path = ~user/reset/*
(Leave reactions empty)

Use this context as an condition in the login redirect rule
(Context rules / is a context set)



RE: Drupal Rules + one-time-login redirect issue - Mrtanglement743 - 07-27-2023

You can also fix this problem just using the module rules, no coding.

In my case I wanted to redirect people to their workbench after they login.
But people that forgot their password would also get redirected to their workbench and wouldn't be able to change their password. They had to navigate to their own profile page but they had to reenter their password again: the onetime logging didn't work anymore.

So this is the rule I added:

**Events**
Event: User logged in.

**Conditions**
Elements: Text comparison.
Parameter: Tekst: [site:current-page:path], Matching text: user, Comparison operation: ends with

**Actions**
Elements: Page redirect
Parameter: URL: admin/workbench, Force redirect: false


RE: Drupal Rules + one-time-login redirect issue - logbook447 - 07-27-2023

I fixed this problem just using rules, as outlined in another answer here but i had to modify it to work, i had to set the Text comparison condition to negative, and the page redirect to Force redirect, and the page i wanted was called 'getting-started'. Works Perfect

So the rule i added:
**EVENTS**
User has logged in

**CONDITIONS**
NOT Text comparison
Parameter: Text: [site:current-page:path], Matching text: user, Comparison operation: starts with

**ACTIONS**
Page redirect
Parameter: URL: getting-started