示例#1
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise ValidationError(
                 ("Un usuario ya ha sido registrado con este correo electrónico."))
     return email
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise serializers.ValidationError(
                 _("A user is already registered with this e-mail address."))
     return email
示例#3
0
 def clean_email(self):
     value = self.cleaned_data["email"]
     if app_settings.UNIQUE_EMAIL:
         if value and email_address_exists(value):
             raise forms.ValidationError \
                 (_("Unavailable Email Address"))
     return value
示例#4
0
 def clean_email(self):
     value = self.cleaned_data["email"]
     value = get_adapter().clean_email(value)
     if app_settings.UNIQUE_EMAIL:
         if value and email_address_exists(value):
             self.raise_duplicate_email_error()
     return value
示例#5
0
 def clean_email(self):
     value = self.cleaned_data["email"]
     if UNIQUE_EMAIL or EMAIL_AUTHENTICATION:
         if value and email_address_exists(value):
             raise forms.ValidationError \
                 (_("A user is registered with this e-mail address."))
     return value
示例#6
0
 def clean_email(self):
     value = self.cleaned_data["email"]
     if app_settings.UNIQUE_EMAIL:
         if value and email_address_exists(value):
             raise forms.ValidationError \
                 (_("A user is registered with this e-mail address."))
     return value
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise serializers.ValidationError((
                 "Un usuario ya está registrado con esta dirección de correo electrónico."
             ))
     return email
示例#8
0
	def _validate_email(self, email, password):
		user = None
		if not email_address_exists(email):
			msg = _('Account with this email address does not exists.')
			raise serializers.ValidationError(msg)

		user = authenticate(email=email, password=password)
		return user
示例#9
0
    def validate_email(self, email):
        email = get_adapter().clean_email(email)
        if allauth_settings.UNIQUE_EMAIL:
            if email and email_address_exists(email):
                raise serializers.ValidationError(
                    i18n.t('lang.errorMessages.auth.emailAlreadyExists'))

        return email
示例#10
0
    def validate_email(self, email):
        email = get_adapter().clean_email(email)

        # E-mail has to be unique by default
        if email and email_address_exists(email):
            raise serializers.ValidationError(_("A user is already registered with this e-mail address."))

        return email
示例#11
0
 def validate_email(self, email) -> str:
     status, msg = AuthAppService.validate_email(email)
     if not status:
         raise serializers.ValidationError(msg)
     if email and email_address_exists(email):
         raise serializers.ValidationError(
             _("User is already registered with this e-mail address."))
     return email
示例#12
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise serializers.ValidationError(
                 _('Email is already registered. Please use "Sign in" to connect with this email address'
                   ))
     return email
示例#13
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise serializers.ValidationError(
                 _("A user is already registered with this e-mail address.")
             )
     return email
示例#14
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = user_email(sociallogin.account.user)
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif app_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: This part contains a lot of duplication of logic
        # ("closed" rendering, create user, send email, in active
        # etc..)
        try:
            if not get_account_adapter().is_open_for_signup(request):
                return render(request,
                              "account/signup_closed.html")
        except ImmediateHttpResponse as e:
            return e.response
        u = sociallogin.account.user
        if account_settings.USER_MODEL_USERNAME_FIELD:
            user_username(u,
                          generate_unique_username(user_username(u)
                                                   or email
                                                   or 'user'))
        for field in ['last_name',
                      'first_name']:
            if hasattr(u, field):
                truncated_value = (user_field(u, field) or '') \
                    [0:User._meta.get_field(field).max_length]
                user_field(u, field, truncated_value)
        user_email(u, email or '')
        if u.password:
            pass
        else:
            u.set_unusable_password()
        sociallogin.save(request)
        ret = complete_social_signup(request, sociallogin)
    return ret
