Skip to content
Pierre Quentel edited this page Apr 24, 2016 · 3 revisions

Karrigell provides a set of functions to manage application users and their rights. They rely on a users database and use a script to manage users login and logout

Different roles can be set to users, to specify different access right to scripts or files. The levels can be "admin", "edit" or "visit". Usually, an administrator has all read and write access to all folders, files and scripts ; editors can read and modify some pages ; visitors can only see a set of pages

Users database

An application defines its user database by the attribute <font color#"#338" size"2">users_db (see Application settings).

It is an instance of a database management class. The module admin_db provides one such class : SQLiteUsersDb. This class stores user information in a SQLite database. It is initialized with one argument : the path of the database in the file system.

Login script

An application defines a script that will be used to ask a user his login and password, and that will check that they match a user in the database.

The url of this script is specified with the application attribute login_url. It defaults to (root_url)/admin/login.py/login, that is, the function login() in the script login.py in folder www/admin of the Karrigell distribution.

The login script can be customized, but the arguments of the login() function must remain the same as in this default script :

  • role : the requested role
  • origin : the url of the script where the login() function was called. It is used to redirect the user to this original script if the login was successful

##Functions

The functions available in scripts to manage users are :

###Login([role[,login_url[,origin]]]) When the framework runs this function, it checks if the user is already authenticated and has the required role (admin, edit or visit). If a user has the admin role, he also has the edit and visit role ; if it has the edit role, he also has the visit role.

If the user is not authenticated, or does not have the required role, a redirection to the specified login_url described above is performed.

role defaults to "admin". login_url defaults to the url of the login script defined above.

After a successful authentication, the user is redirected to the url specified in origin. If not specified, the redirection leads to the page where the Login() function was called.

##Logout([redir_to]) When this function is run, the cookies used to store information about a logged in user are erased, so that he is no longer authenticated. The optional redir_to argument indicated the url where the user should be redirected after this logout operation was performed. It defaults to the url of the script where the Logout() function was run.

##User() This function returns an object with the attributes login and role, matching user login and role (admin, edit or visit), or None if no user is authenticated.

GettingStarted

Clone this wiki locally