models

Models needed for registration, and user servicing.

class pyramid_fullauth.models.User(*args, **kwargs)[source]

Bases: UserPasswordMixin, UserEmailMixin, Base

User object.

Switch possible email and new_email kwarg into new column attribute names.

delete()[source]

Perform soft delete action. along with checking if it’s super admin, or not.

Rises pyramid_fullauth.exceptions.DeleteException:

if you try to delete last super admin.

Note

You should use this method to delete users

email_change_key
property is_active

Check if user is active.

Returns:

Returns False if user account is not active (or deleted).

Return type:

bool

password

password field

provider_id(provider)[source]

Return provider identification for give user.

Parameters:

provider (str) – provider name

Returns:

provider identification

Return type:

str

reset_key

reset key field

validate_is_admin(_, value)[source]

Validate is_admin value, we forbid the deletion of the last superadmin.

Raises:

AttributeError – Information about an error

class pyramid_fullauth.models.Group(**kwargs)[source]

User group object.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

class pyramid_fullauth.models.AuthenticationProvider(**kwargs)[source]

Model to store authentication methods for different providers.

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

models.mixins

Mixin’s main module.

class pyramid_fullauth.models.mixins.UserPasswordMixin[source]

Authentication field definition along with appropriate methods.

password = Column(None, Unicode(length=128), table=None, nullable=False)

password field

_hash_algorithm = Column('hash_algorithm', Enum('sha3_224', 'md5', 'shake_256', 'sha384', 'sha3_512', 'sha256', 'sha3_384', 'blake2b', 'sha512', 'sha224', 'sha1', 'sha3_256', 'blake2s', 'shake_128', name='hash_algorithms_enum'), table=None, nullable=False, default=ScalarElementColumnDefault('sha256'))

hash_algorithm field

_salt = Column('salt', Unicode(length=128), table=None, nullable=False)

salt field

reset_key = Column(None, String(length=255), table=None)

reset key field

check_password(password)[source]

Check if password correspond to the saved one.

Parameters:

password (str) – password to compare

Returns:

True, if password is same, False if not

Return type:

bool

classmethod hash_password(password, salt, hash_method)[source]

Produce hash out of a password.

Parameters:
  • password (str) – password string, not hashed

  • salt (str) – salt

  • hash_method (callable) – a hash method which will be used to generate hash

Returns:

hashed password

Return type:

str

password_validator(_, password)[source]

Validate password.

Password validator keeps new password hashed. Rises Value error on empty password

Parameters:
  • key (str) – field key

  • password (str) – new password

Returns:

hashed and salted password

Return type:

str

Raises:

pyramid_fullauth.exceptions.EmptyError

Note

If you’re using this Mixin on your own User object, don’t forget to add a listener as well, like that:

from sqlalchemy.event import listen

listen(User.password, 'set', User.password_listener, retval=True)

Note

For more information on Attribute Events in sqlalchemy see:

sqlalchemy.orm.events.AttributeEvents.set()

class pyramid_fullauth.models.mixins.UserEmailMixin(*args, **kwargs)[source]

User email fields and functionality.

Switch possible email and new_email kwarg into new column attribute names.

email

Email field comparator.

new_email

Email field comparator.

email_change_key = Column(None, String(length=255), table=None)
change_email()[source]

Change email after activation.

We don’t clear new email field because of validator of email which won’t allow to None value.

set_new_email(email_new)[source]

Set new email and generate new email change hash.

Parameters:

email_new (str) – email address

Returns:

generated email_change_key

Trype:

str

validate_email(_, address)[source]

Validate email addresses.

Note

See pyramid docs about simple validators

Parameters:
  • key (str) – field key

  • address (str) – email address

Raises:

models.extensions

CaseInsensitive comparator for sqlalchemy models.

class pyramid_fullauth.models.extensions.CaseInsensitive(word)[source]

Hybrid value representing a lower case representation.

Initialise comparator object.