This is the authentication system of Stalker. Uses Beaker for the session management.
This helper module is written to help users to persist their login information in their system. The aim of this function is not security. So one can quickly by-pass this system and get himself/herself logged in or query information from the database without login.
The user information is going to be used in the database to store who created, updated, read or delete the data.
There are two main functions to be used in the process of login. The first one is stalker.ext.auth.authenticate(), which accepts username and password as strings and returns a stalker.core.models.User object:
from stalker.ext import auth
user_obj = auth.authenticate("username", "password")
The second one is the stalker.ext.auth.login() which uses a given stalker.core.models.User object and creates a Beaker Session and stores the logged in user id in that session.
The stalker.ext.auth.get_user() can be used to get the authenticated and logged in stalker.core.models.User object.
The basic usage of the system is as follows:
from stalker import db
from stalker.ext import auth
from stalker.core.models import User
if auth.SESSION_KEY in auth.SESSION:
# user has login data
auth.login()
else
#user doesn't have login data get them with login prompt
username, password = get_user_data()
auth.login(username, password)
The module also introduces a decorator called stalker.ext.auth.login_required() to help adding the authentication functionality to any function or method.
There is also another decorator called stalker.ext.auth.premission_required() to check if the logged in user is in the given permission group.
There are also two utility functions two check and set encrypted passwords. stalker.ext.auth.check_password() and stalker.ext.auth.set_password().