本文整理汇总了Python中allauth.account.adapter.get_adapter方法的典型用法代码示例。如果您正苦于以下问题:Python adapter.get_adapter方法的具体用法?Python adapter.get_adapter怎么用?Python adapter.get_adapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类allauth.account.adapter
的用法示例。
在下文中一共展示了adapter.get_adapter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_email
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def clean_email(self):
email = self.cleaned_data["email"]
from allauth.account.adapter import get_adapter
email = get_adapter().clean_email(email)
self.users = filter_users_by_email(email, is_active=True)
return self.cleaned_data["email"]
示例2: save
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def save(self, request, **kwargs):
from django.contrib.sites.shortcuts import get_current_site
current_site = get_current_site(request)
email = self.cleaned_data["email"]
token_generator = EmailAwarePasswordResetTokenGenerator()
for user in self.users:
temp_key = token_generator.make_token(user)
# save it to the password reset model
# password_reset = PasswordReset(user=user, temp_key=temp_key)
# password_reset.save()
# send the password reset email
from django.urls import reverse
path = reverse("account_reset_password_from_key",
kwargs=dict(uidb36=user_pk_to_url_str(user),
key=temp_key))
from allauth.utils import build_absolute_uri
url = build_absolute_uri(
request, path)
context = {"current_site": current_site,
"user": user,
"password_reset_url": url,
"request": request}
from allauth.account import app_settings
if app_settings.AUTHENTICATION_METHOD \
!= app_settings.AuthenticationMethod.EMAIL:
context['username'] = user_username(user)
from allauth.account.adapter import get_adapter
get_adapter(request).send_mail(
'account/email/password_reset_key',
email,
context)
return self.cleaned_data["email"]
示例3: create_user_from_invite
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
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
示例4: get_invitations_adapter
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def get_invitations_adapter():
# Compatibility with legacy allauth only version.
LEGACY_ALLAUTH = hasattr(settings, 'ACCOUNT_ADAPTER') and \
settings.ACCOUNT_ADAPTER == 'invitations.models.InvitationsAdapter'
if LEGACY_ALLAUTH:
# defer to allauth
from allauth.account.adapter import get_adapter
return get_adapter()
else:
# load an adapter from elsewhere
return import_attribute(app_settings.ADAPTER)()
示例5: validate_username
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def validate_username(self, username):
username = get_adapter().clean_username(username)
return username
示例6: validate_email
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
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
示例7: validate_password1
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def validate_password1(self, password):
return get_adapter().clean_password(password)
示例8: save
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
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)
self.custom_signup(request, user)
setup_user_email(request, user, [])
return user
示例9: save
# 需要导入模块: from allauth.account import adapter [as 别名]
# 或者: from allauth.account.adapter import get_adapter [as 别名]
def save(self, request):
adapter = get_adapter()
user = adapter.new_user(request)
self.cleaned_data = self.get_cleaned_data()
# commit=False does not save the user to the DB yet
adapter.save_user(request, user, self, commit=False)
# the custom_signup method contains the openwisp specific logic
self.custom_signup(request, user)
setup_user_email(request, user, [])
return user