Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ADMIN */
- app.get('/admin', (req, res) => {
- res.sendFile(path.join(__dirname + '/public/employeeLogin.html'));
- });
- //HVORFOR VIRKER DET IKKE HVA hahdahdasi
- app.post('/admin', async (req, res) => {
- let admin = await controller.getEmployee(req.body.username);
- if (!admin) {
- return res.status(400).send({message: 'The username does not exists'});
- }
- if (!Bcrypt.compareSync(req.body.password, admin.password)) {
- return res.status(400).send({message: 'the password is invalid'});
- }
- else {
- req.session.username = req.body.username;
- res.send({ok: true});
- }
- });
- app.get('/admin/:username', (req, res) => {
- const admin = req.session.username;
- if (admin && admin === req.params.username) {
- res.sendFile(__dirname + '/employee/employeeIndex.html');
- } else {
- res.redirect('/ingenAdgang.html');
- }
- });
- app.get('/admin/signup/:username', async (req, res) => {
- const admin = await controller.getEmployee(req.session.username);
- if (admin && admin.username === req.params.username && admin.role === 'admin') {
- res.sendFile(path.join(__dirname + '/employee/signupEmployee.html'));
- } else {
- res.redirect('/ingenAdgang.html');
- }
- });
- app.post('/admin/signup', async (req, res) => {
- try {
- req.body.password = Bcrypt.hashSync(req.body.password, 10);
- let { username, name, gender, email, phone, password, role } = req.body;
- let admin = await controller.createEmployee(username, name, gender, email, phone, password, role);
- if (admin)
- res.send({ok: true});
- else
- res.send({ok: false});
- } catch(err) {
- console.error('Error: ' + err);
- if (err.stack) console.error(err.stack);
- res.status(500).send(err);
- }
- });
- // let password = Bcrypt.hashSync('123', 10);
- // let admin = controller.createEmployee('admin', 'Admin Jensen', 'male', 'admin@mail.com', '12345678', password, 'admin');
- // console.log(admin);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement