Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /* ADMIN */
  2. app.get('/admin', (req, res) => {
  3. res.sendFile(path.join(__dirname + '/public/employeeLogin.html'));
  4. });
  5. //HVORFOR VIRKER DET IKKE HVA hahdahdasi
  6.  
  7. app.post('/admin', async (req, res) => {
  8. let admin = await controller.getEmployee(req.body.username);
  9. if (!admin) {
  10. return res.status(400).send({message: 'The username does not exists'});
  11. }
  12. if (!Bcrypt.compareSync(req.body.password, admin.password)) {
  13. return res.status(400).send({message: 'the password is invalid'});
  14. }
  15. else {
  16. req.session.username = req.body.username;
  17. res.send({ok: true});
  18. }
  19. });
  20.  
  21. app.get('/admin/:username', (req, res) => {
  22. const admin = req.session.username;
  23. if (admin && admin === req.params.username) {
  24. res.sendFile(__dirname + '/employee/employeeIndex.html');
  25. } else {
  26. res.redirect('/ingenAdgang.html');
  27. }
  28. });
  29.  
  30. app.get('/admin/signup/:username', async (req, res) => {
  31. const admin = await controller.getEmployee(req.session.username);
  32. if (admin && admin.username === req.params.username && admin.role === 'admin') {
  33. res.sendFile(path.join(__dirname + '/employee/signupEmployee.html'));
  34. } else {
  35. res.redirect('/ingenAdgang.html');
  36. }
  37. });
  38.  
  39. app.post('/admin/signup', async (req, res) => {
  40. try {
  41. req.body.password = Bcrypt.hashSync(req.body.password, 10);
  42. let { username, name, gender, email, phone, password, role } = req.body;
  43. let admin = await controller.createEmployee(username, name, gender, email, phone, password, role);
  44. if (admin)
  45. res.send({ok: true});
  46. else
  47. res.send({ok: false});
  48. } catch(err) {
  49. console.error('Error: ' + err);
  50. if (err.stack) console.error(err.stack);
  51. res.status(500).send(err);
  52. }
  53. });
  54.  
  55.  
  56. // let password = Bcrypt.hashSync('123', 10);
  57. // let admin = controller.createEmployee('admin', 'Admin Jensen', 'male', 'admin@mail.com', '12345678', password, 'admin');
  58. // console.log(admin);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement