Fixes and new endpoints
- Fixed doctor and patient PUT queries - Added patient register - Added doctor register - Added email verification check middleware - Added verified status to doctor table
This commit is contained in:
@@ -46,6 +46,18 @@ export async function verifyPermissions(userId, permissionName, permissionType)
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkIfUserEmailIsVerified(userId) {
|
||||
try {
|
||||
const [user] = await pool.execute('SELECT email_verified FROM users WHERE id = ? LIMIT 1', [userId]);
|
||||
if (user.length === 0) return false;
|
||||
return user[0].email_verified;
|
||||
}
|
||||
catch (err) {
|
||||
error(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export async function checkUserExists(req, res, next) {
|
||||
const userId = req.userId;
|
||||
if (!userExists(userId)) return await respondWithStatus(res, 404, 'User not found');
|
||||
@@ -62,4 +74,10 @@ export const checkPermissions = (permissionName, permissionType) => async (req,
|
||||
const userId = req.userId;
|
||||
if (!verifyPermissions(userId, permissionName, permissionType)) return await respondWithStatus(res, 403, 'Missing permission');
|
||||
next();
|
||||
};
|
||||
|
||||
export const checkEmailVerified = async (req, res, next) => {
|
||||
const userId = req.userId;
|
||||
if (!checkIfUserEmailIsVerified(userId)) return await respondWithStatus(res, 403, 'Email not verified');
|
||||
next();
|
||||
};
|
||||
Reference in New Issue
Block a user