This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
81 lines (63 loc) · 2.02 KB
/
index.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
var express = require('express'),
app = express();
var passport = require('passport')
, LocalStrategy = require('passport-local').Strategy;
//express configuration
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.session({ secret: 'HASKDJRHOQ3NRIUHWNRIUWAHNIUNAHWIEUHNAI' }));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
//passport user serializing
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(obj, done) {
done(null, obj);
});
app.set('view engine', 'ejs');
//authentication strategy set as username and password (as opposed to Fb connect, etc)
passport.use(new LocalStrategy(
function(username, password, done) {
//sample user @TODO load user from the DB
if(username == 'admin' && password == '123') {
var user = {username: username, password: password};
return done(null, user);
}
else {
return done(null, false, { message: 'Incorrect password.' });
}
}));
//signup form
app.get('/signup', function(req, res) {
res.render('signup');
});
//signup submission
app.post('/signupSubmit', function(req, res) {
//get post paramters
var userData = req.body;
//@TODO save userData in the DB
res.render('index');
});
//login form
app.get('/loginForm', function(req, res) {
res.render('index');
});
//login submission
app.post('/login',
passport.authenticate('local', { successRedirect: '/dashboard',
failureRedirect: '/loginForm'
})
);
//game dashboard..
app.get('/dashboard', function(req, res) {
res.render('loading');
});
// Include the logic for determining the winner
var logic = require('./logic.js');
// Example Calls
// console.log(logic.winnerWinnerChickenDinner("Player One", "ROCK", "Player Two", "PAPER"));
// console.log(logic.winnerWinnerChickenDinner("Player One", "scissors", "Player Two", "PAPER"));
app.listen(2013);