Previous topic

stalker.db

Next topic

stalker.db.auth.authenticate

This Page

stalker.db.auth

stalker.db.auth

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 three functions to log a user in, first one is session() that create the session and if there where user entry in session it return true else return false, the second one is authenticate(), which accepts username and password and returns a User object:

from stalker.db import auth
user_obj = auth.authenticate("username", "password")

The third one is the login() which uses a given User object and creates a Beaker Session and stores the logged in user id in that session.

The get_user() can be used to get the authenticated and logged in User object.

The basic usage of the system is as follows:

from stalker import db
from stalker.db import auth
from stalker.core.models import user

if auth.session():
    # user has login data 
    auth.login()
else
    #user doesn't have login data get them with login prompt
    get_user_data()
    login(username, password)

The module also introduces a decorator called login_required() to help adding the authentication functionality to any function or method. There is also another decorator called premission_required() to check if the logged in user is in the given permission group.