Python allauth.account.adapter.get_adapter() Examples
The following are 9
code examples of allauth.account.adapter.get_adapter().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
allauth.account.adapter
, or try the search function
.
Example #1
Source File: forms.py From appstore with GNU Affero General Public License v3.0 | 5 votes |
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"]
Example #2
Source File: forms.py From appstore with GNU Affero General Public License v3.0 | 5 votes |
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"]
Example #3
Source File: invitation.py From intake with MIT License | 5 votes |
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
Example #4
Source File: adapters.py From django-invitations with GNU General Public License v3.0 | 5 votes |
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)()
Example #5
Source File: serializers.py From django-rest-auth with MIT License | 5 votes |
def validate_username(self, username): username = get_adapter().clean_username(username) return username
Example #6
Source File: serializers.py From django-rest-auth with MIT License | 5 votes |
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
Example #7
Source File: serializers.py From django-rest-auth with MIT License | 5 votes |
def validate_password1(self, password): return get_adapter().clean_password(password)
Example #8
Source File: serializers.py From django-rest-auth with MIT License | 5 votes |
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
Example #9
Source File: serializers.py From openwisp-radius with GNU General Public License v3.0 | 5 votes |
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