diff options
author | Marian Sigler <m@qjym.de> | 2012-09-21 01:00:39 +0200 |
---|---|---|
committer | Marian Sigler <m@qjym.de> | 2012-09-21 01:00:39 +0200 |
commit | 6280e6f19e5aea3c2fff7e95e053c1ba63f5c22f (patch) | |
tree | b601699a7c56c86829ac9a4f2ef88d95c3c797b0 /utils.py | |
parent | 597db4fa95aab501de422f410c46a91bc6c6bbbd (diff) | |
download | web-6280e6f19e5aea3c2fff7e95e053c1ba63f5c22f.tar.gz web-6280e6f19e5aea3c2fff7e95e053c1ba63f5c22f.tar.bz2 web-6280e6f19e5aea3c2fff7e95e053c1ba63f5c22f.zip |
start with settings page
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -1,15 +1,17 @@ # -*- coding: utf-8 -*- from functools import wraps -from flask import request, render_template, session +from flask import flash, request, redirect, render_template, session, url_for from random import randint from Crypto.Cipher import AES +from werkzeug.exceptions import Forbidden -# from http://flask.pocoo.org/docs/patterns/viewdecorators/#templating-decorator + +# using http://flask.pocoo.org/docs/patterns/viewdecorators/ def templated(template=None): - def decorator(f): + def templated_(f): @wraps(f) - def decorated_function(*args, **kwargs): + def templated__(*args, **kwargs): template_name = template if template_name is None: template_name = request.endpoint \ @@ -20,8 +22,16 @@ def templated(template=None): elif not isinstance(ctx, dict): return ctx return render_template(template_name, **ctx) - return decorated_function - return decorator + return templated__ + return templated_ + +def login_required(f): + @wraps(f) + def login_required_(*args, **kwargs): + if 'username' not in session: + raise Forbidden + return f(*args, **kwargs) + return login_required_ def login_user(username, password): @@ -64,10 +74,5 @@ def decrypt_password(ciphertext): return encryptor.decrypt(ciphertext[16:]).rstrip('\0') -def login_required(func): - #TODO - return func - - # circular import from app import app |