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
b791bd7d
authored
Jun 10, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue
#438
fixed
parent
6ac4f1af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
24 deletions
sails/src/api/controllers/StudentController.js
sails/src/api/models/Student.js
sails/src/api/controllers/StudentController.js
View file @
b791bd7d
...
...
@@ -221,34 +221,30 @@ module.exports = {
// Updates student information
//
update
:
function
(
req
,
res
)
{
if
(
!
req
.
params
.
id_stu
)
{
return
res
.
json
(
500
,
{
error
:
'No student defined'
});
res
.
badRequest
();
}
Student
.
findOne
(
req
.
params
.
id_stu
)
.
exec
(
function
(
err
,
stu
)
{
var
k
;
if
(
err
||
!
stu
)
return
res
.
json
(
500
,
{
error
:
"No student found"
});
if
(
!
req
.
body
.
password
)
{
delete
req
.
body
.
password
;
}
Student
.
findOne
(
req
.
params
.
id_stu
).
then
(
function
(
stu
)
{
var
k
;
// copy attributes
for
(
k
in
req
.
body
)
stu
[
k
]
=
req
.
body
[
k
];
stu
.
save
(
function
(
stuSaveError
,
saved
)
{
if
(
stuSaveError
)
{
return
res
.
json
(
500
,
{
error
:
'Error when saving student'
});
}
return
res
.
json
(
stu
);
});
// copy attributes
for
(
k
in
req
.
body
)
stu
[
k
]
=
req
.
body
[
k
];
if
(
!
req
.
body
.
password
)
// to avoid change password when no one is provided
delete
stu
.
password
;
stu
.
save
().
then
(
function
(
saved
)
{
res
.
ok
(
stu
);
})
.
catch
(
function
(
err
)
{
res
.
severError
();
});
})
.
catch
(
function
(
err
)
{
res
.
notFound
();
});
},
...
...
sails/src/api/models/Student.js
View file @
b791bd7d
...
...
@@ -240,7 +240,10 @@ module.exports = {
beforeUpdate
:
function
(
attrs
,
next
)
{
delete
attrs
.
username
;
attrs
.
attributes
=
Student
.
getValidAttributes
(
attrs
.
attributes
);
attrs
.
password
=
bcrypt
.
hashSync
(
attrs
.
password
,
bcrypt
.
genSaltSync
());
if
(
attrs
.
password
)
{
sails
.
log
.
debug
(
'password changed'
);
attrs
.
password
=
bcrypt
.
hashSync
(
attrs
.
password
,
bcrypt
.
genSaltSync
());
}
next
();
},
...
...
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