Skip to content

A lightweight authorization and user management module for Python

License

Notifications You must be signed in to change notification settings

jwoschitz/SimpleAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Auth

This module provides a lightweight authorization and login module with almost no dependencies

Dependencies

  • This module has been written for Python 2.7, has not been tested yet with other versions.
  • Currently this module needs MySQLdb, will change this in the future to support also SQLite and other database providers.

Structure

  • console_demo
    • contains a small console application which shows an example usage of the auth module
  • src
    • the source code
  • tests
    • contains the unittests

Setup

  1. Create the database schema manually (see schema.sql), this will change in future versions
  2. Adapt config file to fit your needs, you may use this example as a starting point
  3. Import the module with import auth

Example usage

import auth

config_file = 'file/path/to/config.cfg'
auth_handler = auth.AuthHandler(config_file)

# an activation email will be send to the users email address, 
# this mail contains an activation token and an identifier (encoded email address)
user = auth_handler.create_user(email, password)

# we assume that we got the activation token from somewhere,
# usually the token should be included in the email (see console_demo for a concrete implementation)
user.activate(token)
user.login()

if user.is_logged_in:
    print "login successful."
else:
    result = {
        auth.LoginResult.USER_OR_PASSWORD_WRONG : "Wrong email or password.",
        auth.LoginResult.USER_IS_NOT_ACTIVATED : "Email is not activated.",
        auth.LoginResult.USER_IS_LOCKED_OUT : "Account has been locked."              
    }
    print result.get(user.login_result)

About

A lightweight authorization and user management module for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages