Error in stu/login fixed

parent b6938fcc
...@@ -62,18 +62,18 @@ module.exports = { ...@@ -62,18 +62,18 @@ module.exports = {
student.isStudent = true; student.isStudent = true;
if (!student.license || !student.license[0]) { if (!student.license || !student.license[0]) {
sails.log.error(`Tried to login with non valid license ${req.body.username}`); sails.log.error(`Tried to login with non valid license ${req.body.username}`);
} else res.unauthorized("Student has an invalid license");
} else {
var hasExpired = student.license[0].hasExpired();
student = student.toObject(); // to enable overwrite license field student = student.toObject(); // to enable overwrite license field
student.license = student.license[0]; student.license = student.license[0];
if (student.license[0].hasExpired()) student.license.expired = hasExpired;
student.license.expired = true;
else
student.license.expired = false;
return res.ok({ return res.ok({
user: student, user: student,
token: sailsTokenAuth.issueToken(student, sails.config.jwt.expiresInMinutes), token: sailsTokenAuth.issueToken(student, sails.config.jwt.expiresInMinutes),
server_time: (new Date()).getTime() server_time: (new Date()).getTime()
}); });
}
} else { } else {
sails.log.error(`Invalid student login: user ${student.username}, password\ sails.log.error(`Invalid student login: user ${student.username}, password\
"${req.body.password}"`); "${req.body.password}"`);
...@@ -84,8 +84,8 @@ module.exports = { ...@@ -84,8 +84,8 @@ module.exports = {
res.notFound("Student not found"); res.notFound("Student not found");
} }
}) })
.catch(function () { .catch(function (err) {
sails.log.error(`Error getting student ${req.body.username} for login`); sails.log.error(`Error getting student ${req.body.username} for login: ` + err);
res.serverError("Error when connecting to database"); res.serverError("Error when connecting to database");
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment