Add password hashing to routes
This commit is contained in:
parent
5ccec5878d
commit
bf2fb47033
@ -1,10 +1,13 @@
|
||||
let express = require('express');
|
||||
let router = express.Router();
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const bcrypt = require('bcryptjs');
|
||||
|
||||
let Account = require('../models/accountModel');
|
||||
const Account = require('../models/accountModel');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
const hash = bcrypt.hashSync(data.password, 14);
|
||||
data.password = hash;
|
||||
|
||||
try {
|
||||
const [account] = await Account.addAccount(data);
|
||||
@ -18,6 +21,11 @@ router.put('/:id', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
const id = req.params.id;
|
||||
|
||||
if (data.password) {
|
||||
const hash = bcrypt.hashSync(data.password, 14);
|
||||
data.password = hash;
|
||||
}
|
||||
|
||||
try {
|
||||
const account = await Account.updateAccount(data, id);
|
||||
res.status(200).json(...account);
|
||||
|
@ -1,7 +1,7 @@
|
||||
let express = require('express');
|
||||
let router = express.Router();
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
let Availibility = require('../models/availibilityModel');
|
||||
const Availibility = require('../models/availibilityModel');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
|
@ -1,12 +1,18 @@
|
||||
let express = require('express');
|
||||
let router = express.Router();
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const bcrypt = require('bcryptjs');
|
||||
const { v4: uuidv4 } = require('uuid');
|
||||
|
||||
let Meeting = require('../models/meetingModel');
|
||||
const Meeting = require('../models/meetingModel');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
id = uuidv4();
|
||||
data = {id, ...req.body}
|
||||
data = { id, ...req.body };
|
||||
|
||||
if (data.password) {
|
||||
const hash = bcrypt.hashSync(data.password, 14);
|
||||
data.password = hash;
|
||||
}
|
||||
|
||||
try {
|
||||
const [meeting] = await Meeting.addMeeting(data);
|
||||
@ -20,11 +26,19 @@ router.put('/:id', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
const id = req.params.id;
|
||||
|
||||
if (data.password) {
|
||||
const hash = bcrypt.hashSync(data.password, 14);
|
||||
data.password = hash;
|
||||
}
|
||||
|
||||
try {
|
||||
const meeting = await Meeting.updateMeeting(data, id);
|
||||
res.status(200).json(meeting);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: `Failed to update meeting with id ${id}.`, error });
|
||||
res.status(500).json({
|
||||
message: `Failed to update meeting with id ${id}.`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -33,9 +47,14 @@ router.delete('/:id', async (req, res) => {
|
||||
|
||||
try {
|
||||
const meeting = await Meeting.deleteMeeting(id);
|
||||
res.status(200).json({message: `Meeting with id ${id} successfully deleted.`});
|
||||
res.status(200).json({
|
||||
message: `Meeting with id ${id} successfully deleted.`,
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: `Failed to delete meeting with id ${id}.`, error });
|
||||
res.status(500).json({
|
||||
message: `Failed to delete meeting with id ${id}.`,
|
||||
error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -50,7 +69,6 @@ router.get('/:id', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
router.get('/:id/participants', async (req, res) => {
|
||||
const id = req.params.id;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
let express = require('express');
|
||||
let router = express.Router();
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
let Participant = require('../models/participantModel');
|
||||
const Participant = require('../models/participantModel');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
|
@ -1,7 +1,7 @@
|
||||
let express = require('express');
|
||||
let router = express.Router();
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
let PossibleDate = require('../models/possibleDateModel');
|
||||
const PossibleDate = require('../models/possibleDateModel');
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const data = { ...req.body };
|
||||
|
Loading…
Reference in New Issue
Block a user