示例#15
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = sociallogin.account.user.email
    print 'AUTO SIGNUP - %s' % auto_signup
    print email
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    print 'AUTO SIGNUP 2 - %s' % auto_signup
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin
        url = reverse('socialaccount_signup')
        print url
        ret = HttpResponseRedirect(url)
    else:
        print '555555555'
        # FIXME: There is some duplication of logic inhere
        # (create user, send email, in active etc..)
        u = sociallogin.account.user
        print '66666666666'
        u.username = generate_unique_username(u.username
                                              or email 
                                              or 'user')
        u.last_name = (u.last_name or '') \
            [0:User._meta.get_field('last_name').max_length]
        u.first_name = (u.first_name or '') \
            [0:User._meta.get_field('first_name').max_length]
        u.email = email or ''
        print '777777777'
        u.set_unusable_password()
        print '888888888'
        sociallogin.save()
        print '99999999'
        print '--------'
        #send_email_confirmation(request, u)
        print '00000000'
        ret = complete_social_signup(request, sociallogin)
    print 'RET'
    print ret
    return ret
示例#16
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise CustomValidation(
                 "A user is already registered with this e-mail address.",
                 "error",
                 status_code=status.HTTP_200_OK)
     return email
示例#17
0
    def validate_email(self, email):
        email = get_adapter().clean_email(email)

        if app_settings.UNIQUE_EMAIL:
            if email and email_address_exists(email):
                msg = {"email_error": "This email address has been registered!"}
                raise serializers.ValidationError(msg)

        return email
示例#18
0
def _process_signup(request, sociallogin):
    log.debug('socialaccount.helpers._process_signup')
    # If email is specified, check for duplicate and if so, no auto signup.
    log.debug("_process_signup")
    auto_signup = app_settings.AUTO_SIGNUP
    email = sociallogin.account.user.email
    if auto_signup:
        # Let's check if auto_signup is really possible...
        log.debug("auto_signup")
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            log.debug("no email available")
            auto_signup = False
    if not auto_signup:
        log.debug("not auto signup")
        request.session['socialaccount_sociallogin'] = sociallogin
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: There is some duplication of logic inhere
        # (create user, send email, in active etc..)
        log.debug("Auto sign up again")
        u = sociallogin.account.user
        u.username = generate_unique_username(u.username
                                              or email 
                                              or 'user')
        u.last_name = (u.last_name or '') \
            [0:User._meta.get_field('last_name').max_length]
        u.first_name = (u.first_name or '') \
            [0:User._meta.get_field('first_name').max_length]
        u.email = email or ''
        u.set_unusable_password()
        log.debug(u)
        sociallogin.save()
        log.debug("Sending email to the following:")
        log.debug(email)
        send_email_confirmation(request, u)
        log.debug("Email confirmation sent")
        ret = complete_social_signup(request, sociallogin)
        log.debug(ret)
    return ret
示例#19
0
    def pre_social_login(self, request, sociallogin):
        email = user_email(sociallogin.user)
        UserModel = get_user_model()
        login_provider_id = sociallogin.account.provider

        if (not email or not email_address_exists(email)
                or sociallogin.state.get('process') != AuthProcess.LOGIN):
            # This is a new email address, or we're connecting social accounts
            # so we don't need to do anything
            return

        try:
            user = UserModel.objects.get(email=email)
        except UserModel.DoesNotExist:
            # This case shouldn't really happen, but even if it does, we
            # don't do anything and let the default behavior kick in.
            return

        social_accounts = list(
            SocialAccount.objects.filter(user=user).values_list('provider',
                                                                flat=True))

        if len(social_accounts) == 0:
            # This is a hack to associate existing accounts on pulse
            # that were added via Google Auth the old way to the new allauth
            # system. We only do this for new logins into this system.
            request.migrate_user = user
        elif login_provider_id in social_accounts:
            # In this case, the existing user already has a social account
            # and is logging into it using the same provider.
            return
        else:
            # Here the user already has a Pulse social account (e.g. Google)
            # but is logging in through a different social network
            # (e.g. Github) that uses the same email for the first time.
            # We redirect them to the login view where they have to login
            # through their existing social account on Pulse before going to
            # the Social Account Connections view to connect their secondary
            # social account.
            url = reverse('account_login')
            qs = QueryDict(mutable=True)
            next_url = sociallogin.get_redirect_url(request)
            if next_url:
                # We encode the final destination url in the connection
                # view url so that users are correctly rerouted after
                # connecting their accounts.
                qs['next'] = next_url
            next_url = '{url}?{qs}'.format(
                url=reverse('socialaccount_connections'), qs=qs.urlencode())
            qs = QueryDict(mutable=True)
            qs['next'] = next_url
            qs['promptconnection'] = True
            qs['provider'] = providers.registry.by_id(login_provider_id).name

            raise ImmediateHttpResponse(
                response=HttpResponseRedirect(f'{url}?{qs.urlencode()}'))
示例#20
0
    def clean_email(self, email):
        try:
            User.objects.get(email=email)
        except User.DoesNotExist:
            if email_address_exists(email):
                raise forms.ValidationError(self.error_messages['email_taken'])
        else:
            return email

        return super().clean_email(email)
示例#21
0
文件: helpers.py 项目: usbong/fitsenv
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = user_email(sociallogin.account.user)
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif app_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: This part contains a lot of duplication of logic
        # ("closed" rendering, create user, send email, in active
        # etc..)
        try:
            if not get_account_adapter().is_open_for_signup(request):
                return render(request,
                              "account/signup_closed.html")
        except ImmediateHttpResponse as e:
            return e.response
        u = sociallogin.account.user
        if account_settings.USER_MODEL_USERNAME_FIELD:
            user_username(u,
                          generate_unique_username(user_username(u)
                                                   or email
                                                   or 'user'))
        for field in ['last_name',
                      'first_name']:
            if hasattr(u, field):
                truncated_value = (user_field(u, field) or '') \
                    [0:User._meta.get_field(field).max_length]
                user_field(u, field, truncated_value)
        user_email(u, email or '')
        u.set_unusable_password()
        sociallogin.save(request)
        ret = complete_social_signup(request, sociallogin)
    return ret
示例#22
0
    def dispatch(self, request, *args, **kwargs):
        """
        Override allauth's dispatch method to transparently just login if
        the email already exists.  By doing this in dispatch, we can check for
        existing email, and if a match is found, associate the social account
        with that user and log them in.  Allauth does not provide a mechanism
        for doing precisely this.
        """
        ret = super().dispatch(request, *args, **kwargs)
        # By calling super().dispatch first, we set self.sociallogin
        try:
            # The email is contained in sociallogin.account.extra_data
            extra_data = self.sociallogin.account.extra_data
        except AttributeError:
            return ret
        # extract email
        email = extra_data["email"]
        if email_address_exists(email):
            # check that email exists.
            # If the email does exist, and there is a social account associated
            # with the user, then we don't have to do anything else
            if not self.sociallogin.is_existing:
                # However, if the email exists, and there isn't a social
                # account associated with that user, we need to associate the
                # social account
                # Allauth would perform this as part of the form.save step, but
                # we are entirely bypassing the form.
                account_emailaddress = EmailAddress.objects.get(email=email)
                self.sociallogin.user = account_emailaddress.user
                # allauth (and us) uses the sociallogin user as a temporary
                # holding space, and it already is largely filled out by
                # allauth; we just need to set the user.
                # This model does not get saved to the database.

                # We're trusting social provided emails already
                account_emailaddress.verified = True
                account_emailaddress.save()
                if not SocialAccount.objects.filter(
                        uid=self.sociallogin.account.uid,
                        provider=self.sociallogin.account.provider,
                ).exists():
                    # just to be on the safe side, double check that the account
                    # does not exist in the database and that the provider is
                    # valid.
                    socialaccount = SocialAccount()
                    socialaccount.uid = self.sociallogin.account.uid
                    socialaccount.provider = self.sociallogin.account.provider
                    socialaccount.extra_data = extra_data
                    socialaccount.user = self.sociallogin.user
                    socialaccount.save()
                return complete_social_login(request, self.sociallogin)

        return ret
示例#23
0
def validate_email_setting(request):
    value = request.POST['email']
    print value
    email = User.objects.get(pk=request.session[SESSION_KEY]).email
    print email
    if value != email:
        if value and email_address_exists(value):
            return -1
        else:
            return 1
    else:
        return 1
示例#24
0
def _process_signup(request, data, account):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = data.get('email')
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_signup'] = dict(data=data,
                                                       account=account)
        url = reverse('socialaccount_signup')
        next = request.REQUEST.get('next')
        if next:
            url = url + '?' + urlencode(dict(next=next))
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: There is some duplication of logic inhere
        # (create user, send email, in active etc..)
        username = generate_unique_username \
            (data.get('username', email or 'user'))
        u = User(username=username,
                 email=email or '',
                 last_name=data.get(
                     'last_name',
                     '')[0:User._meta.get_field('last_name').max_length],
                 first_name=data.get(
                     'first_name',
                     '')[0:User._meta.get_field('first_name').max_length])
        u.set_unusable_password()
        u.is_active = not account_settings.EMAIL_VERIFICATION
        u.save()
        account.user = u
        account.sync(data)
        send_email_confirmation(u, request=request)
        ret = complete_social_signup(request, u, account)
    return ret
示例#25
0
def validate_email_setting(request):
	value = request.POST['email']
	print value
	email = User.objects.get(pk=request.session[SESSION_KEY]).email
	print email
	if value != email:
		if value and email_address_exists(value):
			return -1
		else:
			return 1
	else:
		return 1
示例#26
0
 def _delete_user_account(self, user, error=None):
     user_email = user.email
     email_exists = email_address_exists(user_email)
     if email_exists:
         user = User.objects.get(email=user_email)
         social_account_exists = SocialAccount.objects.filter(
             user=user).exists()
         if not social_account_exists:
             deletion_info = user.delete()
             sentry.log_info(deletion_info, error=error)
             return True
     return False
示例#27
0
def validate_email_setting(request):
	value = request.POST['email']
	user_login = get_user_login_object(request)
	email = user_login.email
	print email
	if value != email:
		if value and email_address_exists(value):
			return -1
		else:
			return 1
	else:
		return 1
示例#28
0
 def create(self, validated_data):
     user = self._get_request().user
     email = validated_data.get('email')
     if user.email != email:
         if email_address_exists(email):
             raise serializers.ValidationError(
                 _("A user with that email address exists."))
     user.email = email
     user.username = validated_data.get('userName')
     user.set_password(validated_data.get('password'))
     user.save()
     return user
    def _check_email(self, email: str, check_exists: bool) -> str:
        adapter = get_adapter(self._request)
        email = adapter.clean_email(email)

        if not email:
            raise serializers.ValidationError(_("Invalid e-mail address."))

        if check_exists and email_address_exists(email):
            raise serializers.ValidationError(
                _("A user is already registered with this e-mail address."))

        return email
示例#30
0
def _process_signup(request, data, account):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = data.get('email')
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_signup'] = dict(data=data,
                                                       account=account)
        url = reverse('socialaccount_signup')
        next = request.REQUEST.get('next')
        if next:
            url = url + '?' + urlencode(dict(next=next))
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: There is some duplication of logic inhere 
        # (create user, send email, in active etc..)
        username = generate_unique_username \
            (data.get('username', email or 'user'))
        u = User(username=username,
                 email=email or '',
                 last_name = data.get('last_name', '')[0:User._meta.get_field('last_name').max_length],
                 first_name = data.get('first_name', '')[0:User._meta.get_field('first_name').max_length])
        u.set_unusable_password()
        u.is_active = not account_settings.EMAIL_VERIFICATION
        u.save()
        accountbase = SocialAccount()
        accountbase.user = u
        accountbase.save()
        account.base = accountbase
        account.sync(data)
        send_email_confirmation(u, request=request)
        ret = complete_social_signup(request, u, account)
    return ret
