mirror of
https://github.com/xfarrow/blink
synced 2025-02-19 08:30:36 +01:00
Activation completed
This commit is contained in:
parent
0626cd02c8
commit
6d79cb04d9
@ -8,6 +8,7 @@ LIMITER_MAXIMUM_PER_WINDOW = 5000 # Requests for each limiter window
|
|||||||
SMTP_USERNAME = blink@ik.me # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
SMTP_USERNAME = blink@ik.me # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
||||||
SMTP_PASSWORD = your_password # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
SMTP_PASSWORD = your_password # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
||||||
SMTP_PORT = 465 # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
SMTP_PORT = 465 # Fill only if NEEDS_EMAIL_VERIFICATION is true
|
||||||
|
FRONT_END_URL = http://localhost # Primary fron-end's root URL
|
||||||
|
|
||||||
# Database settings
|
# Database settings
|
||||||
POSTGRES_SERVER = localhost
|
POSTGRES_SERVER = localhost
|
||||||
|
@ -76,8 +76,7 @@ async function registerPerson(req, res) {
|
|||||||
req.body.qualification);
|
req.body.qualification);
|
||||||
await personModel.registerPerson(personToInsert, activationLink);
|
await personModel.registerPerson(personToInsert, activationLink);
|
||||||
if (process.env.NEEDS_EMAIL_VERIFICATION === 'true') {
|
if (process.env.NEEDS_EMAIL_VERIFICATION === 'true') {
|
||||||
// TODO generalize
|
mailUtils.sendConfirmationLink(req.body.email, activationLink);
|
||||||
mailUtils.sendConfirmationLink(req.body.email, 'http://localhost:3000/api/persons/me/activation?q=' + activationLink);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
@ -308,7 +307,7 @@ async function confirmActivation(req, res) {
|
|||||||
errors: errors.array()
|
errors: errors.array()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const personId = await activationModel.getPersonIdByIdentifier(req.query.q);
|
const personId = await activationModel.getPersonIdByIdentifier(req.body.code);
|
||||||
if (!personId) {
|
if (!personId) {
|
||||||
return res.status(401).json({
|
return res.status(401).json({
|
||||||
error: 'Activation Link either not valid or expired'
|
error: 'Activation Link either not valid or expired'
|
||||||
@ -330,7 +329,7 @@ const publicRoutes = express.Router(); // Routes not requiring token
|
|||||||
publicRoutes.post('/persons', personValidator.registerValidator, registerPerson);
|
publicRoutes.post('/persons', personValidator.registerValidator, registerPerson);
|
||||||
publicRoutes.post('/persons/me/token', personValidator.getTokenValidator, createTokenByEmailAndPassword);
|
publicRoutes.post('/persons/me/token', personValidator.getTokenValidator, createTokenByEmailAndPassword);
|
||||||
publicRoutes.get('/persons/:id/details', getPerson);
|
publicRoutes.get('/persons/:id/details', getPerson);
|
||||||
publicRoutes.get('/persons/me/activation', personValidator.confirmActivationValidator, confirmActivation);
|
publicRoutes.post('/persons/me/activation', personValidator.confirmActivationValidator, confirmActivation);
|
||||||
|
|
||||||
const protectedRoutes = express.Router(); // Routes requiring token
|
const protectedRoutes = express.Router(); // Routes requiring token
|
||||||
protectedRoutes.use(jwtUtils.verifyToken);
|
protectedRoutes.use(jwtUtils.verifyToken);
|
||||||
|
@ -9,7 +9,8 @@ let transporter = nodemailer.createTransport({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function sendConfirmationLink(destinationEmail, confirmationLink) {
|
function sendConfirmationLink(destinationEmail, code) {
|
||||||
|
const confirmationLink = `${process.env.FRONT_END_URL}/activate-account.html?q=${code}`
|
||||||
let mailOptions = {
|
let mailOptions = {
|
||||||
from: `"Blink" ${process.env.SMTP_USERNAME}`,
|
from: `"Blink" ${process.env.SMTP_USERNAME}`,
|
||||||
to: destinationEmail,
|
to: destinationEmail,
|
||||||
|
@ -66,7 +66,7 @@ const updatePersonValidator = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
const confirmActivationValidator = [
|
const confirmActivationValidator = [
|
||||||
check('q').trim().escape()
|
check('code').trim().escape()
|
||||||
]
|
]
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
51
frontend/vanilla/html/activate-account.html
Normal file
51
frontend/vanilla/html/activate-account.html
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div id="successDialog" class="alert alert-success" role="alert" style="display: none;">
|
||||||
|
<p>Your account has been activated! Welcome onboard.</p>
|
||||||
|
<p>Log in <a href="login.html">here</a></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="errorDialog" class="alert alert-danger" role="alert" style="display: none;">
|
||||||
|
URL either invalid or account already activated.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="../js/constants.js"></script>
|
||||||
|
<script>
|
||||||
|
window.addEventListener("load", async function () {
|
||||||
|
await activateAccount();
|
||||||
|
});
|
||||||
|
|
||||||
|
async function activateAccount () {
|
||||||
|
const code = new URLSearchParams(window.location.search).get('q');
|
||||||
|
if(!code){
|
||||||
|
document.getElementById('errorDialog').style.display = 'block';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const response = await fetch(`${API_URL}/persons/me/activation`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
code
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if(response.ok) {
|
||||||
|
document.getElementById('successDialog').style.display = 'block';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('errorDialog').style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user