Community

Rule to redirect new users to Organic Groups page?

I'm trying to avoid any custom coding to accomplish this. Here's what I need it to do:

1. New user registers for site.
2. Upon registration (i.e., after they fill out the profile fields and hit submit), I need them to be sent directly to a page that will list all of the Organic Groups that I have setup. This page already exists as a view page showing icons/labels of all of the groups.

This site is a group-based social network so it's important that new users join one or more groups.

To accomplish this, I setup a Rule:

Event: User has logged in.
Conditions:

  • USer has roles (set so that their role must be as an Authenticated User)
  • Data Value is Empty (data selector = site:current-user:og-membership--1)

Action: Page redirect

The event and action are working. Whenever a user with the role of Authenticated User logs in, they are redirected to the Groups page. Problem is, ALL authenticated users are being redirected to that page. I only want those who currently are not members of a Group to be redirected to that page.

So I'm pretty sure I've selected the wrong OG Data Selector, but I'm not sure which one works or if I'm just approaching this wrong?

Help! : )

Comments

hook_user_login

You should consider writing some code to a hook_user_login. You'll be able to provide your own logic that would eventually execute a drupal_goto.

Do you have any complex logic to help decide which group to direct the user to?

http://api.drupal.org/api/drupal/modules%21user%21user.api.php/function/...

Solved I think!

I think I got it. I changed the Data Selector to:

site:current-user:og-membership

And that did it. So basically, upon login, the logic is this:

If user = authenticated user then check to see if (site:current-user:og-membership == false) (i.e., they are not members of any group), then redirect them to a specific page

It seems to be working with the two accounts I tested it on.

I'm new to Drupal and have no idea how to write a module or apply custom code. I'm not a PHP programmer (I have experience in Python, Java, Actionscript). I'm sure I could learn it pretty quickly but at this point I'm still struggling with basic site building in Drupal so I'm trying to do everything through the UI.

That said - there is a good chance that my client (who I'm working for free at this point as I wanted to take on this project to learn Drupal) may insist that group membership be selected within the registration form versus as a redirect after they register and subsequently login. If that's the case, I'll be back to ask about how to do the code thing : )

You should add the condition

You should add the condition "User is a group member" of rules and negate it, so the users who are not the group members will get redirected when the login.

Hth,
Sadashiv.

Hi Sadashiv, I think that's

Hi Sadashiv,

I think that's what I finally did to get it working. Where I was confused was which "Data Selector" actually equals group membership. It turns out that this one does:

site:current-user:og-membership

nobody click here