-
Notifications
You must be signed in to change notification settings - Fork 22
/
routes.js
43 lines (33 loc) · 1.07 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
var passport = require('passport');
var Account = require('./models/account');
module.exports = function (app) {
app.get('/', function (req, res) {
res.render('index', { user : req.user });
});
app.get('/register', function(req, res) {
res.render('register', { });
});
app.post('/register', function(req, res) {
Account.register(new Account({ username : req.body.username }), req.body.password, function(err, account) {
if (err) {
return res.render("register", {info: "Sorry. That username already exists. Try again."});
}
passport.authenticate('local')(req, res, function () {
res.redirect('/');
});
});
});
app.get('/login', function(req, res) {
res.render('login', { user : req.user });
});
app.post('/login', passport.authenticate('local'), function(req, res) {
res.redirect('/');
});
app.get('/logout', function(req, res) {
req.logout();
res.redirect('/');
});
app.get('/ping', function(req, res){
res.send("pong!", 200);
});
};