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
83
84
85
86
87
|
var users = require('./controllers/users')
, system = require('./controllers/system');
/*
* ============================================================
* Routes
*
*/
module.exports = function(app, passport, auth) {
app.get('/', system.index);
app.get('/test', system.test);
app.get('/home', system.home);
app.get('/dashboard', system.dashboard);
app.get('/login', users.login);
app.post('/login', users.signin);
// GET /auth/facebook
// Use passport.authenticate() as route middleware to authenticate the
// request. The first step in Facebook authentication will involve
// redirecting the user to facebook.com. After authorization, Facebook will
// redirect the user back to this application at /auth/facebook/callback
app.get('/auth/facebook', passport.authenticate('facebook'), function(req, res){
// The request will be redirected to Facebook for authentication, so this
// function will not be called.
});
// GET /auth/facebook/callback
// Use passport.authenticate() as route middleware to authenticate the
// request. If authentication fails, the user will be redirected back to the
// login page. Otherwise, the primary route function function will be called,
// which, in this example, will redirect the user to the home page.
app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) {
console.log('/auth/facebook/callback --- ' + req.user.username);
res.redirect('/dashboard');
});
app.get('/auth/twitter', passport.authenticate('twitter', { failureRedirect: '/login' }), users.signin);
app.get('/auth/twitter/callback', passport.authenticate('twitter', { failureRedirect: '/login' }), users.authCallback);
/*
* GET logout
*
* '/logout'
*/
app.get('/logout', users.logout);
/*
* GET project page
*
* '/project'
*/
app.get('/project', system.project);
/*
* GET signup page
*
* '/signup'
*/
app.get('/signup', users.signup);
/* POST */
app.post('/signup', users.create);
};
|