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.get('/person/:id/details', personRoutes.getPerson);
publicRoutes.get('/organization/:id', organizationRoutes.getOrganization);
publicRoutes.get('/person/activation', personRoutes.enablePersonByActivationLink);
publicRoutes.get('/person/activation', personRoutes.confirmActivation);
const protectedRoutes = express.Router();
protectedRoutes.use(jwtUtils.verifyToken);

View File

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

View File

@ -243,16 +243,16 @@ async function deletePerson (req, res) {
*
* Required field(s): identifier
*/
async function enablePersonByActivationLink(req, res){
async function confirmActivation(req, res){
try {
const personId = await activationModel.getPersonIdByIdentifier(req.query.q);
if(!personId){
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 });
} 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' });
}
}
@ -267,5 +267,5 @@ module.exports = {
getMyself,
updatePerson,
deletePerson,
enablePersonByActivationLink
confirmActivation
};