-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplicit.js
More file actions
56 lines (53 loc) · 1.79 KB
/
Copy pathimplicit.js
File metadata and controls
56 lines (53 loc) · 1.79 KB
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
var passport = require('passport'),
login = require('connect-ensure-login'),
querystring = require('querystring');
exports.loginForm = function(req, res){
if(req.isAuthenticated()){
res.redirect('/account');
} else {
res.render('loginImplicit', {
clientId: req.query.client_id,
redirectUri: req.query.redirect_uri,
scope: req.query.scope
});
}
}
exports.login = function(req, res, next){
passport.authenticate('local', function(err, user, info){
//console.log(user);
if (err) { throw err;}
var urlParams = querystring.stringify({
client_id: req.body.client_id,
redirect_uri: req.body.redirect_uri,
scope: req.body.scope
});
if (!user){
res.redirect('/loginImplicit?' + urlParams);
}
req.logIn(user, function(err) {
if (err) { throw err;}
return res.redirect('/dialog/authorize?response_type=token&' + urlParams);
});
})(req, res, next);
}
exports.autologin = function(req, res, next){
var urlParams = querystring.stringify({
client_id: req.query.client_id,
redirect_uri: req.query.redirect_uri,
scope: req.query.scope
});
if(req.isAuthenticated()){
res.redirect('/dialog/authorize?response_type=token&' + urlParams);
} else {
passport.authenticate('local', function(err, user, info){
if (err) { throw err;}
if (!user) {
return res.redirect('/loginImplicit?' + urlParams);
}
req.logIn(user, function(err) {
if (err) { throw err;}
return res.redirect('/dialog/authorize?response_type=token&' + urlParams);
});
})(req, res, next);
}
}