This module provides basic methods to manage users authentication state on your site. This module uses encripted bottle cookies to store user id from database and perform checks using this id.
Just Python 2.7+ and Bottle. You also need to have some database module. Every "self.db" method in this module is just a demo.
from bottle import *
from bottle_user_auth import User
@root.route('/')
def index_page(): #displays index page
user = User() #here and below - creates an instance of User class
if user.loggedin:
return 'You are an authenticated user'
redirect('/login')
@root.post('/login')
@view('login_page')
def login_page():
#assume you have a login page with two fields:
#"email" and "password" and submit button
@root.post('/login')
def user_login(): #getting credentials from POST request from login page
user = User()
if user.authenticate(
request.POST.get( 'email' ),
request.POST.get( 'password' )
):
#if authentication has been successful module will assing a cookie
#with encripted user id from database to user
redirect('/')
redirect('/login/error')