Commit 56e1dfcb authored by Julian Rother's avatar Julian Rother
Browse files

Restructured database wrapper

parent 5bf2f754
......@@ -44,16 +44,19 @@ def query(operation, *params):
import mysql.connector
if 'db' not in g or not g.db.is_connected():
g.db = mysql.connector.connect(user=config['MYSQL_USER'], password=config['MYSQL_PASSWD'], host=config['MYSQL_HOST'], database=config['MYSQL_DB'])
cur = g.db.cursor(dictionary=True)
cur.execute(operation.replace('?', '%s'), params)
return cur.fetchall()
if not hasattr(request, 'db'):
request.db = g.db.cursor(dictionary=True)
request.db.execute(operation.replace('?', '%s'), params)
elif config['DB_ENGINE'] == 'sqlite':
if 'db' not in g:
g.db = sqlite3.connect(config['SQLITE_DB'])
g.db.row_factory = dict_factory
cur = g.db.cursor()
cur.execute(operation, params)
return cur.fetchall()
if not hasattr(request, 'db'):
request.db = g.db.cursor()
request.db.execute(operation, params)
else:
return []
return request.db.fetchall()
def searchquery(text, columns, match, tables, suffix, *suffixparams):
params = []
......@@ -73,8 +76,12 @@ def searchquery(text, columns, match, tables, suffix, *suffixparams):
return query(expr, *params, *suffixparams)
LDAP_USERRE = re.compile(r'[^a-z0-9]')
notldap = {
'videoag':('videoag', ['users','videoag'], {'uid': 'videoag', 'givenName': 'Video', 'sn': 'Geier'}),
'gustav':('passwort', ['users'], {'uid': 'gustav', 'givenName': 'Gustav', 'sn': 'Geier'})
}
def ldapauth(user, password):
notldap = {'videoag':('videoag', ['users','videoag']), 'gustav':('passwort', ['users'])}
user = LDAP_USERRE.sub(r'', user.lower())
if 'LDAP_HOST' in config:
import ldap3
......@@ -91,8 +98,6 @@ def ldapauth(user, password):
return None, []
def ldapget(user):
notldap = {'videoag': {'uid': 'videoag', 'givenName': 'Video', 'sn': 'Geier'},
'gustav': {'uid': 'gustav', 'givenName': 'Gustav', 'sn': 'Geier'}}
user = LDAP_USERRE.sub(r'', user.lower())
if 'LDAP_HOST' in config:
import ldap3
......@@ -102,7 +107,7 @@ def ldapget(user):
e = conn.entries[0]
return {'uid': user, 'givenName': e.givenName.value, 'sn':e.sn.value}
else:
return notldap[user]
return notldap[user][2]
@app.route('/')
def index():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment