flowserv.model.user module
Base class to manage information about users that are registered with the API. Each user has a unique identifier and a display name. The identifier is generated automatically during user registration. It is used internally to reference a user.
The user manager contains methods to login and logout users. At login, the user is assigned an API key that can be used for authentication and authorization in requests to the API. Each key has a fixed lifespan after which it becomes invalid. If a user logs out the API key is invalidated immediately.
- class flowserv.model.user.UserManager(session, token_timeout: Optional[int] = 86400)
Bases:
objectThe user manager registers new users and handles requests to reset a user password. The user manager also allows users to login and to logout. A user that is logged in has an API key associated with them. This key is valid until a timeout period has passed. When the user logs out the API key is invalidated. API keys are stored in an underlying database.
- activate_user(user_id)
Activate the user with the given identifier. A user is active if the respective active flag in the underlying database is set to 1.
- Parameters
user_id (string) – Unique user identifier
- Return type
- Raises
- get_user(user_id, active=None)
Get handle for specified user. The active parameter allows to put an additional constraint on the value of the active property for the user.
Raises an unknown user error if no matching user exists.
- Return type
- Raises
- list_users(prefix=None)
Get a listing of registered users. The optional query string is used to filter users whose name starts with the given string.
- Parameters
prefix (string, default=None) – Prefix string to filter users based on their name.
- Return type
list(flowserv.model.base.User)
- Raises
- login_user(username, password)
Authorize a given user and assign an API key for them. If the user is unknown or the given credentials do not match those in the database an unknown user error is raised.
Returns the API key that has been associated with the user identifier.
- Parameters
username (string) – Unique name (i.e., email address) that the user provided when they registered
password (string) – User password specified during registration (in plain text)
- Return type
- Raises
- logout_user(api_key)
Invalidate the API key for the given user. This will logout the user.
- Parameters
user (flowserv.model.base.User) – Handle for user that is being logged out
- Return type
- register_user(username, password, verify=False)
Create a new user for the given username. Raises an error if a user with that name already is registered. Returns the internal unique identifier for the created user.
The verify flag allows to create active or inactive users. An inactive user cannot login until they have been activated. This option is intended for scenarios where the user receives an email after they register that contains a verification/activation link to ensure that the provided email address is valid.
- Parameters
username (string) – User email address that is used as the username
password (string) – Password used to authenticate the user
verify (bool, optional) – Determines whether the created user is active or inactive
- Return type
- Raises
- request_password_reset(username)
Request a password reset for the user with a given name. Returns the request identifier that is required as an argument to reset the password. The result is always going to be the identifier string independently of whether a user with the given username is registered or not.
Invalidates all previous password reset requests for the user.
- Parameters
username (string) – User email that was provided at registration
- Return type
string
- reset_password(request_id, password)
Reset the password for the user that made the given password reset request. Raises an error if no such request exists or if the request has timed out.
- Parameters
request_id (string) – Unique password reset request identifier
password (string) – New user password
- Return type
- Raises
- flowserv.model.user.validate_password(password)
Validate a given password. Raises constraint violation error if an invalid password is given.
Currently, the only constraint for passwords is that they are not empty
- Parameters
password (string) – User password for authentication
- Raises