Skip to content

Commit

Permalink
update login impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
YouQam committed Aug 5, 2022
1 parent aec1c9c commit 811c590
Show file tree
Hide file tree
Showing 3 changed files with 2,900 additions and 2,775 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"socket.io": "^2.0.4",
"underscore": "^1.12.0",
"util": "^0.12.2",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"validator": "^13.7.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
Expand Down
24 changes: 21 additions & 3 deletions src/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const passport = require("passport");
const { verifyUserRegistration } = require("./mailController");

var User = require("../models/user");
var validator = require('validator'); // To validate received email

const {
createToken,
Expand Down Expand Up @@ -165,7 +166,7 @@ module.exports.authenticate = async function authenticate(req, res, next) {
}).exec();

if (!user) {
return res.send(403, {
return res.send(401, {
code: "Unauthorized",
message: "Wrong username or password",
});
Expand All @@ -183,7 +184,7 @@ module.exports.authenticate = async function authenticate(req, res, next) {
refreshToken,
});
} else {
return res.send(403, {
return res.send(401, {
code: "Unauthorized",
message: "Wrong username or password",
});
Expand Down Expand Up @@ -311,12 +312,29 @@ module.exports.register = function register(req, res, next) {
});

//CAREFUL HARDCODED LENGTH FOR PW
if (req.body.password.length < 7) {
if (req.body.password.length < 8) {
return res.send(400, {
success: false,
msg: "Password must be at least 8 characters.",
});
}

//CAREFUL HARDCODED LENGTH FOR Username
if (req.body.username.length < 5) {
return res.send(400, {
success: false,
msg: "Username must be at least 5 characters.",
});
}

//CAREFUL HARDCODED email-validator
if (!validator.isEmail(req.body.email)) {
return res.send(400, {
success: false,
msg: "Invalid Email.",
});
}

User.addUser(newUser, async (err, user) => {
if (err) {
console.info(err);
Expand Down
Loading

0 comments on commit 811c590

Please sign in to comment.