Exemplo n.º 1
0
def invite_user_to_reactivate_account(user, request):
    """
    Send an email to a user asking them if they'd like to reactivate
    their account.
    """
    # Build and send a reactivation link for closed account
    user.auth_token = generate_unique_id()  # Reset token
    user.auth_token_is_used = False
    user.save()

    site = get_current_site(request)
    url = request.build_absolute_uri(
        reverse('accounts:activate-account', args=[user.auth_token]))

    # Send email
    subject = _('Reactivate your {} account'.format(site.name))
    template = 'accounts/emails/reactivate_account.html'

    send_connect_email(subject=subject,
                       template=template,
                       recipient=user,
                       site=site,
                       url=url)

    return user
Exemplo n.º 2
0
def invite_user_to_reactivate_account(user, request):
    """
    Send an email to a user asking them if they'd like to reactivate
    their account.
    """
    # Build and send a reactivation link for closed account
    user.auth_token = generate_unique_id()  # Reset token
    user.auth_token_is_used = False
    user.save()

    site = get_current_site(request)
    url = request.build_absolute_uri(
        reverse('accounts:activate-account',
                args=[user.auth_token]))

    # Send email
    subject = _('Reactivate your {} account'.format(site.name))
    template = 'accounts/emails/reactivate_account.html'

    send_connect_email(subject=subject,
                       template=template,
                       recipient=user,
                       site=site,
                       url=url)

    return user
Exemplo n.º 3
0
    def reinvite_user(self, user, email):
        """
        Reinvite an already invited user.
        """
        if self.is_moderator and self.has_perm('accounts.invite_user'):
            # Reset email, set a new token and update decision datetime
            user.email = email
            user.auth_token = generate_unique_id()
            user.decision_datetime = timezone.now()
            user.save()

            return user

        else:
            raise PermissionDenied
Exemplo n.º 4
0
    def reinvite_user(self, user, email):
        """
        Reinvite an already invited user.
        """
        if self.is_moderator and self.has_perm('accounts.invite_user'):
            # Reset email, set a new token and update decision datetime
            user.email = email
            user.auth_token = generate_unique_id()
            user.decision_datetime = timezone.now()
            user.save()

            return user

        else:
            raise PermissionDenied
Exemplo n.º 5
0
    def approve_user_application(self, user):
        """
        Approve a user's application
        """
        if self.is_moderator and \
           self.has_perm('accounts.approve_user_application'):
            user.moderator = self
            user.moderator_decision = user.APPROVED
            user.decision_datetime = timezone.now()
            user.auth_token = generate_unique_id()
            user.save()

            return user

        else:
            raise PermissionDenied
Exemplo n.º 6
0
    def approve_user_application(self, user):
        """
        Approve a user's application
        """
        if self.is_moderator and \
           self.has_perm('accounts.approve_user_application'):
            user.moderator = self
            user.moderator_decision = user.APPROVED
            user.decision_datetime = timezone.now()
            user.auth_token = generate_unique_id()
            user.save()

            return user

        else:
            raise PermissionDenied
Exemplo n.º 7
0
    def invite_new_user(self, email, full_name):
        """
        Invite an inactive user (who needs to activate their account).
        Returns none if user already exists.
        """
        User = get_user_model()

        if self.is_moderator and self.has_perm('accounts.invite_user'):
            try:
                User.objects.get(email=email)
            except User.DoesNotExist:
                new_user = create_inactive_user(email, full_name)
                new_user.registration_method = new_user.INVITED
                new_user.moderator = self
                new_user.moderator_decision = new_user.PRE_APPROVED
                new_user.decision_datetime = timezone.now()
                new_user.auth_token = generate_unique_id()
                new_user.save()
                return new_user
            else:
                return None
        else:
            raise PermissionDenied
Exemplo n.º 8
0
    def invite_new_user(self, email, full_name):
        """
        Invite an inactive user (who needs to activate their account).
        Returns none if user already exists.
        """
        User = get_user_model()

        if self.is_moderator and self.has_perm('accounts.invite_user'):
            try:
                User.objects.get(email=email)
            except User.DoesNotExist:
                new_user = create_inactive_user(email, full_name)
                new_user.registration_method = new_user.INVITED
                new_user.moderator = self
                new_user.moderator_decision = new_user.PRE_APPROVED
                new_user.decision_datetime = timezone.now()
                new_user.auth_token = generate_unique_id()
                new_user.save()
                return new_user
            else:
                return None
        else:
            raise PermissionDenied
Exemplo n.º 9
0
 def test_generate_unique_id(self):
     uid = generate_unique_id()
     self.assertEqual(len(uid), 30)
     self.assertRegexpMatches(uid, '^\w+$')