Commit f1e5f239 authored by Nicholas Anderson's avatar Nicholas Anderson
Browse files

Added LDAP fallback lookup

parent 1d3db92f
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})
@app.route('/basic/all/<search>/<page>')
def search_all(search, page):
return jsonify(call_standard(search, page=page))
standardResults = call_standard(search, page=page)
if len(standardResults['results']) < 1:
try:
res=jsonify(call_ldap(search))
except Exception as e:
print(e)
return res
else:
return jsonify(standardResults)
@app.route('/basic/students/<search>', defaults={'page':1})
@app.route('/basic/students/<search>/<page>')
......@@ -20,7 +28,11 @@ def search_students(search, page):
@app.route('/basic/faculty/<search>', defaults={'page':1})
@app.route('/basic/faculty/<search>/<page>')
def search_faculty(search, page):
return jsonify(call_standard(search, group="students", page=page))
return jsonify(call_standard(search, group="faculty", page=page))
@app.route('/ldap/<search>')
def search_ldap(search):
return jsonify(call_ldap(search))
if __name__ == "__main__":
import os
......
import re
import requests
import simpleldap
from bs4 import BeautifulSoup
BASE_URL = "http://peoplefinder.gmu.edu/index.php"
......@@ -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('directory.gmu.edu')
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