action event in StudentController refactorized (new event added in events.js)

parent ba9342c1
......@@ -41,17 +41,13 @@ module.exports = {
*/
login: function (req, res) {
var bcrypt = require('bcrypt-nodejs');
console.log('1');
Student.findOne({
username: req.body.username
})
.then(function (student) {
console.log('2');
if (student) {
console.log('3');
if (bcrypt.compareSync(req.body.password, student.password)) {
student.isStudent = true;
console.log('4');
res.ok({
user: student,
token: sailsTokenAuth.issueToken(student, sails.config.jwt.expiresInMinutes),
......@@ -59,7 +55,6 @@ module.exports = {
.getTime()
});
} else {
console.log('5');
sails.log.error(`Invalid student login: user ${student.username}, password\
"${req.body.password}"`);
res.badRequest();
......@@ -1020,13 +1015,7 @@ module.exports = {
const socketToOmit = (req.isSocket) ? req.socket : undefined;
sails.hooks.events.broadcastEvent(
sails.hooks.rooms.student(attributes.id_stu),
{
name: 'action',
data: {
"action": action,
"attributes": attributes
}
},
sails.hooks.events.actionPerformed(action, attributes),
socketToOmit
);
......
......@@ -100,6 +100,23 @@ module.exports = function eventsHook(sails) {
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
}
};
}
};
};
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