Search - User list
Full Version: Default group for new users
Root » Feature requests » Default group for new users
1
tzot
Hello. I have set up a djangobb project on a site, and through the admin interface I have setup three Groups, and some Categories where the appropriate Groups have permissions.

However, when a new user is registered, they haven't any default group, so they have no permissions at all.
How can I setup a new User to belong to a specific Group by default? Note that I might have missed some step of the forum setup, all the documentation I found was scattered and mostly incomplete.

Thanks in advance.
slav0nic
More correct question: “as do this in django?”

Check django-registration (or what you uses?) registration.signals.user_registered signal and group in handler
tzot
I'm sorry, I'm very new with django. I assumed I could do that from the web administration interface.
I'm using a basic_project forum and the registration module, with so far untouched code. Where would I add code so that upon user registration, the user becomes automatically a member of the “Users” group?
Searching the web, I found that I got to do something along the lines:
from registration.signals import user_registered
user_registered.connect(new_user_created)
Where can I add this?
Obviously the new_user_created function is where I add the logic for making the User object a member of the Users group, but I still don't know how to make what I want.
This StackOverflow answer seems related to my issue.
tzot
Since the documentation says “connect the signal anywhere in an imported module”, I added the code in local_settings.py (I imagine it's a gross misuse of the file but it works; I will try to make it more “clean” somehow). The function “new_user_created” works now.
So I have to do something like
user.groups.add(users_group)
and the only thing I need to find out is, well, how to set “users_group” to be the group “Users”. Like I said, I'm very new to Django.
hevin
put this code in models.py of your custom app:
from registration.signals import *
from django.contrib.auth.models import Group
from django.dispatch import receiver

# Create your models here.

@receiver(user_registered)
def add_group_to_user(sender, user, request, **kwargs):
defaultgroup = Group.objects.get(name = ‘normaluser’)
if defaultgroup:
user.groups.add(defaultgroup)

'normaluser' is the name of your default group
willholt627
had thought about it, but did not grow together, in principle, it is easier than the current version, can be in the distant future, and implements
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB