blob: 35c047569026ec6ab38449f0d5e3910d3155b737 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# -*- coding: utf-8 -*-
import account
import ldap
import os
from flask import Flask, g, session
from utils import *
from views import default, admin
app = Flask(__name__)
app.register_blueprint(default.bp)
app.register_blueprint(admin.bp, url_prefix='/admin')
app.config.from_object('accounts.default_settings')
if 'SPLINE_ACCOUNT_WEB_SETTINGS' in os.environ:
app.config.from_envvar('SPLINE_ACCOUNT_WEB_SETTINGS')
app.all_services = account.SERVICES #TODO: take that from our json file or so
app.username_blacklist = list()
app.user_backend = get_backend(app.config['USER_BACKEND'], app)
app.mail_backend = get_backend(app.config['MAIL_BACKEND'], app)
@app.before_request
def session_permanent():
if app.config.get('PERMANENT_SESSION_LIFETIME'):
session.permanent = True
else:
session.permanent = False
@app.before_request
def initialize_user():
g.user = None
if 'username' in session and 'password' in session:
username = ensure_utf8(session['username'])
password = ensure_utf8(decrypt_password(session['password']))
try:
g.user = current_app.user_backend.auth(username, password)
except ldap.INVALID_CREDENTIALS:
# we had crap in the session, delete it
logout_user()
@app.before_first_request
def read_blacklist():
if app.config.get('USERNAME_BLACKLIST_FILE'):
with open(app.config['USERNAME_BLACKLIST_FILE']) as f:
app.username_blacklist = f.read().split('\n')
@app.context_processor
def template_default_context():
return {
'app': app
}
|