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
ff51658d
authored
May 23, 2016
by
Pablo Molina
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Añadida comprobación de los valores de meta_stu en la creación de un estudiante
parent
16ef6ddc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
56 deletions
sails/src/api/models/Student.js
sails/src/api/models/Student.js
View file @
ff51658d
/* global sails */
/* global sails, MetaStu */
const
bcrypt
=
require
(
'bcrypt-nodejs'
)
/**
* student.js
...
...
@@ -95,67 +97,51 @@ module.exports = {
collection
:
"StuPicto"
,
via
:
"student"
},
toJSON
:
function
()
{
var
student
=
this
.
toObject
();
student
.
pic
=
sails
.
config
.
pictogram
.
urls
.
getStudentAvatarUrl
(
student
.
pic
);
delete
student
.
password
;
return
student
;
},
},
toJSON
:
function
()
{
var
student
=
this
.
toObject
();
student
.
pic
=
sails
.
config
.
pictogram
.
urls
.
getStudentAvatarUrl
(
student
.
pic
);
delete
student
.
password
;
return
student
;
},
//
// Model hook for storing default configuration adding a new account
//
beforeCreate
:
function
(
attrs
,
next
)
{
MetaStu
.
find
().
exec
(
function
(
err
,
metaStu
)
{
/**
* Checks the given attributes before creating a new Student
* @param {Object} attrs All student properties to be stored
* @param {Function} next Function to be executed when the check process
* has been completed (an error object will be passed
* to the function if necesary)
*/
beforeCreate
:
function
(
attrs
,
next
)
{
MetaStu
.
find
().
then
(
function
(
metaAttributes
)
{
var
attributeValue
;
var
attributeDomains
=
{};
var
validAttributes
=
{};
metaAttributes
.
forEach
((
metaAttribute
)
=>
{
validAttributes
[
metaAttribute
.
name
]
=
metaAttribute
.
default_val
;
attributeDomains
[
metaAttribute
.
name
]
=
metaAttribute
.
domain
.
split
(
','
);
});
if
(
err
||
!
metaStu
||
metaStu
.
length
==
0
)
return
next
(
err
);
/* Default Configuration:
var configuration = {
"categories":"on",
"input_feedback":{"vibration":true,"click":false,"read":false,"highlight":false},
"input_selection":"drag",
"pictogram_size":"normal",
"tts_engine":"IVONA Text-to-Speech HQ",
"tts_voice":"child", -- NO USADO
"picto_select":"enlarge", -- NO USADO
"legend":"yes",
"legendsize":"50",
"animation":"yes", -- NO USADO
"tts_options":{phrase":true},
"picto_background":"#000000",
"phrase_background":"#ff0000"};
*/
var
configuration
=
[];
// The default configuration is built by meta_stu fields and its default values
for
(
var
i
=
0
;
i
<
metaStu
.
length
;
i
++
)
{
configuration
.
push
(
'"'
+
metaStu
[
i
].
name
+
'":'
+
metaStu
[
i
].
default_val
);
attrs
.
attributes
.
keys
().
forEach
((
attributeKey
)
=>
{
attributeValue
=
attrs
.
attributes
[
attributeKey
];
if
(
attributeDomains
[
attributeKey
]
&&
attributeDomains
[
attributeKey
].
indexOf
(
attributeValue
)
!==
-
1
)
{
validAttributes
[
attributeKey
]
=
attributeValue
;
}
else
{
sails
.
log
.
error
(
`Received invalid attribute \
${
attributeKey
}
with value "
${
attributeValue
}
`
);
}
attrs
.
attributes
=
JSON
.
parse
(
"{"
+
configuration
.
toString
()
+
"}"
);
//attrs.attributes = "{" + configuration.toString() + "}";
//console.log(attrs.attributes);
//
// Encrypt password before insertion
//
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
bcrypt
.
genSalt
(
10
,
function
(
err
,
salt
)
{
if
(
err
)
return
next
(
err
);
bcrypt
.
hash
(
attrs
.
password
,
salt
,
null
,
function
(
err
,
hash
)
{
if
(
err
)
return
next
(
err
);
attrs
.
password
=
hash
;
next
();
});
});
attrs
.
password
=
bcrypt
.
hashSync
(
attrs
.
password
,
bcrypt
.
genSaltSync
());
}).
catch
((
error
)
=>
{
if
(
error
)
{
next
(
error
);
}
else
{
next
(
new
Error
());
}
});
},
...
...
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