Error in stu/login fixed

parent b6938fcc
......@@ -62,18 +62,18 @@ module.exports = {
student.isStudent = true;
if (!student.license || !student.license[0]) {
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.license = student.license[0];
if (student.license[0].hasExpired())
student.license.expired = true;
else
student.license.expired = false;
student.license.expired = hasExpired;
return res.ok({
user: student,
token: sailsTokenAuth.issueToken(student, sails.config.jwt.expiresInMinutes),
server_time: (new Date()).getTime()
});
}
} else {
sails.log.error(`Invalid student login: user ${student.username}, password\
"${req.body.password}"`);
......@@ -84,8 +84,8 @@ module.exports = {
res.notFound("Student not found");
}
})
.catch(function () {
sails.log.error(`Error getting student ${req.body.username} for login`);
.catch(function (err) {
sails.log.error(`Error getting student ${req.body.username} for login: ` + err);
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