示例#31
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             user = get_user_model().objects.get(email=email)
             email_address = user.emailaddress_set.get(email=user.email)
             if email_address.verified:
                 raise serializers.ValidationError(
                     _("A user is already registered with this e-mail address."
                       ))
             else:
                 user.delete()
     return email
示例#32
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = user_email(sociallogin.account.user)
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif app_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin.serialize()
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # Ok, auto signup it is, at least the e-mail address is ok.
        # We still need to check the username though...
        if account_settings.USER_MODEL_USERNAME_FIELD:
            username = user_username(sociallogin.account.user)
            try:
                get_account_adapter().clean_username(username)
            except ValidationError:
                # This username is no good ...
                user_username(sociallogin.account.user, '')
        # FIXME: This part contains a lot of duplication of logic
        # ("closed" rendering, create user, send email, in active
        # etc..)
        try:
            if not get_adapter().is_open_for_signup(request,
                                                    sociallogin):
                return render(request,
                              "account/signup_closed.html")
        except ImmediateHttpResponse as e:
            return e.response
        get_adapter().save_user(request, sociallogin, form=None)
        ret = complete_social_signup(request, sociallogin)
    return ret
示例#33
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = user_email(sociallogin.account.user)
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif app_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin.serialize()
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # Ok, auto signup it is, at least the e-mail address is ok.
        # We still need to check the username though...
        if account_settings.USER_MODEL_USERNAME_FIELD:
            username = user_username(sociallogin.account.user)
            try:
                get_account_adapter().clean_username(username)
            except ValidationError:
                # This username is no good ...
                user_username(sociallogin.account.user, '')
        # FIXME: This part contains a lot of duplication of logic
        # ("closed" rendering, create user, send email, in active
        # etc..)
        try:
            if not get_adapter().is_open_for_signup(request,
                                                    sociallogin):
                return render(request,
                              "account/signup_closed.html")
        except ImmediateHttpResponse as e:
            return e.response
        get_adapter().save_user(request, sociallogin, form=None)
        ret = complete_social_signup(request, sociallogin)
    return ret
示例#34
0
	def validate_email(self, email):
		
		self.is_phone_number  = is_using_phone_number(email)
		self.is_email_address = is_using_email_address(email)

		self.username = email
		if self.is_phone_number:
			return self.validate_phone_number(self.username)
		
		if allauth_settings.UNIQUE_EMAIL:
			if email and email_address_exists(email):
				msg = _("A user is already registered with this e-mail address.")
				raise serializers.ValidationError(msg)
		return self.username
示例#35
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
示例#36
0
 def is_auto_signup_allowed(self, request, sociallogin):
     auto_signup = app_settings.AUTO_SIGNUP
     if auto_signup:
         email = user_email(sociallogin.user)
         if email:
             if account_settings.UNIQUE_EMAIL:
                 if email_address_exists(email):
                     auto_signup = False
                     messages.error(
                         request, '해당 이메일 계정은 이미 회원가입이 되어 있습니다.'
                         ' 소셜 로그인이 아닌 사이트 자체 로그인을 사용해 주세요.')
         elif app_settings.EMAIL_REQUIRED:
             auto_signup = False
     return auto_signup
示例#37
0
    def clean_email(self):
        value = self.cleaned_data["email"]
        data = self.cleaned_data
        email = data.get("email", "verify")
        required_domain = getattr(settings, 'ACCOUNT_REQUIRED_EMAIL_DOMAIN', '')

        if required_domain:
            if not email.endswith(required_domain):
                raise forms.ValidationError(_('You need to have a .edu email to sign up'))

        if app_settings.UNIQUE_EMAIL:
            if value and email_address_exists(value):
                raise forms.ValidationError \
                    (_("A user is already registered with this e-mail address."))
        return value
