1

I'd like users with certain roles to be redirected to the page /civicrm when they login, unless they've already been redirected elsewhere. For example, an email might have a link that directs them to the page /elsewhere.

When I tried the module 'login destination' I can only achieve one or the other, never both - either the redirect works but a regular login doesn't redirect to /civicrm or the other way round.

From browsing in Drupal Answers, I'm pretty sure that Rules could do this, but I've tried and failed so far. The rule needs 2 conditions to be satisfied - user is one of the roles, and they are not already being redirected - then they should be directed to /civicrm.

Can anyone please suggest how a rule might achieve this?

2 Answers 2

1

You should be able to get this to work, using the Rules module, using the "Drupal is initializing" event. That will ensure that the rule gets triggered BEFORE the actual content is shown. Using Rules event " Content is viewed " is typically 'too late'. Refer to 'How to specify a Rules event like "Content is 'going to be' viewed"?' for more details on that. Adapt your rule to use this event, combine that with the relevant Rules conditions (like roles, etc) and, just for temporary unit testing, add a Rules Action (as the very first Rules Action) to "Show a message on a site", e.g to say 'Bingo, let the Rules party begin (we did find a Rules Event to continue building on)'.

1
  • Thanks - your answer is appreciated and I have learnt a lot with this episode. I found that there was a module R4032login installed that I wasn't aware of which was obviously making things difficult. Embarrassing I guess but there you go!
    – Andy Clark
    Commented Dec 20, 2019 at 20:33
1

Make a flag on users: 'flag_user_has_logged_out', you will need more than one rule, first rule: react on: user has logged out, and flag the user with this new flag, on another rule: react on logged_in: first validate your roles, then validate if user is 'flagged' if so, redirect to /whatever, and unflag user has logged out. if not, the other redirect will take control. This kind of rules i use a lot, i make many calculations on user has logged-out and i do not need to recalculate things again when user loggs in, it work both ways, maybe user just clossed browser and did not made a logged-out, so a evalutate that when loggs in and i do not duplicate my calculations. i hope you understood me and help you. is just a pointing directions on what you can do. Examples how your rules will look like:

user has logged out

user has logged in

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.