wow
This commit is contained in:
@@ -10,7 +10,10 @@ exports.signup = (req, res) => {
|
||||
const user = new User({
|
||||
username: req.body.username,
|
||||
email: req.body.email,
|
||||
password: bcrypt.hashSync(req.body.password, 8)
|
||||
password: bcrypt.hashSync(req.body.password, 8),
|
||||
active: false,
|
||||
balance: 0,
|
||||
walletid: null
|
||||
});
|
||||
|
||||
user.save((err, user) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
exports.allAccess = (req, res) => {
|
||||
res.status(200).send("ljdp.ca");
|
||||
res.status(200).send({ message: "ljdp.ca"});
|
||||
};
|
||||
|
||||
exports.userBoard = (req, res) => {
|
||||
@@ -8,5 +8,5 @@ exports.allAccess = (req, res) => {
|
||||
};
|
||||
|
||||
exports.adminBoard = (req, res) => {
|
||||
res.status(200).send("admin");
|
||||
res.status(200).send({ message: "admin btw" });
|
||||
};
|
||||
@@ -45,7 +45,7 @@ isAdmin = (req, res, next) => {
|
||||
}
|
||||
}
|
||||
|
||||
res.status(403).send({ message: "Require Admin Role!" });
|
||||
res.status(403).send({ message: "yo t'es pas admin :(" });
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const db = require("../models");
|
||||
const dev = require("deep-email-validator");
|
||||
const ROLES = db.ROLES;
|
||||
const User = db.user;
|
||||
|
||||
@@ -51,9 +52,49 @@ checkRolesExisted = (req, res, next) => {
|
||||
next();
|
||||
};
|
||||
|
||||
validateEmail = async (req, res, next) => {
|
||||
if (req.body.email) {
|
||||
const emailRes = await dev.validate({
|
||||
email: req.body.email,
|
||||
sender: req.body.email,
|
||||
validateRegex: true,
|
||||
valideMx: true,
|
||||
validateTypo: true,
|
||||
validateDisposable: true,
|
||||
validateSMTP: false,
|
||||
})
|
||||
console.log((emailRes.valid))
|
||||
if (!emailRes.valid) {
|
||||
res.status(400).send({
|
||||
message: "oof! ton email est pas valide loco"
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
checkPassLimit = (req, res, next) => {
|
||||
if (req.body.password) {
|
||||
for (let i = 0; i < req.body.password.length; i++) {
|
||||
if (req.body.password.length <= 8) {
|
||||
res.status(400).send({
|
||||
message: "oof! ce password ne respecte pas les limitations en cours."
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
const verifySignUp = {
|
||||
checkDuplicateUsernameOrEmail,
|
||||
checkRolesExisted
|
||||
checkRolesExisted,
|
||||
validateEmail,
|
||||
checkPassLimit
|
||||
};
|
||||
|
||||
module.exports = verifySignUp;
|
||||
|
||||
@@ -6,6 +6,9 @@ const User = mongoose.model(
|
||||
username: String,
|
||||
email: String,
|
||||
password: String,
|
||||
active: Boolean,
|
||||
balance: Number,
|
||||
walletid: String,
|
||||
roles: [
|
||||
{
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
|
||||
@@ -14,7 +14,9 @@ module.exports = function(app) {
|
||||
"/api/auth/signup",
|
||||
[
|
||||
verifySignUp.checkDuplicateUsernameOrEmail,
|
||||
verifySignUp.checkRolesExisted
|
||||
verifySignUp.checkRolesExisted,
|
||||
verifySignUp.validateEmail,
|
||||
verifySignUp.checkPassLimit
|
||||
],
|
||||
controller.signup
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user