-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
82 lines (66 loc) · 1.95 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var restify = require("restify");
var authentication = require("./src/authentication.js");
var response = require("./src/response.js");
var server = restify.createServer({
name: 'orionsbeltauth',
version: '0.1.0'
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
function createContext(req, res){
console.log("creating authentication context");
return {
username : req.params.username,
email : req.params.email,
password : req.params.password,
res : res
}
}
server.post("/login", function (req, res, next) {
if( req.params == null){
return response.sendError('No parameters were supplied');
}
console.log("Checking invalid username and email");
if( req.params.username == null && req.params.email == null){
return response.sendError(res,'Username or email are required');
}
console.log("Checking invalid password");
if( req.params.password == null){
return response.sendError(res,'Password is required');
}
console.log("calling authentication::login");
authentication.login(
createContext(req,res)
);
});
server.post("/create", function (req, res, next) {
if( req.params == null){
return response.sendError(res,'No parameters were supplied');
}
console.log("calling authentication::create");
authentication.create(
createContext(req,res)
);
});
server.post("/usernameexists", function (req, res, next) {
if( req.params == null){
return response.sendError(res,'No parameters were supplied');
}
console.log("calling authentication::usernameexists");
authentication.userNameExists(
createContext(req,res)
);
});
server.post("/emailexists", function (req, res, next) {
if( req.params == null){
return response.sendError(res,'No parameters were supplied');
}
console.log("calling authentication::emailExists");
authentication.emailExists(
createContext(req,res)
);
});
server.listen(3000, function () {
console.log("Server started @ 3000");
});