models

Models needed for registration, and user servicing.

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

Bases: pyramid_fullauth.models.mixins.password.UserPasswordMixin, pyramid_fullauth.models.mixins.email.UserEmailMixin, sqlalchemy.ext.declarative.api.Base

User 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.

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

is_active[source]

Check if user is active.

Returns:Returns False if user account is not active (or deleted).
Return type:bool
provider_id(provider)[source]

Return provider identification for give user.

Parameters:provider (str) – provider name
Returns:provider identification
Return type:str
validate_is_admin(key, 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

class pyramid_fullauth.models.mixins.UserPasswordMixin

Authentication field definition along with appropriate methods.

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

password field

_hash_algorithm = Column('hash_algorithm', Enum('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', name='hash_algorithms_enum'), table=None, nullable=False, default=ColumnDefault(u'sha1'))

hash_algorithm field

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

salt field

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

reset key field

check_password(password)

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)

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(key, password)

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

User email fields and functionality.

email = Column(None, Unicode(length=254), table=None, nullable=False)
new_email = Column(None, Unicode(length=254), table=None)
email_change_key = Column(None, String(length=255), table=None)
change_email()

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)

Set new email and generate new email change hash.

Parameters:email_new (str) – email address
Returns:generated email_change_key
Trype:str
validate_email(key, address)

Validate email addresses.

Note

See pyramid docs about simple validators

Parameters:
  • key (str) – field key
  • address (str) – email address
Raises:
  • EmailValidationError
  • EmptyError

Table Of Contents

Previous topic

Api

Next topic

auth

This Page