Skip to content

Commit

Permalink
Base registration two-step workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
wlorenzetti committed Sep 14, 2023
1 parent 13d1ae4 commit 6c6a02f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
5 changes: 5 additions & 0 deletions g3w-admin/usersmanage/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def GiveBaseGrant(sender, **kwargs):
"""
Insert group base in to database, and give base permissions
"""

if isinstance(sender, UsersmanageConfig):
AuthGroup = apps.get_app_config('auth').get_model('Group')
Permission = apps.get_app_config('auth').get_model('Permission')
Expand Down Expand Up @@ -38,4 +39,8 @@ class UsersmanageConfig(AppConfig):
verbose_name = 'Users Manager'

def ready(self):

# Activate signals receivers
import usersmanage.receivers

post_migrate.connect(GiveBaseGrant, sender=self)
40 changes: 40 additions & 0 deletions g3w-admin/usersmanage/receivers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding=utf-8
"""" Usermanage receivers module
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the Mozilla Public License 2.0.
"""

__author__ = "[email protected]"
__date__ = "2023-09-14"
__copyright__ = "Copyright 2015 - 2023, Gis3w"
__license__ = "MPL 2.0"

from django.conf import settings
from django.dispatch import receiver
from django_registration.signals import user_registered
from usersmanage.models import Userbackend, USER_BACKEND_DEFAULT, Group as AuthGroup
from usersmanage.configs import G3W_VIEWER1
import logging

logger = logging.getLogger('django.request')

@receiver(user_registered)
def set_user_backend(sender, **kwargs):
"""
Set User-backend on registration
"""

# Set default g3w-suite backend
Userbackend(user=kwargs['user'], backend=USER_BACKEND_DEFAULT).save()
logger.info(f"Assigned backend {USER_BACKEND_DEFAULT} to registered user {kwargs['user']}")

# Set default registration role
if hasattr(settings, 'REGISTRATION_MAIN_ROLES'):
for role in settings.REGISTRATION_MAIN_ROLES:
AuthGroup.objects.get(name=role).user_set.add(kwargs["user"])
else:

# By default, add user to Viewer Level 1 group
AuthGroup.objects.get(name=G3W_VIEWER1).user_set.add(kwargs['user'])

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

Dear {{user.username}},

please got to the following link or copy it an pate in you browser to activate your account and validate your email.
please got to the following link or copy it and paste in you browser to activate your account and validate your email.

<a href="{% url 'django_registration_activate' activation_key %}">{% url 'django_registration_activate' activation_key %}</a>
{% url 'django_registration_activate' activation_key %}

0 comments on commit 6c6a02f

Please sign in to comment.