themetman's picture

I am trying to redirect any user with a particular Role at login to a URL. I am using the latest Backdrop and Rules Module. I have looked at most of the posts relating to this problem, and tried many of the examples but the redirect fails. There are no messages in the Logs, I have debugging on in Rules. I have tried this which is from a post I found, and modified for my page redirection which works:

    { "rules_after_login_redirect_to_host_registration" : {
    "LABEL" : "After login redirect to Host Registration.",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_login" : [] },
    "IF" : [
      { "NOT text_matches" : {
          "text" : [ "site:current-page:path" ],
          "match" : "^user\/reset\/",
          "operation" : "regex"
        }
      }
    ],
    "DO" : [
      { "redirect" : { "url" : "webform\/host-registration" } },
      { "backdrop_message" : { "message" : "Redirecting to Host Registration" } }  ]
  }
}

However my Rule to Redirect a user at login with a Role of Host does not work:

{ "rules_redirect_role_host_to_selected_page" : {
    "LABEL" : "Redirect role Host to selected page",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "user_login" : [] },
    "IF" : [
      { "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "host" : "host" } } } }
    ],
    "DO" : [ { "redirect" : { "url" : "webform\/host-registration" } } ]
  }
}

I have asked this on Stackexchange  where it was suggested using the ID of the Role rather than the name as per above. I have tried this by changing "host" to the ID of the Role, but still not working.

I am wondering if there is some peculiarity of Backdrop with Rules I am missing, hence my posting here.

I am baffled. Why is the Role Condition not picked up?

Comments

I don't have an answer to your specific question, but wanted to note an alternate suggestion: have you looked into Login Destination?

The way roles are referenced in code changed with Backdrop and it's possible there is a bug in Rules that needs to be ironed out. (Actually, I just checked and it looks like this issue might be related. If you are able to test this fix I'm sure it would be appreciated!)

themetman's picture

Thanks, @laryn I wil have a look at that fix tomorrow.

I have solved the problem for now by using the Login Destination Module, but have some other Rules I would like to apply using Role as the condition, so would like to try and get it working.

Regards

themetman's picture

I have tried the fix #49 and it works for me. I have left a message there.