Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6baafbf1
authored
Dec 30, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #728 closed
parent
0a4a021e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
7 deletions
sails/src/api/controllers/SupervisorController.js
sails/src/api/controllers/SupervisorController.js
View file @
6baafbf1
...
@@ -53,21 +53,28 @@ module.exports = {
...
@@ -53,21 +53,28 @@ module.exports = {
* "token": "...k3498xz...",
* "token": "...k3498xz...",
* "server_time": 1450980322069
* "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
)
{
login
:
function
(
req
,
res
)
{
var
email
=
req
.
body
.
email
;
var
email
=
req
.
body
.
email
;
var
password
=
req
.
body
.
password
;
var
password
=
req
.
body
.
password
;
if
(
!
email
||
!
password
)
if
(
!
email
||
!
password
)
return
res
.
badRequest
(
'
No email or or password
'
);
return
res
.
badRequest
(
'
Missing parameters
'
);
Supervisor
.
findOneByEmail
(
email
).
then
(
function
(
supervisor
)
{
Supervisor
.
findOneByEmail
(
email
).
then
(
function
(
supervisor
)
{
if
(
!
supervisor
)
if
(
!
supervisor
)
throw
new
Error
(
'Invalid user'
);
return
res
.
notFound
(
"Supervisor not found"
)
if
(
!
bcrypt
.
compareSync
(
password
,
supervisor
.
password
))
if
(
!
bcrypt
.
compareSync
(
password
,
supervisor
.
password
))
throw
new
Error
(
'Invalid password'
);
throw
res
.
unauthorized
(
"Invalid email/password"
)
return
(
supervisor
);
return
(
supervisor
);
...
@@ -93,9 +100,7 @@ module.exports = {
...
@@ -93,9 +100,7 @@ module.exports = {
}
}
if
(
!
supervisor
.
isSupAdmin
&&
!
stuSup
)
if
(
!
supervisor
.
isSupAdmin
&&
!
stuSup
)
throw
new
Error
(
"User without students linked to"
);
throw
res
.
unauthorized
(
"Supervisor without students"
);
return
res
.
ok
({
return
res
.
ok
({
user
:
supervisor
,
user
:
supervisor
,
...
@@ -105,7 +110,7 @@ module.exports = {
...
@@ -105,7 +110,7 @@ module.exports = {
})
})
.
catch
(
function
(
err
)
{
.
catch
(
function
(
err
)
{
return
res
.
badRequest
(
"Error in login: "
+
err
);
return
res
.
serverError
(
"Error when connecting to database"
);
});
});
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment