0

I have created user through admin. Admin Assign specific role to user. But On first time login we want user to complete user profile and then only it will able to access anything else on site. So I want to remove role from user profile if any of field in user profile is empty. And add Pre-assign role again to user after completion of user profile.

Please help. Thanks in advance

0

I never did something similar before, but I guess, rules module suits you like nothing else.

First of all you need 2 roles: users who just created and users who filled some profile fields. When admin creates a new user he set first (just created) role.

Then you create a new page view event (in rules core):

  1. Create action load entity by id using site:current-user token (so you can access user profile fields in condition section);
  2. In condition section, Check user role (only for just created);
  3. In condition section, create condition for each profile field you wanna check (not empty or something similar);
  4. Create action to redirect user to edit profile page.

So, each time when new user will load any site page, he will be redirected to edit profile page until he doesn't fill profile fields.

The second event is after profile save, assign new role "Fills some profile fields". There is no difficult conditions, so I'm sure you can handle this event yourself.

If you need more complex solution, redirect on profile if only user load specific page you can try rules page. If you would like to redirect only once per session, you have to write your own rules condition through rules API or try out this one (never use this before).

I hope this could be helpfull for you, anyway wish you luck to find what you are really looking for.

| improve this answer | |
  • Hi @Oleg Sherbakov..Thanks for replay.. I am redirecting user on every login to edit profile page until he finishes his profile. But my concern is if he tries to access some other links on site without completing his profile. That should not happen. I am doing it on Hook_user_login. But for assigning and removing roles, I don't understand which function to user. As it gives error when I use it in Hook_form_alter. Is something else wwe can do? – sneha.kamble Jul 15 '13 at 4:58
  • You can trigger user login event, instead of page view. Anyway can you give us your code to be more precise. – Oleg Sherbakov Jul 15 '13 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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