activation link function update

This commit is contained in:
xfarrow 2024-03-04 15:50:14 +01:00
parent 5ef0317833
commit 797a69fe34
3 changed files with 15 additions and 8 deletions

View File

@ -56,7 +56,7 @@ publicRoutes.post('/register', personRoutes.registerPerson);
publicRoutes.post('/login', personRoutes.login); publicRoutes.post('/login', personRoutes.login);
publicRoutes.get('/person/:id/details', personRoutes.getPerson); publicRoutes.get('/person/:id/details', personRoutes.getPerson);
publicRoutes.get('/organization/:id', organizationRoutes.getOrganization); publicRoutes.get('/organization/:id', organizationRoutes.getOrganization);
publicRoutes.get('/person/activation', personRoutes.enablePersonByActivationLink); publicRoutes.get('/person/activation', personRoutes.confirmActivation);
const protectedRoutes = express.Router(); const protectedRoutes = express.Router();
protectedRoutes.use(jwtUtils.verifyToken); protectedRoutes.use(jwtUtils.verifyToken);

View File

@ -128,10 +128,17 @@ async function deletePerson (personId) {
.del(); .del();
} }
async function enablePerson (personId) { async function confirmActivation (personId) {
await knex('Person') await knex.transaction(async (tr) => {
await knex('Person')
.where('id', personId) .where('id', personId)
.update({enabled: true}); .update({enabled: true});
await tr('ActivationLink')
.where('person_id', personId)
.del();
});
} }
// Exporting a function // Exporting a function
@ -145,5 +152,5 @@ module.exports = {
registerPerson, registerPerson,
updatePerson, updatePerson,
deletePerson, deletePerson,
enablePerson confirmActivation
}; };

View File

@ -243,16 +243,16 @@ async function deletePerson (req, res) {
* *
* Required field(s): identifier * Required field(s): identifier
*/ */
async function enablePersonByActivationLink(req, res){ async function confirmActivation(req, res){
try { try {
const personId = await activationModel.getPersonIdByIdentifier(req.query.q); const personId = await activationModel.getPersonIdByIdentifier(req.query.q);
if(!personId){ if(!personId){
return res.status(401).json({error: 'Activation Link either not valid or expired'}); return res.status(401).json({error: 'Activation Link either not valid or expired'});
} }
await personModel.enablePerson(personId); await personModel.confirmActivation(personId);
return res.status(200).json({ success: true }); return res.status(200).json({ success: true });
} catch (error) { } catch (error) {
console.error(`Error in function ${enablePersonByActivationLink.name}: ${error}`); console.error(`Error in function ${confirmActivation.name}: ${error}`);
return res.status(500).json({ error: 'Internal server error' }); return res.status(500).json({ error: 'Internal server error' });
} }
} }
@ -267,5 +267,5 @@ module.exports = {
getMyself, getMyself,
updatePerson, updatePerson,
deletePerson, deletePerson,
enablePersonByActivationLink confirmActivation
}; };