/
routes.js
114 lines (100 loc) · 3.24 KB
/
routes.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*!
* Module dependencies.
*/
var async = require('async')
/**
* Controllers
*/
var users = require('../app/controllers/users')
, articles = require('../app/controllers/articles')
, auth = require('./middlewares/authorization')
/**
* Route middlewares
*/
var articleAuth = [auth.requiresLogin, auth.article.hasAuthorization]
var commentAuth = [auth.requiresLogin, auth.comment.hasAuthorization]
/**
* Expose routes
*/
module.exports = function (app, passport) {
// user routes
app.get('/login', users.login)
app.get('/signup', users.signup)
app.get('/logout', users.logout)
app.post('/users', users.create)
app.post('/users/session',
passport.authenticate('local', {
failureRedirect: '/login',
failureFlash: 'Invalid email or password.'
}), users.session)
app.get('/users/:userId', users.show)
app.get('/auth/facebook',
passport.authenticate('facebook', {
scope: [ 'email', 'user_about_me'],
failureRedirect: '/login'
}), users.signin)
app.get('/auth/facebook/callback',
passport.authenticate('facebook', {
failureRedirect: '/login'
}), users.authCallback)
app.get('/auth/github',
passport.authenticate('github', {
failureRedirect: '/login'
}), users.signin)
app.get('/auth/github/callback',
passport.authenticate('github', {
failureRedirect: '/login'
}), users.authCallback)
app.get('/auth/twitter',
passport.authenticate('twitter', {
failureRedirect: '/login'
}), users.signin)
app.get('/auth/twitter/callback',
passport.authenticate('twitter', {
failureRedirect: '/login'
}), users.authCallback)
app.get('/auth/google',
passport.authenticate('google', {
failureRedirect: '/login',
scope: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email'
]
}), users.signin)
app.get('/auth/google/callback',
passport.authenticate('google', {
failureRedirect: '/login'
}), users.authCallback)
app.get('/auth/linkedin',
passport.authenticate('linkedin', {
failureRedirect: '/login',
scope: [
'r_emailaddress'
]
}), users.signin)
app.get('/auth/linkedin/callback',
passport.authenticate('linkedin', {
failureRedirect: '/login'
}), users.authCallback)
app.param('userId', users.user)
// article routes
app.param('id', articles.load)
app.get('/articles', articles.index)
app.get('/articles/new', auth.requiresLogin, articles.new)
app.post('/articles', auth.requiresLogin, articles.create)
app.get('/articles/:id', articles.show)
app.get('/articles/:id/edit', articleAuth, articles.edit)
app.put('/articles/:id', articleAuth, articles.update)
app.del('/articles/:id', articleAuth, articles.destroy)
// home route
app.get('/', articles.index)
// comment routes
var comments = require('../app/controllers/comments')
app.param('commentId', comments.load)
app.post('/articles/:id/comments', auth.requiresLogin, comments.create)
app.get('/articles/:id/comments', auth.requiresLogin, comments.create)
app.del('/articles/:id/comments/:commentId', commentAuth, comments.destroy)
// tag routes
var tags = require('../app/controllers/tags')
app.get('/tags/:tag', tags.index)
}