|
|
|
@ -1,7 +1,10 @@
|
|
|
|
|
import * as DataEvent from '../../utils/events/DataEvent';
|
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
const bCrypt = require('bcrypt-nodejs');
|
|
|
|
|
const jwt = require('jsonwebtoken');
|
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get Auth Status
|
|
|
|
@ -21,6 +24,34 @@ router.get('/', function(req, res) {
|
|
|
|
|
* Login Member and return token
|
|
|
|
|
*/
|
|
|
|
|
router.post('/login', function(req, res) {
|
|
|
|
|
let form = req.body;
|
|
|
|
|
fs.readJson('config/folks.json').then(folks => {
|
|
|
|
|
let found = _.find(folks, { handle: req.body.handle });
|
|
|
|
|
if (found) {
|
|
|
|
|
if (!isValidPassword(found, req.body.password)) {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: 'CHECK YOUR PASSWORD'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let token = jwt.sign({ id: found.id }, 'super-secret-string', {
|
|
|
|
|
expiresIn: 86400 // expires in 24 hours
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let session = req.session;
|
|
|
|
|
session.user = found;
|
|
|
|
|
session.token = token;
|
|
|
|
|
|
|
|
|
|
res.json({ type: DataEvent.REQUEST_GOOD, message: 'Yes', token: session.token });
|
|
|
|
|
} else {
|
|
|
|
|
res.json({
|
|
|
|
|
type: DataEvent.REQUEST_LAME,
|
|
|
|
|
message: 'MEMBER NOT FOUND'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Models.User.findOne({
|
|
|
|
|
where: {
|
|
|
|
|