Skip to content

Commit

Permalink
Merge pull request #79 from VRI-UFPR/77-feat-management-of-user-accep…
Browse files Browse the repository at this point in the history
…tance-of-terms-of-use

#77 [FEAT]: Management of user acceptance of terms of use
  • Loading branch information
IosBonaldi authored May 2, 2024
2 parents 877cfcb + 54df6aa commit 14a6f2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/controllers/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const signIn = async (req: Request, res: Response) => {

res.status(200).json({
message: 'User signed in.',
data: { id: user.id, token: token, expiresIn: ms(process.env.JWT_EXPIRATION as string) },
data: { id: user.id, acceptedTerms: user.acceptedTerms, token: token, expiresIn: ms(process.env.JWT_EXPIRATION as string) },
});
} catch (error: any) {
res.status(400).json(errorFormatter(error));
Expand Down Expand Up @@ -131,3 +131,26 @@ export const checkSignIn = async (req: Request, res: Response) => {
res.status(400).json(errorFormatter(error));
}
};

export const acceptTerms = async (req: Request, res: Response) => {
try {
const user = req.user as User;

if (user.id === 1) {
throw new Error('Cannot accept terms as anonymous user.');
}

const updatedUser = await prismaClient.user.update({
where: {
id: user.id,
},
data: {
acceptedTerms: true,
},
});

res.status(200).json({ message: 'Terms accepted.', data: { id: updatedUser.id, acceptedTerms: updatedUser.acceptedTerms } });
} catch (error) {
res.status(400).json(errorFormatter(error));
}
};
4 changes: 3 additions & 1 deletion src/routes/authRoutes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import express from 'express';
import uploader from '../services/multerUploader';
import passport from '../services/passportAuth';
import { signIn, signUp, renewSignIn, checkSignIn, passwordlessSignIn } from '../controllers/authController';
import { signIn, signUp, renewSignIn, checkSignIn, passwordlessSignIn, acceptTerms } from '../controllers/authController';

/**
* @swagger
Expand Down Expand Up @@ -155,4 +155,6 @@ router.post('/renewSignIn', passport.authenticate('jwt', { session: false }), up

router.get('/checkSignIn', passport.authenticate('jwt', { session: false }), uploader.none(), checkSignIn);

router.get('/acceptTerms', passport.authenticate('jwt', { session: false }), uploader.none(), acceptTerms);

export default router;

0 comments on commit 14a6f2f

Please sign in to comment.