· 9 years ago · Jun 22, 2016, 10:21 PM
1var session = require('express-session');
2var FileStore = require('session-file-store')(session);
3
4var sess_options = {
5 path: "./tmp/sessions/",
6 useAsync: true,
7 reapInterval: 5000,
8 maxAge: 1000*60*60*24*30*12
9};
10
11app.use(session({
12 store: new FileStore(sess_options),
13 secret: 'secret_key',
14 name: 'connect.sid',
15 resave : true,
16 saveUninitialized : false,
17 cookie: {
18 domain : 'example.com',
19 maxAge : 1000*60*60*24*30*12
20 }
21}));
22
23router.post('/login', function(req,res,next){
24var sess = req.session;
25
26var username = req.body.username;
27var password = req.body.password;
28var hash = crypto.createHash('sha256').update(password).digest('hex');
29console.log("Password Hash ", hash);
30connection.query('SELECT * FROM users WHERE username=? AND password=?',[username,hash], function (error,results,fields){
31 console.log("Results: "+results);
32 if(results.length > 0)
33 {
34 req.session.username = results[0].username;
35 req.session.profile = results[0].profile;
36 req.session.organization = results[0].organization;
37 req.session.branch = results[0].branch;
38 req.session.name = results[0].name;
39
40 res.send("1");
41 } else
42 {
43 res.send("No match");
44 }
45});
46
47});
48
49router.get('/logout', function(req,res,next){
50res.clearCookie('connect.sid');
51
52req.session.destroy(function(err) {
53
54 });
55
56
57res.send("1");
58});
59
60[0mOPTIONS /account/login [32m200 [0m43.349 ms - 4[0m
61Results: [object Object]
62[0mPOST /account/login [32m200 [0m135.829 ms - 1[0m
63error: restarting script because add changed
64error: Forever detected script was killed by signal: SIGKILL
65error: Script restart attempt #11
66connected as id 427
67error: restarting script because add changed
68error: Forever detected script was killed by signal: SIGKILL
69error: Script restart attempt #12
70connected as id 428
71[0mGET /account/logout [32m200 [0m79.119 ms - 1[0m
72error: restarting script because unlink changed
73error: Forever detected script was killed by signal: SIGKILL
74error: Script restart attempt #13
75connected as id 429
76[0mOPTIONS /account/login [32m200 [0m40.363 ms - 4[0m
77[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
78[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
79[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
80[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
81[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
82Results: [object Object]
83error: restarting script because add changed
84error: Forever detected script was killed by signal: SIGKILL
85error: Script restart attempt #14
86connected as id 430
87[0mOPTIONS /account/login [32m200 [0m31.751 ms - 4[0m
88[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
89[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
90[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
91[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
92[session-file-store] will retry, error on last attempt: Error: ENOENT: no such file or directory, open 'tmp/sessions/LVjEYmzL3nARlBgqM6Sqy_q0dUYmYAYK.json'
93Results: [object Object]
94error: restarting script because add changed
95error: Forever detected script was killed by signal: SIGKILL
96error: Script restart attempt #15
97connected as id 431