Commit 0701bac8 authored by Julian Rother's avatar Julian Rother
Browse files

Added ldap wrapper

parent 22c06b14
from flask import Flask, render_template, g, request, url_for, redirect
from flask import Flask, render_template, g, request, url_for, redirect, session
import mysql.connector
import sqlite3
import os
import ldap3
import re
app = Flask(__name__)
config = app.config
......@@ -71,6 +73,23 @@ def searchquery(text, columns, match, tables, suffix, *suffixparams):
expr = 'SELECT *,SUM(_prio) AS _score FROM (%s) AS _tmp %s'%(' UNION '.join(subexprs), suffix)
return query(expr, *params, *suffixparams)
LDAP_USERRE = re.compile(r'[^a-z0-9]')
def ldapauth(user, password):
notldap = {'videoag':('videoag', ['users','videoag']), 'gustav':('passwort', ['users'])}
user = LDAP_USERRE.sub(r'', user.lower())
if 'LDAP_HOST' in config:
conn = ldap3.Connection(config['LDAP_HOST'], 'uid=%s,ou=users,dc=fsmpi,dc=rwth-aachen,dc=de'%user, password, auto_bind=True)
if"ou=groups,dc=fsmpi,dc=rwth-aachen,dc=de", "(&(cn=*)(memberUid=%s))"%user, attributes=['cn']):
groups = [ for e in conn.entries]
return user, groups
except ldap3.core.exceptions.LDAPBindError:
elif config.get('DEBUG') and user in notldap and password == notldap[user][0]:
return user, notldap[user][1]
return None, []
def index():
return render_template('index.html', latestvideos=query('''
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