2020-01-14 20:06:25 +00:00
|
|
|
const knex = require('../data/db')
|
2020-01-14 22:22:42 +00:00
|
|
|
const { hashPassword, compareHash } = require('../services/bcrypt');
|
|
|
|
|
2020-01-13 22:47:45 +00:00
|
|
|
const signToken = require('../services/signToken');
|
2020-01-10 01:44:58 +00:00
|
|
|
|
2020-01-13 22:47:45 +00:00
|
|
|
const signUp = async (req, res, next) => {
|
|
|
|
|
|
|
|
const user = req.body;
|
|
|
|
try {
|
2020-01-14 22:22:42 +00:00
|
|
|
|
|
|
|
const hashedPassword = await hashPassword(user.password);
|
|
|
|
const secureUser = { ...user, password: hashedPassword }
|
|
|
|
|
2020-01-14 20:06:25 +00:00
|
|
|
knex('user')
|
2020-01-14 22:22:42 +00:00
|
|
|
.insert(secureUser)
|
|
|
|
.then(queryResults => {
|
|
|
|
const newUser = queryResults[0];
|
|
|
|
signToken(res, newUser);
|
|
|
|
res.send('ok').status(200);
|
|
|
|
})
|
2020-01-13 22:47:45 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
res.status(500).json(err)
|
|
|
|
}
|
2020-01-10 01:44:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const login = (req, res, next) => {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
signUp,
|
|
|
|
login
|
|
|
|
}
|