Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardxia committed Nov 7, 2015
0 parents commit d6aa62a
Show file tree
Hide file tree
Showing 28 changed files with 1,555 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
#Pods/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "Frameworks/AFNetworking"]
path = Frameworks/AFNetworking
url = https://github.com/AFNetworking/AFNetworking.git
1 change: 1 addition & 0 deletions Frameworks/AFNetworking
Submodule AFNetworking added at 743953
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 UCI ICS Student Council

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# UCI-Directory

Demo app used in iOS Workshop on Nov 6, 2015
1 change: 1 addition & 0 deletions Server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
20 changes: 20 additions & 0 deletions Server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "uci_directory",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"ldapjs": "^1.0.0"
},
"dependencies": {
"ldapjs": "latest"
},
"devDependencies": {
"coffee-script": "latest"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT"
}
27 changes: 27 additions & 0 deletions Server/server.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
http = require 'http'
url = require 'url'
querystring = require 'querystring'
directory = require "./uci_directory.coffee"

http.createServer (req, res) ->
_url = url.parse req.url
if match = _url.pathname.match /^\/(.*).json$/i
endpoint = match[1].toLowerCase()
if directory[endpoint]
query = querystring.parse _url.query
console.log "#{endpoint}: #{query.query}"
directory[endpoint] query.query, (entry) ->
if entry
res.writeHead 200, "Content-Type": "application/json"
res.end JSON.stringify
query: query.query
data: entry
else
res.writeHead 404, "Content-Type": "application/json"
res.end JSON.stringify error: "not found"

else
res.writeHead 502, "Content-Type": "application/json"
res.end JSON.stringify error: "wrong API format"
.listen 1337

59 changes: 59 additions & 0 deletions Server/uci_directory.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
ldap = require "ldapjs"

url = "ldap://ldap.service.uci.edu"

base = "ou=University of California Irvine,o=University of California, c=US"

complete = (uid, callback) ->
if uid.replace(/\s/g, "").match /[\W_]/
callback []
else
client = ldap.createClient
url: url

options =
scope: "sub"
filter: "(|(uid=#{uid}*)(displayName=#{uid}*))"
sizeLimit: 20

client.search base, options, (err, res) ->
if err
callback []
else
entries = []

res.on 'searchEntry', (entry) ->
entry.object.uid = entry.object.uid.toLowerCase()
entries.push entry.object
res.on 'error', (err) ->
if (err || {}).name is 'SizeLimitExceededError'
callback entries
else
callback []
res.on 'end', (result) ->
callback entries

lookup = (uid, callback) ->
if uid.match /[\W_]/
callback null
else
client = ldap.createClient
url: url
options =
scope: "sub"
filter: "(uid=#{uid})"

client.search base, options, (err, res) ->
entry = null
if err
callback entry
else
res.on 'searchEntry', (entry) ->
callback entry.object
res.on 'error', (err) ->
callback entry
res.on 'end', (status) ->
callback entry unless entry


module.exports = {complete, lookup}
Loading

0 comments on commit d6aa62a

Please sign in to comment.