Commit f8ad70c5 authored by Nicholas J Anderson's avatar Nicholas J Anderson
Browse files

Merge branch 'ldap' into 'master'

Added LDAP fallback lookup

See merge request !2
parents 1d3db92f f1e5f239
from flask import Flask, jsonify, render_template
from peoplefinder import call_standard
from peoplefinder import call_standard, call_ldap
app = Flask(__name__)
......@@ -10,7 +10,15 @@ def base_api():
@app.route('/basic/all/<search>', defaults={'page':1})
def search_all(search, page):
return jsonify(call_standard(search, page=page))
standardResults = call_standard(search, page=page)
if len(standardResults['results']) < 1:
except Exception as e:
return res
return jsonify(standardResults)
@app.route('/basic/students/<search>', defaults={'page':1})
......@@ -20,7 +28,11 @@ def search_students(search, page):
@app.route('/basic/faculty/<search>', defaults={'page':1})
def search_faculty(search, page):
return jsonify(call_standard(search, group="students", page=page))
return jsonify(call_standard(search, group="faculty", page=page))
def search_ldap(search):
return jsonify(call_ldap(search))
if __name__ == "__main__":
import os
import re
import requests
import simpleldap
from bs4 import BeautifulSoup
......@@ -52,6 +53,23 @@ def call_standard(search, group="all", page=1):
return {
'results': people,
'hasNextPage': bool(soup.find('li', {'class': 'next'}))
'hasNextPage': bool(soup.find('li', {'class': 'next'})),
'method': 'peoplefinder'
def call_ldap(search):
conn = simpleldap.Connection('')
res = conn.get("uid=%s" % search)
return {
"results": [
"name": res['cn'][0],
"mail": res['mail'][0],
"surname": res['sn'][0],
"givenname": res['givenName'][0],
"dn": res.dn
"hasNextPage": False,
"method": "ldap"
\ No newline at end of file
Markdown is supported
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