websauna.system.user.userregistry module

Default user object generator.

class websauna.system.user.userregistry.DefaultEmailBasedUserRegistry(request)[source]

Bases: object

Default user backend which uses SQLAlchemy to store User models.

Provides default user actions

property Activation

Currently configured User SQLAlchemy model.

Return type

Type[InterfaceClass]

Returns

Class implementing IActivationModel.

property User

Currently configured User SQLAlchemy model.

Return type

Type[InterfaceClass]

Returns

Class implementing IUserModel.

activate_user_by_email_token(token)[source]

Get user by a password token issued earlier.

Consume any activation token.

Parameters

token (str) – Password token to be used to return the user.

Return type

Optional[UserMixin]

Returns

User instance of none if token is not found.

can_login(user)[source]

Verify if user is allowed do login.

Parameters

user (InterfaceClass) – User object.

Return type

bool

Returns

Boolean

can_reset_password(user)[source]

Verify if user is allowed to reset their password.

Parameters

user (InterfaceClass) – User object.

Return type

bool

Returns

Boolean

create_email_activation_token(user)[source]

Create activation token for the user to be used in the email

Parameters

user (InterfaceClass) – User object.

Return type

Tuple[str, int]

Returns

Tuple (email activation code, expiration in seconds)

create_password_reset_token(email)[source]

Sets password reset token for user.

Parameters

email (str) – Email to be used.

Return type

Optional[Tuple[object, str, int]]

Returns

[User, password reset token, token expiration in seconds]. None if user is disabled or is not email login based.

get_authenticated_user_by_email(email, password)[source]

Authenticate incoming user using email and password.

Parameters
  • email (str) – Provided email.

  • password (str) – Provided password.

Return type

Optional[UserMixin]

Returns

User instance of none if password does not match

get_authenticated_user_by_username(username, password)[source]

Authenticate incoming user using username and password.

Parameters
  • username (str) – Provided username.

  • password (str) – Provided password.

Return type

Optional[UserMixin]

Returns

User instance of none if password does not match

get_by_activation(activation)[source]

Return the User with the given activation.

Parameters

activation (InterfaceClass) – Activation object..

Return type

InterfaceClass

Returns

User object.

get_by_email(email)[source]

Return the User with the given email.

We always compare the lowercase version of User.email and email.

Parameters

email (str) – Email to be used.

Return type

InterfaceClass

Returns

User object.

get_by_username(username)[source]

Return the User with the given username.

We always compare the lowercase version of User.username and username.

Parameters

username (str) – Username to be used.

Return type

InterfaceClass

Returns

User object.

get_groups(user)[source]

Groups for a user.

Parameters

user (InterfaceClass) – User object.

Return type

List[GroupMixin]

Returns

List of groups for this user.

get_session_token(user)[source]

Get marker string we use to store reference to this user in authenticated session.

Parameters

user (InterfaceClass) – User object.

Returns

User id.

get_user_by_password_reset_token(token)[source]

Get user by a password token issued earlier.

Consume any activation token.

Parameters

token (str) – Reset password token to be used to return the user.

Return type

Optional[UserMixin]

Returns

User instance of none if token is not found.

get_user_by_session_token(token)[source]

Resolve the authenticated user by a session token reference.

Parameters

token (str) – Token to be used to return the user.

Return type

UserMixin

Returns

User object.

reset_password(user, password)[source]

Reset user password and clear all pending activation issues.

Parameters
  • user (InterfaceClass) – User object,

  • password (str) – New password.

set_password(user, password)[source]

Hash a password for persistent storage.

Uses password hasher registered in websauna.system.Initializer.configure_password().

Parameters
  • user (InterfaceClass) – User object.

  • password (str) – User password.

sign_up(registration_source, user_data)[source]

Sign up a new user through registration form.

Parameters
  • registration_source (str) – Indication where the user came from.

  • user_data (dict) – Payload with new user information.

Return type

UserMixin

Returns

Newly created User object.

verify_password(user, password)[source]

Validate user password.

Uses password hasher registered in websauna.system.Initializer.configure_password().

Parameters
  • user (InterfaceClass) – User object.

  • password (str) – User password.

Return type

bool

Returns

Boolean of the password verification.