app.use('/',function(req, res, next){
res.cookie('userid', '', { expires: new Date(Date.now() + 900000), httpOnly: true });
});
writeHead: [Function: writeHead],
[Symbol(outHeadersKey)]:
{ 'set-cookie':
[ 'Set-Cookie',
'userid=0.4073350528603512; Path=/; Expires=Wed, 18 Oct 2017 15:24:25 GMT; HttpOnly' ] } }
function authclients(data){
if(!data['name']) return;
if(!data['pass']) return;
sqlc.getConnection(function(error, connection) {
sqlc.query("SELECT * FROM users WHERE name = ?", [data['name']], function(err, rows, fields){
if(!rows) return;
if(rows[0]['pass'] == data['pass']){
const secret = 'abcdefg';
const hash = crypto.createHmac('sha256', secret)
.update('1234a')
.digest('hex');
cookiesid = Math.random();
sqlc.query('UPDATE users SET cookie = ?,hash = ? WHERE id = ?', [cookiesid,hash,rows[0]['id']]);
console.log('Авторизован');
}else return;
});
});
}
app.post('/post', upload.array(), function (req, res, next) {
switch(req.body['type']){
case 'auth':
authclients(req.body['data']);
break;
}
});