forked from linnovate/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
98 lines (80 loc) · 2.88 KB
/
users.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
// User routes use users controller
var users = require('../controllers/users');
module.exports = function(app, passport) {
app.route('/logout')
.get(users.signout);
app.route('/users/me')
.get(users.me);
// Setting up the users api
app.route('/register')
.post(users.create);
// Setting up the userId param
app.param('userId', users.user);
// AngularJS route to check for authentication
app.route('/loggedin')
.get(function(req, res) {
res.send(req.isAuthenticated() ? req.user : '0');
});
// Setting the local strategy route
app.route('/login')
.post(passport.authenticate('local', {
failureFlash: true
}), function(req, res) {
res.send({
user: req.user,
redirect: (req.user.roles.indexOf('admin') !== -1) ? req.get('referer') : false
});
});
// Setting the facebook oauth routes
app.route('/auth/facebook')
.get(passport.authenticate('facebook', {
scope: ['email', 'user_about_me'],
failureRedirect: '#!/login'
}), users.signin);
app.route('/auth/facebook/callback')
.get(passport.authenticate('facebook', {
failureRedirect: '#!/login'
}), users.authCallback);
// Setting the github oauth routes
app.route('/auth/github')
.get(passport.authenticate('github', {
failureRedirect: '#!/login'
}), users.signin);
app.route('/auth/github/callback')
.get(passport.authenticate('github', {
failureRedirect: '#!/login'
}), users.authCallback);
// Setting the twitter oauth routes
app.route('/auth/twitter')
.get(passport.authenticate('twitter', {
failureRedirect: '#!/login'
}), users.signin);
app.route('/auth/twitter/callback')
.get(passport.authenticate('twitter', {
failureRedirect: '#!/login'
}), users.authCallback);
// Setting the google oauth routes
app.route('/auth/google')
.get(passport.authenticate('google', {
failureRedirect: '#!/login',
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
]
}), users.signin);
app.route('/auth/google/callback')
.get(passport.authenticate('google', {
failureRedirect: '#!/login'
}), users.authCallback);
// Setting the linkedin oauth routes
app.route('/auth/linkedin')
.get(passport.authenticate('linkedin', {
failureRedirect: '#!/login',
scope: ['r_emailaddress']
}), users.signin);
app.route('/auth/linkedin/callback')
.get(passport.authenticate('linkedin', {
failureRedirect: '#!/login'
}), users.authCallback);
};