Added server side validation
This commit is contained in:
1 parent
a8af106606
commit
6ac5f3ab10
2 files changed
+27
-1
No files matched your search
@@ -4,6 +4,9 @@ const {
|
|||||||
loginValidation,
|
loginValidation,
|
||||||
editUserParamValidation,
|
editUserParamValidation,
|
||||||
editUserBodyValidation,
|
editUserBodyValidation,
|
||||||
|
recoveryValidation,
|
||||||
|
recoveryTokenValidation,
|
||||||
|
newPasswordValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
const logger = require("../utils/logger");
|
const logger = require("../utils/logger");
|
||||||
require("dotenv").config();
|
require("dotenv").config();
|
||||||
@@ -161,6 +164,7 @@ const userEditController = async (req, res, next) => {
|
|||||||
*/
|
*/
|
||||||
const recoveryRequestController = async (req, res, next) => {
|
const recoveryRequestController = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
await recoveryValidation.validateAsync(req.body);
|
||||||
const user = await req.db.getUserByEmail(req, res);
|
const user = await req.db.getUserByEmail(req, res);
|
||||||
if (user) {
|
if (user) {
|
||||||
const recoveryToken = await req.db.requestRecoveryToken(req, res);
|
const recoveryToken = await req.db.requestRecoveryToken(req, res);
|
||||||
@@ -194,7 +198,8 @@ const recoveryRequestController = async (req, res, next) => {
|
|||||||
*/
|
*/
|
||||||
const validateRecoveryTokenController = async (req, res, next) => {
|
const validateRecoveryTokenController = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const recoveryToken = await req.db.validateRecoveryToken(req, res);
|
await recoveryTokenValidation.validateAsync(req.body);
|
||||||
|
await req.db.validateRecoveryToken(req, res);
|
||||||
// TODO Redirect user to reset password after validating token
|
// TODO Redirect user to reset password after validating token
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@@ -219,6 +224,7 @@ const validateRecoveryTokenController = async (req, res, next) => {
|
|||||||
*/
|
*/
|
||||||
const resetPasswordController = async (req, res, next) => {
|
const resetPasswordController = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
await newPasswordValidation.validateAsync(req.body);
|
||||||
user = await req.db.resetPassword(req, res);
|
user = await req.db.resetPassword(req, res);
|
||||||
res.status(200).json({ success: true, msg: "Password reset", data: user });
|
res.status(200).json({ success: true, msg: "Password reset", data: user });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -26,6 +26,23 @@ const editUserBodyValidation = joi.object({
|
|||||||
profilePicUrl: joi.string(),
|
profilePicUrl: joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const recoveryValidation = joi.object({
|
||||||
|
email: joi
|
||||||
|
.string()
|
||||||
|
.email({ tlds: { allow: false } })
|
||||||
|
.required(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const recoveryTokenValidation = joi.object({
|
||||||
|
recoveryToken: joi.string().required(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const newPasswordValidation = joi.object({
|
||||||
|
recoveryToken: joi.string().required(),
|
||||||
|
password: joi.string().min(8).required(),
|
||||||
|
confirm: joi.string(),
|
||||||
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// Monitors
|
// Monitors
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -120,6 +137,9 @@ const deleteChecksParamValidation = joi.object({
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
loginValidation,
|
loginValidation,
|
||||||
registerValidation,
|
registerValidation,
|
||||||
|
recoveryValidation,
|
||||||
|
recoveryTokenValidation,
|
||||||
|
newPasswordValidation,
|
||||||
getMonitorByIdValidation,
|
getMonitorByIdValidation,
|
||||||
getMonitorsByUserIdValidation,
|
getMonitorsByUserIdValidation,
|
||||||
monitorValidation,
|
monitorValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user