G.. :py:currentmodule:: fplaneserver.lib.user
user
- Flask user login handling¶
This module contains a user model, the database setup and the Flask-login hooks for storing usernames and passwords on the server
-
exception
fplaneserver.lib.user.
InvalidUserException
(message, status_code=None)[source]¶ Bases:
fplaneserver.lib.user.UserException
Overloaded from
UserException
with a default status code 403-
status_code
= 403¶
-
-
exception
fplaneserver.lib.user.
NoUserException
(message, status_code=None)[source]¶ Bases:
fplaneserver.lib.user.UserException
Overloaded from
UserException
with a default status code 404-
status_code
= 401¶
-
-
exception
fplaneserver.lib.user.
UserException
(message, status_code=None)[source]¶ Bases:
Exception
Overloaded from Exception for handling user login errors.
Parameters: - message : str
The error message of the exception
- status_code : int, optional
The status_code to be sent with response. Default is 400
Attributes: - message : str
The error message of the exception
- status_code : int
The status_code to be sent with response.
-
to_dict
(self)[source]¶ Create a dictionart containing the message. This dictionary can be turned into a json and sent with the response
Returns: - dict
-
status_code
= 400¶
-
class
fplaneserver.lib.user.
User
(**kwargs)[source]¶ Bases:
peewee.Model
,flask_login.mixins.UserMixin
User object that wraps around a sqlite 3 database containing a table with the registered users.
The user apikey should be created using
binascii.hexlify(os.urandom(24))
Attributes: - id : int
The user id
- username : str
The username
- firstname : str
First name of the user
- lastname : str
Last name of the user
- email : str
E-mail address of the user
- password : str
The users password Currently unused
- apikey : str
The key used for login.
-
DoesNotExist
¶ alias of
UserDoesNotExist
-
_meta
= <peewee.Metadata object>¶
-
_schema
= <peewee.SchemaManager object>¶
-
apikey
= <TextField: User.apikey>¶
-
email
= <TextField: User.email>¶
-
firstname
= <TextField: User.firstname>¶
-
id
= <AutoField: User.id>¶
-
lastname
= <TextField: User.lastname>¶
-
password
= <TextField: User.password>¶
-
username
= <TextField: User.username>¶
-
fplaneserver.lib.user.
connect_db
()[source]¶ Connects to the database specified in the USER_DATABASE configuration field.
Returns: SqliteDatabase
-
fplaneserver.lib.user.
get_db
()[source]¶ Opens a new database connection if there is none yet for the current application context.
Returns: SqliteDatabase
-
fplaneserver.lib.user.
handle_user_error
(error)[source]¶ - Handler for errors, jsonifies the error as a dictionary
- and sets the response status code from the error status code.
Parameters: - error :
UserException
The user exception
Returns: flask.Response
-
fplaneserver.lib.user.
init_db
(app)[source]¶ Initialize the database.
Parameters: - app: Flask object
application
-
fplaneserver.lib.user.
load_user_from_request
(request)[source]¶ Interface hook for flask. For a given request object, try to load the user from the Authorization header. Return None, if the user cannot be found, or if the Authorization format is wrong.
The request object must contain an Authorization header of the form “FPS_API APIKEY=<user apikey>”
Parameters: - request :
flask.Request
The request object.
- request :