issue #728 closed

parent 0a4a021e
......@@ -53,21 +53,28 @@ module.exports = {
* "token": "...k3498xz...",
* "server_time": 1450980322069
* }
*
* @param {response} Errors:
* - 400 (Bad request) with error message "Missing parameters"
* - 401 (Unauthorized) with error message "Invalid email/password"
* - 404 (Not found) with error message "Supervisor not found"
* - 401 (Unauthorized) with error message "Supervisor without students"
* - 500 (Server error) with error message "Error when connecting to database"
*/
login: function (req, res) {
var email = req.body.email;
var password = req.body.password;
if (!email || !password)
return res.badRequest('No email or or password');
return res.badRequest('Missing parameters');
Supervisor.findOneByEmail(email).then(function (supervisor) {
if (!supervisor)
throw new Error('Invalid user');
return res.notFound("Supervisor not found")
if (!bcrypt.compareSync(password, supervisor.password))
throw new Error('Invalid password');
throw res.unauthorized("Invalid email/password")
return (supervisor);
......@@ -93,9 +100,7 @@ module.exports = {
}
if (!supervisor.isSupAdmin && !stuSup)
throw new Error("User without students linked to");
throw res.unauthorized("Supervisor without students");
return res.ok({
user: supervisor,
......@@ -105,7 +110,7 @@ module.exports = {
})
.catch(function (err) {
return res.badRequest("Error in login: " + err);
return 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