views:

36

answers:

3

I am using a hook form alter to override the registration process. I want to assign a custom role that i have defined to the new user. How do i get about doing that?

I see that there is a users_roles table. Would simply making an entry in it with the user id and role id do the trick?

Thanks

+2  A: 

If every new user is going to get the role of authenticated user by default, why not just set the permissions the way you want them for that role? That way you don't need to mess with the database tables at all.

Dylan West
I understand that however this is going to be a custom role (that is user registrations that happen within this week as part of a marketing promotion so we can show them different access)
jini
Hmm. Understood. Then maybe you should try out the autoassignrole module that slavelle mentioned below. Or, if you don't want any new plugins, you can always change the perms for the authenticated users just for this week and then change them back after the promotion is over. That would only be practical if you didn't have to change too many perms, though. Whatever ends up being easiest.
Dylan West
+2  A: 

What Dylan says is an excellent point. There is also a contrib module that you can use that will make it easy to assign a specific role: http://drupal.org/project/autoassignrole

slavalle
A: 

Can you please tell, like do users can different roles based on something they choose during registration.

If thats not the case then solution by DYLAN WEST is the one you should go with.

Nikhil
From the autoassignrole project page:"The Auto Assign Role serves three primary purposes. The first is to provide an automatic assignment of roles when a new account is created. The second is to allow the end user the option of choosing their own role or roles when they create their account."I haven't messed with the choosing the roles at registration features, but do have a site that assigns a role at creation (there are other roles with different permissions that admins create, it works for that site).
slavalle