-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.js
71 lines (59 loc) · 1.76 KB
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const express = require('express');
const path = require('path');
const router = express.Router();
const { authenticate } = require('../Server/utils/authMiddleware');
router.get('/login', (req, res) => {
res.render('Auth/login.html', {
process: {
env: {
HOST: process.env.HOST
}
}
});
});
router.get('/signup', (req, res) => {
res.render('Auth/signup.html', {
process: {
env: {
HOST: process.env.HOST
}
}
});
});
router.post('/logout', authenticate, (req, res) => {
authController.logout(req, res);
});
router.get('/forgot-password', (req, res) => {
res.sendFile(path.join(__dirname, '../Public/templates/Auth/ResetPassword/Submit_Email.html'));
});
router.get('/verify-otp', (req, res) => {
res.render('Utility/Verify_OTP.html', {
process: {
env: {
HOST: process.env.HOST
}
}
});
});
router.get('/reset-password', (req, res) => {
res.sendFile(path.join(__dirname, '../Public/templates/Auth/ResetPassword/Reset_Password.html'));
});
router.post('/send-signup-otp', async (req, res) => {
const { email } = req.body;
const otp = Math.floor(1000 + Math.random() * 9000);
try {
await otpModel.create({
email,
otp,
purpose: 'signup',
createdAt: new Date(),
expiresAt: new Date(Date.now() + 10 * 60 * 1000)
});
await sendEmail(email, 'StreamNet Registration OTP',
`Your OTP for registration is: ${otp}`);
res.json({ message: 'OTP sent successfully' });
} catch (err) {
res.status(500).json({ message: 'Failed to send OTP' });
}
});
module.exports = router;