Adapter

class allauth.account.adapter.DefaultAccountAdapter(request: HttpRequest | None = None)

The adapter class allows you to override various functionality of the allauth.account app. To do so, point settings.ACCOUNT_ADAPTER to your own class that derives from DefaultAccountAdapter and override the behavior by altering the implementation of the methods according to your own needs.

add_message(request: HttpRequest, level: int, message_template: str | None = None, message_context: dict[str, Any] | None = None, extra_tags: str = '', message: str | None = None) None

Wrapper of django.contrib.messages.add_message, that reads the message text from a template.

authenticate(request: HttpRequest, **credentials: Any) AbstractBaseUser | None

Only authenticates, does not actually login. See login

can_delete_email(email_address: EmailAddress) bool

Returns whether or not the given email address can be deleted.

clean_email(email: str) str

Validates an email value. You can hook into this if you want to (dynamically) restrict what email addresses can be chosen.

clean_password(password: str, user: AbstractBaseUser | None = None) str

Validates a password. You can hook into this if you want to restric the allowed password choices.

clean_phone(phone: str) str

Validates a phone number. You can hook into this if you want to (dynamically) restrict what phone numbers can be chosen.

clean_username(username: str, shallow: bool = False) str

Validates the username. You can hook into this if you want to (dynamically) restrict what usernames can be chosen.

confirm_email(request: HttpRequest, email_address: EmailAddress) bool

Marks the email address as confirmed on the db

format_email_subject(subject: str) str

Formats the given email subject.

generate_email_verification_code() str

Generates a new email verification code.

generate_login_code() str

Generates a new login code.

generate_password_reset_code() str

Generates a new password reset code.

generate_phone_verification_code(*, user: AbstractBaseUser, phone: str) str

Generates a new phone verification code.

get_client_ip(request: HttpRequest) str

Returns the IP address of the client.

get_email_confirmation_url(request: HttpRequest, emailconfirmation: EmailConfirmation) str

Constructs the email confirmation (activation) url.

Note that if you have architected your system such that email confirmations are sent outside of the request context request can be None here.

get_email_verification_redirect_url(email_address: EmailAddress) str

The URL to return to after email verification.

get_from_email() str

This is a hook that can be overridden to programmatically set the ‘from’ email address for sending emails

get_login_redirect_url(request: HttpRequest) str

Returns the default URL to redirect to after logging in. Note that URLs passed explicitly (e.g. by passing along a next GET parameter) take precedence over the value returned here.

get_logout_redirect_url(request: HttpRequest) str

Returns the URL to redirect to after the user logs out. Note that this method is also invoked if you attempt to log out while no users is logged in. Therefore, request.user is not guaranteed to be an authenticated user.

get_password_change_redirect_url(request: HttpRequest) str

The URL to redirect to after a successful password change/set.

NOTE: Not called during the password reset flow.

get_phone(user: AbstractBaseUser) tuple[str, bool] | None

Returns the phone number stored for the given user. A tuple of the phone number itself, and whether or not the phone number was verified is returned.

get_reauthentication_methods(user: AbstractBaseUser | AnonymousUser) list[dict]

The order of the methods returned matters. The first method is the default when using the @reauthentication_required decorator.

get_reset_password_from_key_url(key: str) str

Method intended to be overridden in case the password reset email needs to be adjusted.

get_signup_redirect_url(request: HttpRequest) str

Returns the default URL to redirect to directly after signing up.

get_user_by_phone(phone: str) AbstractBaseUser | None

Looks up a user given the specified phone number. Returns None if no user was found.

is_email_verified(request: HttpRequest, email: str) bool

Checks whether or not the email address is already verified beyond allauth scope, for example, by having accepted an invitation before signing up.

is_login_by_code_required(login: Login) bool

Returns whether or not login-by-code is required for the given login.

is_open_for_signup(request: HttpRequest) bool

Checks whether or not the site is open for signups.

Next to simply returning True/False you can also intervene the regular flow by raising an ImmediateHttpResponse

new_user(request: HttpRequest) AbstractBaseUser

Instantiates a new User instance.

phone_form_field(**kwargs: Any) Any

Returns a form field used to input phone numbers.

populate_username(request: HttpRequest, user: AbstractBaseUser) None

Fills in a valid username, if required and missing. If the username is already present it is assumed to be valid (unique).

render_mail(template_prefix: str, email: str | list[str], context: dict[str, Any], headers: dict[str, str] | None = None) EmailMessage

Renders an email to email. template_prefix identifies the email that is to be sent, e.g. “account/email/email_confirmation”

save_user(request: HttpRequest, user: AbstractBaseUser, form: BaseForm, commit: bool = True) AbstractBaseUser

Saves a new User instance using information provided in the signup form.

send_password_reset_mail(user: AbstractBaseUser, email: str, context: dict[str, Any]) None

Method intended to be overridden in case you need to customize the logic used to determine whether a user is permitted to request a password reset. For example, if you are enforcing something like “social only” authentication in your app, you may want to intervene here by checking user.has_usable_password

send_unknown_account_sms(phone: str, **kwargs: Any) None

In case enumeration prevention is enabled, and, a verification code is requested for an unlisted phone number, this method is invoked to send a text explaining that no account is on file.

send_verification_code_sms(user: AbstractBaseUser, phone: str, code: str, **kwargs: Any) None

Sends a verification code.

set_password(user: AbstractBaseUser, password: str) None

Sets the password for the user.

set_phone(user: AbstractBaseUser, phone: str, verified: bool) None

Sets the phone number (and verified status) for the given user.

set_phone_verified(user: AbstractBaseUser, phone: str) None

Marks the specified phone number for the given user as verified. Note that the user is already expected to have the phone number attached to the account.