예제 #1
0
def complete_signup(request, user, signal_kwargs={}):
    signals.user_signed_up.send(sender=user.__class__,
                                request=request,
                                user=user,
                                **signal_kwargs)

    return get_adapter().new_user_response(user, request=request)
예제 #2
0
def perform_login(request, user, email_verification, return_data={}, signal_kwargs={},
                  signup=False):
    """
    Keyword arguments:

    signup -- Indicates whether or not sending the
    email is essential (during signup), or if it can be skipped (e.g. in
    case email verification is optional and we are only logging in).
    """
    from allauth.account.models import EmailAddress
    has_verified_email = EmailAddress.objects.filter(user=user,
                                                     verified=True).exists()
    if email_verification == EmailVerificationMethod.NONE:
        pass
    elif email_verification == EmailVerificationMethod.OPTIONAL:
        # In case of OPTIONAL verification: send on signup.
        if not has_verified_email and signup:
            send_email_confirmation(request, user, signup=signup)
    elif email_verification == EmailVerificationMethod.MANDATORY:
        if not has_verified_email:
            send_email_confirmation(request, user, signup=signup)
            return Response({'message': 'Account email verification sent'}, HTTP_401_UNAUTHORIZED)
    # Local users are stopped due to form validation checking
    # is_active, yet, adapter methods could toy with is_active in a
    # `user_signed_up` signal. Furthermore, social users should be
    # stopped anyway.
    if not user.is_active:
        return Response({'message': 'User account is inactive'}, HTTP_403_FORBIDDEN)

    get_adapter().login(request, user)
    signals.user_logged_in.send(sender=user.__class__,
                                request=request,
                                user=user,
                                **signal_kwargs)
    get_adapter().add_message(request,
                              messages.SUCCESS,
                              'account/messages/logged_in.txt',
                              {'user': user})

    return_data.update({'message': 'User logged in.'})
    return Response(return_data, HTTP_200_OK)
예제 #3
0
    def clean_email(self):
        """Check that email address is unique.

        Returns:
            str: cleaned email
        Raises:
            Validation error if email is nit unique
        """
        value = self.cleaned_data["email"]
        value = get_adapter().clean_email(value)
        if value and email_address_exists(value):
            raise forms.ValidationError("A user is already registered"
                                        " with this e-mail address.")
        return value
예제 #4
0
    def save(self, request):
        """Save new user with data from form. Used functions from allauth
        adapter and custom actions, like setting up user role and avatar.

        Returns:
            new user
        """
        adapter = get_adapter()
        user = AppUser()
        user = adapter.save_user(request, user, self, commit=False)
        avatar = request.FILES.get('avatar')
        if avatar:
            user.avatar.save(avatar.name, avatar)
        user.role = AppUser.USER_ROLE

        # set account for new user
        # users can be added just to merchant's account
        merchant = self.cleaned_data['merchant']
        account, _ = merchant.account_set.get_or_create(type=Account.MERCHANT)
        user.account = account
        user.save()
        setup_user_email(request, user, [])
        return user
예제 #5
0
 def is_open(self):
     return get_adapter(self.request).is_matriculant_open_for_signup(
         self.request)