app.models.user

Description

Classes

User(*args, **kwargs)

User database model.

class app.models.user.User(*args, **kwargs)

User database model.

References

fs_uniquier field is required by flask-security-too: https://flask-security-too.readthedocs.io/en/stable/changelog.html#version-4-0-0

DoesNotExist

alias of app.models.user.UserDoesNotExist

_coerce = True
_meta = <peewee.Metadata object>
classmethod _normalize_data(data, kwargs)
property _pk
_pk_expr()
_populate_unsaved_relations(field_dict)
_prune_fields(field_dict, only)
_schema = <peewee.SchemaManager object>
active = <BooleanField: User.active>
classmethod add_index(*fields, **kwargs)
classmethod alias(alias=None)
classmethod bind(database, bind_refs=True, bind_backrefs=True, _exclude=None)
classmethod bind_ctx(database, bind_refs=True, bind_backrefs=True)
birth_date = <DateField: User.birth_date>
classmethod bulk_create(model_list, batch_size=None)
classmethod bulk_update(model_list, fields, batch_size=None)
calc_username() str

Come up with the best ‘username’ based on how the app is configured (via SECURITY_USER_IDENTITY_ATTRIBUTES). Returns the first non-null match (and converts to string). In theory this should NEVER be the empty string unless the user record isn’t actually valid.

New in version 3.4.0.

children
clone()
coerce(_coerce=True)
static copy(method)
classmethod create(**query)
classmethod create_table(safe=True, **options)
created_at = <TimestampField: User.created_at>
created_by = <ForeignKeyField: User.created_by>
created_by_id = <ForeignKeyField: User.created_by>
classmethod delete()
classmethod delete_by_id(pk)
delete_instance(recursive=False, delete_nullable=False)
deleted_at = <TimestampField: User.deleted_at>
dependencies(search_nullable=False)
property dirty_fields
document_set
classmethod drop_table(safe=True, drop_sequences=True, **options)
email = <CharField: User.email>
static ensure_password(plain_text: str) str
classmethod filter(*dq_nodes, **filters)
fs_uniquifier = <TextField: User.fs_uniquifier>
genre = <FixedCharField: User.genre>
classmethod get(*query, **filters)
get_auth_token() Union[str, bytes]

Constructs the user’s authentication token.

Raises

ValueError – If fs_token_uniquifier is part of model but not set.

Optionally use a separate uniquifier so that changing password doesn’t invalidate auth tokens.

This data MUST be securely signed using the remember_token_serializer

Changed in version 4.0.0: If user model has fs_token_uniquifier - use that (raise ValueError if not set). Otherwise fallback to using fs_uniqifier.

classmethod get_by_id(pk)
classmethod get_fields(exclude: Optional[list] = None, include: Optional[list] = None, sort_order: Optional[list] = None) set
get_id()

Returns the user identification attribute. ‘Alternative-token’ for Flask-Login. This is always fs_uniquifier.

New in version 3.4.0.

classmethod get_or_create(**kwargs)
classmethod get_or_none(*query, **filters)
get_redirect_qparams(existing: Optional[Dict[str, Any]] = None) Dict[str, Any]

Return user info that will be added to redirect query params.

Parameters

existing – A dict that will be updated.

Returns

A dict whose keys will be query params and values will be query values.

The returned dict will always have an ‘identity’ key/value. If the User Model contains ‘email’, an ‘email’ key/value will added. All keys provided in ‘existing’ will also be merged in.

New in version 3.2.0.

Changed in version 4.0.0: Add ‘identity’ using UserMixin.calc_username() - email is optional.

get_reset_token() str
get_security_payload() Dict[str, Any]

Serialize user object as response payload. Override this to return any/all of the user object in JSON responses. Return a dict.

has_permission(permission: str) bool

Returns True if user has this permission (via a role it has).

Parameters

permission – permission string name

New in version 3.3.0.

has_role(role: Union[str, Role]) bool

Returns True if the user identifies with the specified role.

Parameters

role – A role name or Role instance

id = <AutoField: User.id>
classmethod index(*fields, **kwargs)
classmethod insert(_Model__data=None, **insert)
classmethod insert_from(query, fields)
classmethod insert_many(rows, fields=None)
property is_active: bool

Returns True if the user is active.

is_alias()
property is_anonymous
property is_authenticated
is_dirty()
last_name = <CharField: User.last_name>
name = <CharField: User.name>
classmethod noop()
password = <CharField: User.password>
static raw(query: str)
reload()
classmethod replace(_Model__data=None, **insert)
classmethod replace_many(rows, fields=None)
roles = <ManyToManyField: User.roles>
save(*args: list, **kwargs: dict) int
classmethod select(*fields)
classmethod set_by_id(key, value)
classmethod table_exists()
tf_send_security_token(method: str, **kwargs: Any) Optional[str]

Generate and send the security code for two-factor.

Parameters
  • method – The method in which the code will be sent

  • kwargs – Opaque parameters that are subject to change at any time

Returns

None if successful, error message if not.

This is a wrapper around tf_send_security_token() that can be overridden to manage any errors.

New in version 3.4.0.

classmethod truncate_table(**options)
unwrap()
classmethod update(_Model__data=None, **update)
updated_at = <TimestampField: User.updated_at>
us_send_security_token(method: str, **kwargs: Any) Optional[str]

Generate and send the security code for unified sign in.

Parameters
  • method – The method in which the code will be sent

  • kwargs – Opaque parameters that are subject to change at any time

Returns

None if successful, error message if not.

This is a wrapper around us_send_security_token() that can be overridden to manage any errors.

New in version 3.4.0.

userrolethrough_set
classmethod validate_model()
verify_and_update_password(password: str) bool

Returns True if the password is valid for the specified user.

Additionally, the hashed password in the database is updated if the hashing algorithm happens to have changed.

N.B. you MUST call DB commit if you are using a session-based datastore (such as SqlAlchemy) since the user instance might have been altered (i.e. app.security.datastore.commit()). This is usually handled in the view.

Parameters

password – A plaintext password to verify

New in version 3.2.0.

verify_auth_token(data: Union[str, bytes]) bool

Perform additional verification of contents of auth token. Prior to this being called the token has been validated (via signing) and has not expired.

Parameters

data – the data as formulated by get_auth_token()

New in version 3.3.0.

Changed in version 4.0.0: If user model has fs_token_uniquifier - use that otherwise use fs_uniquifier.

static verify_reset_token(token: str) any