Python allauth.account.adapter 模块,get_adapter() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用allauth.account.adapter.get_adapter()

项目:popcorn-backend    作者:We-Lab    | 项目源码 | 文件源码
def save(self, request):
        adapter = get_adapter()
        user = adapter.new_user(request)
        self.cleaned_data = self.get_cleaned_data()

        user.nickname = self.cleaned_data['nickname']
        user.gender = self.cleaned_data['gender']
        user.phone_number = self.cleaned_data['phone_number']
        user.date_of_birth = self.cleaned_data['date_of_birth']
        user.profile_img = self.cleaned_data['profile_img']

        adapter.save_user(request, user, self)
        self.custom_signup(request, user)
        setup_user_email(request, user, [])

        return user
项目:intake    作者:codeforamerica    | 项目源码 | 文件源码
def create_user_from_invite(self, password=None, accept=True, **kwargs):
        '''This is a utility function that
        creates a new user, with an associated profile and organization,
        from an existing invite.
        It should be used to programmatically create users, similar to
        django.contrib.auth.models.UserManager.create_user()
        If no password is supplied, this will assign an unusable password
        to the user.
        This method adapts steps from:
            allauth.account.forms.SignUpForm.save()
            allauth.account.forms.SignUpForm.save.adapter.save_user()
            user_accounts.forms.SignUpForm.custom_signup()
            allauth.account.utils.setup_user_email()
        This will mark the invite as accepted, or as designated in the
        `accept` option.
        '''
        if accept:
            self.accepted = True
            self.save()
        # get the right adapter
        allauth_adapter = get_adapter()
        MockRequest = namedtuple('MockRequest', 'session')
        mock_request = MockRequest(session={})
        # get an empty instance of designated U ser model
        user = allauth_adapter.new_user(request=mock_request)
        data = dict(email=self.email)
        if password:
            data['password1'] = password
        MockForm = namedtuple('MockForm', 'cleaned_data')
        user = allauth_adapter.save_user(
            request=mock_request,
            user=user,
            form=MockForm(cleaned_data=data)
        )
        user.groups.add(*self.groups)
        user_accounts.models.UserProfile.create_from_invited_user(
            user, self, **kwargs)
        allauth_account_utils.setup_user_email(mock_request, user, [])
        return user
项目:django-twilio-tfa    作者:rtindru    | 项目源码 | 文件源码
def get_search_fields(self, request):
        base_fields = get_adapter().get_user_search_fields()
        return list(map(lambda a: 'user__' + a, base_fields))
项目:api    作者:manosxgotas    | 项目源码 | 文件源码
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
项目:api    作者:manosxgotas    | 项目源码 | 文件源码
def validate_password1(self, password1):
        return get_adapter().clean_password(password1)
项目:api    作者:manosxgotas    | 项目源码 | 文件源码
def save(self, request):
        adapter = get_adapter()
        user = adapter.new_user(request)
        self.cleaned_data = self.get_cleaned_data()
        adapter.save_user(request, user, self)
        setup_user_email(request, user, [])
        user.donante.genero = self.cleaned_data['genero']
        user.is_active = False
        user.save()
        enviar_mail_activacion(user)
        return user
项目:Provo-Housing-Database    作者:marcopete5    | 项目源码 | 文件源码
def get_search_fields(self, request):
        base_fields = get_adapter().get_user_search_fields()
        return list(map(lambda a: 'user__' + a, base_fields))
项目:tunga-api    作者:tunga-io    | 项目源码 | 文件源码
def save(self, request):
        email = self.initial_data.get('email', None)
        user_type = self.initial_data.get('type', None)
        confirm_key = self.initial_data.get('key', None)
        invite_key = self.initial_data.get('invite_key', None)
        application = None
        invitation = None

        if confirm_key:
            try:
                application = DeveloperApplication.objects.get(confirmation_key=confirm_key, used=False)
                user_type = USER_TYPE_DEVELOPER
            except:
                raise ValidationError({'key': 'Invalid or expired key'})
        elif invite_key:
            try:
                invitation = DeveloperInvitation.objects.get(invitation_key=invite_key, used=False)
                user_type = invitation.type
            except:
                raise ValidationError({'invite_key': 'Invalid or expired key'})

        if application or invitation:
            # Skip email activation for developer applications and invitations
            adapter = get_adapter()
            adapter.stash_verified_email(request, email)

        user = super(TungaRegisterSerializer, self).save(request)
        user.type = user_type
        user.first_name = self.initial_data['first_name']
        user.last_name = self.initial_data['last_name']
        user.pending = False
        user.save()

        if application:
            application.used = True
            application.used_at = datetime.datetime.utcnow()
            application.save()

            profile = UserProfile(user=user, phone_number=application.phone_number, country=application.country)
            profile.city = application.city
            profile.save()

        if invitation:
            invitation.used = True
            invitation.used_at = datetime.datetime.utcnow()
            invitation.save()

            # Notify admins that developer has accepted invitation
            send_developer_invitation_accepted_email.delay(invitation.id)
        return user