Exemple #1
0
 def save(self, *args, **kwargs):
     create = True
     user = User()
     password = self.cleaned_data['new_password']
     user.name = self.cleaned_data['name']
     user.email = self.cleaned_data['email']
     user.username = self.cleaned_data['email']
     user.active = True
     user.is_superuser = False
     user.last_login = None
     user.date_joined = datetime.datetime.now()
     user.username = user.email
     user.set_password(password)
     if create:
         user.save()
         return user
     else:
         token = signing.dumps('{};{};{}'.format(user.name, user.email,
                                                 password))
         url = '{}/admin/create_user/{}/'.format(settings.SERVER_ADDRESS,
                                                 token)
         msg = '{}: {}'.format(
             _('Click on the link to activate your account'),
             url), settings.SYSTEM_EMAIL_ADDRESS
         user.email_user(_('Account Activation'), msg)
         return None
Exemple #2
0
def create_user(request, token):
    user = User()
    user.first_name, user.last_name, user.email, password = decrypt(token).split(';')
    user.is_active = True
    user.is_superuser = False
    user.last_login = datetime.datetime.now()
    user.date_joined = datetime.datetime.now()
    user.username = user.email
    user.set_password(password)
    user.save()
    return httprr(request, '/admin/login/', u'Conta confirmada com sucesso.')
Exemple #3
0
def check_role(self, saving=True):
    role_name = get_metadata(self.__class__, 'role_name')
    role_username = get_metadata(self.__class__, 'role_username')
    verbose_name = get_metadata(self.__class__, 'verbose_name')
    role_email = get_metadata(self.__class__, 'role_email', '')
    role_scope = get_metadata(self.__class__, 'role_scope', False)

    if role_username:
        from django.conf import settings
        from django.contrib.auth.models import Group
        from djangoplus.admin.models import User, Role, Organization, Unit

        group_name = verbose_name
        username = getattr2(self, role_username)
        name = role_name and getattr2(self, role_name) or None
        email = role_email and getattr2(self, role_email) or ''

        scopes = []

        if username:
            if role_scope:
                value = getattr2(self, role_scope)
                if hasattr(value, 'all'):
                    for scope in value.all():
                        scopes.append(scope)
                elif value:
                    scopes.append(value)

            group = Group.objects.get_or_create(name=group_name)[0]

            if saving:
                qs = User.objects.filter(username=username)
                if qs.exists():
                    user = qs[0]
                    user.email = email
                    user.name = name or str(self)
                    user.save()
                else:
                    user = User()
                    user.username = username
                    user.name = name or str(self)
                    user.email = email
                    user.save()
                    if user.email and not (settings.DEBUG
                                           or 'test' in sys.argv):
                        user.send_access_invitation()

                user.groups.add(group)
                if scopes:
                    for scope in scopes:
                        Role.objects.get_or_create(user=user,
                                                   group=group,
                                                   scope=scope)
                else:
                    Role.objects.get_or_create(user=user, group=group)
            else:
                user = User.objects.filter(username=username).first()
                if user:
                    if scopes:
                        for scope in scopes:
                            Role.objects.filter(user=user,
                                                group=group,
                                                scope=scope).delete()
                    else:
                        Role.objects.filter(user=user, group=group).delete()
                    user.check_role_groups()
Exemple #4
0
 def _mocked_request(self):
     if not self._request:
         self._request = HttpRequest()
         self._request.user = User(pk=0)
     return self._request
Exemple #5
0
 def save(self, *args, **kwargs):
     user = User()
     password = self.cleaned_data['new_password']
     user.name = self.cleaned_data['name']
     user.email = self.cleaned_data['email']
     user.username = self.cleaned_data['email']
     user.active = True
     user.is_superuser = False
     user.last_login = datetime.datetime.now()
     user.date_joined = datetime.datetime.now()
     user.username = user.email
     user.set_password(password)
     if True:
         user.save()
         return user
     else:
         token = encrypt('%s;%s;%s;%s' % (user.first_name, user.last_name, user.email, password))
         url = u'%s/admin/create_user/%s/' % (settings.SERVER_ADDRESS, token)
         user.email_user(u'Criação de Conta', u'Clique para confirmar a criação de sua conta: %s' % url,
                         settings.SYSTEM_EMAIL_ADDRESS)
         return None