Parcourir la source

bozza recupero/salvataggio uuid per autenticazione

auth
Andrea Papotti il y a 13 ans
Parent
révision
672176401b
1 fichiers modifiés avec 44 ajouts et 0 suppressions
  1. +44
    -0
      decorators.py

+ 44
- 0
decorators.py Voir le fichier

@@ -1,10 +1,21 @@
#!/usr/bin/python
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: nil; -*-

## all
from singleton import Singleton

## WSGITemplate
from template import render
from functools import partial

## WSGIAuth
import Cookie
import hashlib
import hmac
md5 = lambda x : hashlib.md5( x ).hexdigest()
sha1 = lambda key,value: hmac.new( key, value, hashlib.sha1 ).hexdigest()

#------------------------------------------------------------------------------

class WSGITemplate( object ):
__metaclass__ = Singleton
@@ -125,3 +136,36 @@ class WSGIMySQL( object ):
for dsndict in self.__dsn.items():
for conn in dsndict['pool']:
conn.close()


class WSGISimpleAuth( object ):
__metaclass__ = Singleton

def __init__( self, secret_key, login_url=None, forbidden_url=None ):
self.__secret_key = secret_key

def auth( self, permission='', group='', p_g_mode='AND', p_mode='OR', g_mode='OR' ):
def real_decorator( wsgi_application ):
def wrapper( environ, start_response ):
try:
uuid = Cookie.SimpleCookie(environ["HTTP_COOKIE"])["uuid"].value
except:
uuid = None

environ['auth.uuid'] = uuid

def my_start_response( status, response_headers ):
cookie = Cookie.SimpleCookie()
cookie["uuid"] = uuid
response_headers.append( ('Set-Cookie',cookie.OutputString()) )
start_response( status, response_headers );

for item in wsgi_application( environ, my_start_response ):
yield item

return wrapper

return real_decorator


# EOF

Chargement…
Annuler
Enregistrer