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
e58cd715
authored
Jun 14, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
action event in StudentController refactorized (new event added in events.js)
parent
ba9342c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
12 deletions
sails/src/api/controllers/StudentController.js
sails/src/api/hooks/events.js
sails/src/api/controllers/StudentController.js
View file @
e58cd715
...
@@ -41,17 +41,13 @@ module.exports = {
...
@@ -41,17 +41,13 @@ module.exports = {
*/
*/
login
:
function
(
req
,
res
)
{
login
:
function
(
req
,
res
)
{
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
console
.
log
(
'1'
);
Student
.
findOne
({
Student
.
findOne
({
username
:
req
.
body
.
username
username
:
req
.
body
.
username
})
})
.
then
(
function
(
student
)
{
.
then
(
function
(
student
)
{
console
.
log
(
'2'
);
if
(
student
)
{
if
(
student
)
{
console
.
log
(
'3'
);
if
(
bcrypt
.
compareSync
(
req
.
body
.
password
,
student
.
password
))
{
if
(
bcrypt
.
compareSync
(
req
.
body
.
password
,
student
.
password
))
{
student
.
isStudent
=
true
;
student
.
isStudent
=
true
;
console
.
log
(
'4'
);
res
.
ok
({
res
.
ok
({
user
:
student
,
user
:
student
,
token
:
sailsTokenAuth
.
issueToken
(
student
,
sails
.
config
.
jwt
.
expiresInMinutes
),
token
:
sailsTokenAuth
.
issueToken
(
student
,
sails
.
config
.
jwt
.
expiresInMinutes
),
...
@@ -59,7 +55,6 @@ module.exports = {
...
@@ -59,7 +55,6 @@ module.exports = {
.
getTime
()
.
getTime
()
});
});
}
else
{
}
else
{
console
.
log
(
'5'
);
sails
.
log
.
error
(
`Invalid student login: user
${
student
.
username
}
, password\
sails
.
log
.
error
(
`Invalid student login: user
${
student
.
username
}
, password\
"
${
req
.
body
.
password
}
"`
);
"
${
req
.
body
.
password
}
"`
);
res
.
badRequest
();
res
.
badRequest
();
...
@@ -1020,13 +1015,7 @@ module.exports = {
...
@@ -1020,13 +1015,7 @@ module.exports = {
const
socketToOmit
=
(
req
.
isSocket
)
?
req
.
socket
:
undefined
;
const
socketToOmit
=
(
req
.
isSocket
)
?
req
.
socket
:
undefined
;
sails
.
hooks
.
events
.
broadcastEvent
(
sails
.
hooks
.
events
.
broadcastEvent
(
sails
.
hooks
.
rooms
.
student
(
attributes
.
id_stu
),
sails
.
hooks
.
rooms
.
student
(
attributes
.
id_stu
),
{
sails
.
hooks
.
events
.
actionPerformed
(
action
,
attributes
),
name
:
'action'
,
data
:
{
"action"
:
action
,
"attributes"
:
attributes
}
},
socketToOmit
socketToOmit
);
);
...
...
sails/src/api/hooks/events.js
View file @
e58cd715
...
@@ -100,6 +100,23 @@ module.exports = function eventsHook(sails) {
...
@@ -100,6 +100,23 @@ module.exports = function eventsHook(sails) {
count
:
subscriberCount
count
:
subscriberCount
}
}
};
};
},
/**
* A new action is performed by the user in the tablet
* @param {action} type of the action
* @param {attributes} attributes of the action (e.g. picto attributes when
* clicking on it)
* @return {Object} {name, data}
*/
actionPerformed
:
function
(
action
,
attributes
)
{
return
{
name
:
'action'
,
data
:
{
action
:
action
,
attributes
:
attributes
}
};
}
}
};
};
};
};
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