示例#38
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     '''
     get role, raise exception if email exists and pertains to an owner
     '''
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             #get the role of existing email address
             user = User.objects.get(email=email)
             role = user.userprofile.basic_role
             if role == 'owner':
                 raise serializers.ValidationError(
                     _("An owner is already registered with this e-mail address."
                       ))
     return email
示例#39
0
 def validate_username(self, username):
     """Check for unique email address or phone number."""
     pattern = re.compile("^\d{10,13}")
     match = pattern.match(username)
     if match:
         username = self.validate_phone(username)
         # TODO: validate phone
         return username
     else:
         email = get_adapter().clean_email(username)
         if app_settings.UNIQUE_EMAIL:
             if email and email_address_exists(email):
                 raise serializers.ValidationError(
                     "A user is already registered with this e-mail address."
                 )
         return email
示例#40
0
 def is_auto_signup_allowed(self, request, sociallogin):
     # If email is specified, check for duplicate and if so, no auto signup.
     auto_signup = app_settings.AUTO_SIGNUP
     if auto_signup:
         email = user_email(sociallogin.user)
         # Let's check if auto_signup is really possible...
         if email:
             if settings.ACCOUNT_UNIQUE_EMAIL:
                 # Change: in Badge always check for email
                 if email_address_exists(email):
                     # Oops, another user already has this address.
                     # Otherwise False, because we cannot trust which provider properly verified the emails.
                     auto_signup = False
         elif app_settings.EMAIL_REQUIRED:
             # Nope, email is required and we don't have it yet...
             auto_signup = False
     return auto_signup
示例#41
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = sociallogin.account.user.email
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
        elif account_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        request.session['socialaccount_sociallogin'] = sociallogin
        url = reverse('socialaccount_signup')
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: There is some duplication of logic inhere
        # (create user, send email, in active etc..)
        u = sociallogin.account.user
        u.username = generate_unique_username(u.username
                                              or email 
                                              or 'user')
        u.last_name = (u.last_name or '') \
            [0:User._meta.get_field('last_name').max_length]
        u.first_name = (u.first_name or '') \
            [0:User._meta.get_field('first_name').max_length]
        u.email = email or ''
        u.set_unusable_password()
        sociallogin.save()
        send_email_confirmation(request, u)
        ret = complete_social_signup(request, sociallogin)
    return ret
示例#42
0
    def is_auto_signup_allowed(self, request, sociallogin):
        # If email is specified, check for duplicate and if so, no auto signup.
        auto_signup = app_settings.AUTO_SIGNUP
        if auto_signup:
            email = user_email(sociallogin.user)
            # Let's check if auto_signup is really possible...
            if email:
                if account_settings.UNIQUE_EMAIL:
                    if email_address_exists(email):
                        auto_signup = False
                        # FIXME: We redirect to signup form -- user will
                        # see email address conflict only after posting
                        # whereas we detected it here already.
            elif app_settings.EMAIL_REQUIRED:
                # Nope, email is required and we don't have it yet...
                auto_signup = False

        return auto_signup
示例#43
0
	def validate_email(self, value):
		# Create PasswordResetForm with the serializer
		email = value
		self.is_phone_number = is_using_phone_number(value)
		if self.is_phone_number:
			return self.validate_phone_number(value)
			
		if not email_address_exists(email):
			msg = _('Account with this email address does not exists.')
			raise serializers.ValidationError(msg)

		#if  not email_is_verified(email):
		#	msg = _('You must confirm your account before you can change a password.')
		#	raise serializers.ValidationError(msg)

		self.reset_form = CustomPasswordResetForm(data=self.initial_data)
		if not self.reset_form.is_valid():
			raise serializers.ValidationError(self.reset_form.errors)

		return value
示例#44
0
 def is_open_for_signup(self, request, sociallogin):
     email = user_email(sociallogin.user)
     # If we have a user with that email already, we don't allow
     # a signup through a new provider. Revisit this in the future.
     if email_address_exists(email):
         User = get_user_model()
         try:
             user = User.objects.get(email__iexact=email)
             social_set = user.socialaccount_set.all()
             # If the account doesn't have any social logins yet,
             # allow the signup.
             if not social_set:
                 return True
             providers = [a.provider for a in social_set]
             request.other_logins = LoginMethod.objects.filter(
                 provider_id__in=providers)
         except User.DoesNotExist:
             request.other_logins = []
         return False
     else:
         return True
示例#45
0
文件: forms.py 项目: Avatazjoe/apr
 def clean_email(self):
     email = self.cleaned_data['email']
     if email_address_exists(email) and email != self.initial['email']:
         raise forms.ValidationError(_("This email already exists."))
     return email
示例#46
0
 def validate_email(self, email):
     email = get_adapter().clean_email(email)
     if allauth_settings.UNIQUE_EMAIL:
         if email and email_address_exists(email):
             raise serializers.ValidationError("이미 등록된 메일입니다.")
     return email
示例#47
0
def _process_signup(request, sociallogin):
    # If email is specified, check for duplicate and if so, no auto signup.
    auto_signup = app_settings.AUTO_SIGNUP
    email = user_email(sociallogin.account.user)
    if auto_signup:
        # Let's check if auto_signup is really possible...
        if email:
            if account_settings.UNIQUE_EMAIL:
                if email_address_exists(email):
                    # Oops, another user already has this address.  We
                    # cannot simply connect this social account to the
                    # existing user. Reason is that the email adress may
                    # not be verified, meaning, the user may be a hacker
                    # that has added your email address to his account in
                    # the hope that you fall in his trap.  We cannot check
                    # on 'email_address.verified' either, because
                    # 'email_address' is not guaranteed to be verified.
                    auto_signup = False
                    # FIXME: We redirect to signup form -- user will
                    # see email address conflict only after posting
                    # whereas we detected it here already.
                else:
                    # Extra stuff hacked in here to integrate with
                    # the account whitelist app.
                    # Will be ignored if the whitelist app can't be
                    # imported, thus making this slightly less hacky.
                    whitelist_model_setting = getattr(
                        settings,
                        'SOCIALACCOUNT_WHITELIST_MODEL',
                        None
                    )
                    if whitelist_model_setting:
                        whitelist_model_path = whitelist_model_setting.split(r'.')
                        whitelist_model_str = whitelist_model_path[-1]
                        whitelist_path_str = r'.'.join(whitelist_model_path[:-1])
                        try:
                            whitelist_app = __import__(whitelist_path_str, fromlist=[whitelist_path_str])
                            whitelist_model = getattr(whitelist_app, whitelist_model_str, None)
                            if whitelist_model:
                                try:
                                    guest = whitelist_model.objects.get(email=email)
                                    if not guest.active:
                                        auto_signup = False
                                except whitelist_model.DoesNotExist:
                                    auto_signup = False
                        except ImportError:
                            pass
        elif app_settings.EMAIL_REQUIRED:
            # Nope, email is required and we don't have it yet...
            auto_signup = False
    if not auto_signup:
        url = reverse('socialaccount_login_error')
        ret = HttpResponseRedirect(url)
    else:
        # FIXME: This part contains a lot of duplication of logic
        # ("closed" rendering, create user, send email, in active
        # etc..)
        try:
            if not get_account_adapter().is_open_for_signup(request):
                return render(request,
                              "account/signup_closed.html")
        except ImmediateHttpResponse as e:
            return e.response
        u = sociallogin.account.user
        if account_settings.USER_MODEL_USERNAME_FIELD:
            user_username(u,
                          generate_unique_username(user_username(u)
                                                   or email 
                                                   or 'user'))
        u.last_name = (u.last_name or '') \
            [0:User._meta.get_field('last_name').max_length]
        u.first_name = (u.first_name or '') \
            [0:User._meta.get_field('first_name').max_length]
        user_email(u, email or '')
        u.set_unusable_password()
        sociallogin.save(request)
        ret = complete_social_signup(request, sociallogin)
    return ret