$scope.referentials = Referential.query();
// Récupération de l'utilisateur actuel
- $scope.currentUser = Auth.getCurrentUser();
+ $scope.currentUser = angular.copy(Auth.getCurrentUser());
+ $scope.isAdmin = Auth.isAdmin();
$scope.errors = {};
}
};
+ var updateMe = function (params, cb, errorCb) {
+ Auth.updateMe(params)
+ .then(function () {
+ if (typeof cb === 'function') {
+ cb();
+ }
+ })
+ .catch(function (e) {
+ if (typeof errorCb === 'function') {
+ errorCb(e);
+ }
+ });
+ };
+
$scope.confirm = function (e) {
- $modalInstance.close(e);
+ updateMe($scope.currentUser, function () {
+ angular.copy($scope.currentUser, Auth.getCurrentUser());
+ $modalInstance.close(e);
+ });
};
$scope.cancel = function (e) {
block content
.row
.col-sm-12
- .col-sm-6
+ div(ng-class="isAdmin ? 'col-sm-12' : 'col-sm-6'")
h3 Changement de mot de passe
hr
.col-sm-12
p.help-block {{ message }}
button.btn.btn-primary(type='submit', ng-click="changePassword(modalForm)") Modifier
- .col-sm-6
+ .col-sm-6(ng-if="!isAdmin")
h3 Référentiel de vérification
hr
.col-sm-12
ref-setter(ng-model="currentUser.referential", referentials="referentials")
block footer
- button.btn.btn-success(ng-click='confirm($event)') Valider
- button.btn.btn-default(ng-click='cancel($event)') Annuler
+ div(ng-if="!isAdmin")
+ button.btn.btn-success(ng-click='confirm($event)') Valider
+ button.btn.btn-default(ng-click='cancel($event)') Annuler
+ button.btn.btn-default(ng-click='cancel($event)', ng-if="isAdmin") Fermer
'use strict';
angular.module('liberValidApp')
- .controller('ModalUserCtrl', function ($scope, $modalInstance, User, Referential) {
+ .controller('ModalUserCtrl', function ($scope, $modalInstance, User, Referential, Auth) {
// Récupération des référentiels
$scope.referentials = Referential.query();
$scope.args[0] = $scope.args[0] || new User();
$scope.isNew = !$scope.args[0]._id;
+ if (!$scope.args[0].referential) {
+ $scope.args[0].referential = {};
+ }
+
$scope.confirm = function (e) {
// Angular.copy avec cible, afin de garder la référence à l'objet
angular.copy($scope.user, $scope.args[0]);
+ // Mise à jour de l'utilisateur actuel si édité !
+ if (Auth.getCurrentUser()._id === $scope.args[0]._id) {
+ angular.copy($scope.user, Auth.getCurrentUser());
+ }
$modalInstance.close(e);
};
'use strict';
angular.module('liberValidApp')
- .controller('UsersCtrl', function ($scope, $http, Auth, User, Modal) {
+ .controller('UsersCtrl', function ($scope, $http, Auth, User, Modal, socket) {
- $scope.getCurrentUser = Auth.getCurrentUser;
+ $scope.getCurrentUser = Auth.getCurrentUser;
- var listUsers = function() {
- // Use the User $resource to fetch all users
- $scope.users = User.query();
- };
+ var listUsers = function () {
+ // Use the User $resource to fetch all users
+ $scope.users = User.query();
+ };
- $scope.modifyUser = function(user) {
- Modal.openModal(function(updated) {
- // User updated
- updated.$save();
- }, 'app/admin/users/modalUser/modalUser.html', 'ModalUserCtrl', 'modal-info')(user);
- };
+ $scope.modifyUser = function (user) {
+ Modal.openModal(function (updated) {
+ // User updated
+ updated.$save();
+ }, 'app/admin/users/modalUser/modalUser.html', 'ModalUserCtrl', 'modal-info')(user);
+ };
- $scope.createUser = function() {
- Modal.openModal(function(updated) {
- // User updated
- updated.$save(function() {
- listUsers();
- });
- }, 'app/admin/users/modalUser/modalUser.html', 'ModalUserCtrl', 'modal-success')();
- };
+ $scope.createUser = function () {
+ Modal.openModal(function (updated) {
+ // User updated
+ updated.$save(function () {
+ listUsers();
+ });
+ }, 'app/admin/users/modalUser/modalUser.html', 'ModalUserCtrl', 'modal-success')();
+ };
- $scope.delete = function(user) {
- Modal.confirm.delete('l\'utilisateur ' + user.name, function() {
- User.remove({ id: user._id });
- angular.forEach($scope.users, function(u, i) {
- if (u === user) {
- $scope.users.splice(i, 1);
- }
- });
- })();
- };
+ $scope.delete = function (user) {
+ Modal.confirm.delete('l\'utilisateur ' + user.name, function () {
+ User.remove({id: user._id});
+ angular.forEach($scope.users, function (u, i) {
+ if (u === user) {
+ $scope.users.splice(i, 1);
+ }
+ });
+ })();
+ };
- listUsers();
- });
+ listUsers();
+ });
'use strict';
angular.module('liberValidApp')
- .factory('Auth', function Auth($location, $rootScope, $http, User, $cookieStore, $q) {
- var currentUser = {};
- if($cookieStore.get('token')) {
- currentUser = User.get();
- }
-
- return {
-
- /**
- * Authenticate user and save token
- *
- * @param {Object} user - login info
- * @param {Function} callback - optional
- * @return {Promise}
- */
- login: function(user, callback) {
- var cb = callback || angular.noop;
- var deferred = $q.defer();
-
- $http.post('/auth/local', {
- email: user.email,
- password: user.password
- }).
- success(function(data) {
- $cookieStore.put('token', data.token);
- currentUser = User.get();
- deferred.resolve(data);
- return cb();
- }).
- error(function(err) {
- this.logout();
- deferred.reject(err);
- return cb(err);
- }.bind(this));
-
- return deferred.promise;
- },
-
- /**
- * Delete access token and user info
- */
- logout: function() {
- $cookieStore.remove('token');
- currentUser = {};
- },
-
- /**
- * Create a new user
- *
- * @param {Object} user - user info
- * @param {Function} callback - optional
- * @return {Promise}
- */
- createUser: function(user, callback) {
- var cb = callback || angular.noop;
-
- return User.save(user,
- function(data) {
- $cookieStore.put('token', data.token);
+ .factory('Auth', function Auth($location, $rootScope, $http, User, $cookieStore, $q) {
+ var currentUser = {};
+ if ($cookieStore.get('token')) {
currentUser = User.get();
- return cb(user);
- },
- function(err) {
- this.logout();
- return cb(err);
- }.bind(this)).$promise;
- },
-
- /**
- * Change password
- *
- * @param {String} oldPassword
- * @param {String} newPassword
- * @param {Function} callback - optional
- * @return {Promise}
- */
- changePassword: function(oldPassword, newPassword, callback) {
- var cb = callback || angular.noop;
-
- return User.changePassword({ id: currentUser._id }, {
- oldPassword: oldPassword,
- newPassword: newPassword
- }, function(user) {
- return cb(user);
- }, function(err) {
- return cb(err);
- }).$promise;
- },
-
- /**
- * Gets all available info on authenticated user
- *
- * @return {Object} user
- */
- getCurrentUser: function() {
- return currentUser;
- },
-
- /**
- * Check if a user is logged in
- *
- * @return {Boolean}
- */
- isLoggedIn: function() {
- return currentUser.hasOwnProperty('role');
- },
-
- /**
- * Waits for currentUser to resolve before checking if user is logged in
- */
- isLoggedInAsync: function(cb) {
- if(currentUser.hasOwnProperty('$promise')) {
- currentUser.$promise.then(function() {
- cb(true);
- }).catch(function() {
- cb(false);
- });
- } else if(currentUser.hasOwnProperty('role')) {
- cb(true);
- } else {
- cb(false);
}
- },
-
- /**
- * Check if a user is an admin
- *
- * @return {Boolean}
- */
- isAdmin: function() {
- return currentUser.role === 'admin';
- },
-
- /**
- * Get auth token
- */
- getToken: function() {
- return $cookieStore.get('token');
- }
- };
- });
+
+ return {
+
+ /**
+ * Authenticate user and save token
+ *
+ * @param {Object} user - login info
+ * @param {Function} callback - optional
+ * @return {Promise}
+ */
+ login: function (user, callback) {
+ var cb = callback || angular.noop;
+ var deferred = $q.defer();
+
+ $http.post('/auth/local', {
+ email: user.email,
+ password: user.password
+ }).
+ success(function (data) {
+ $cookieStore.put('token', data.token);
+ currentUser = User.get();
+ deferred.resolve(data);
+ return cb();
+ }).
+ error(function (err) {
+ this.logout();
+ deferred.reject(err);
+ return cb(err);
+ }.bind(this));
+
+ return deferred.promise;
+ },
+
+ /**
+ * Delete access token and user info
+ */
+ logout: function () {
+ $cookieStore.remove('token');
+ currentUser = {};
+ },
+
+ /**
+ * Create a new user
+ *
+ * @param {Object} user - user info
+ * @param {Function} callback - optional
+ * @return {Promise}
+ */
+ createUser: function (user, callback) {
+ var cb = callback || angular.noop;
+
+ return User.save(user,
+ function (data) {
+ $cookieStore.put('token', data.token);
+ currentUser = User.get();
+ return cb(user);
+ },
+ function (err) {
+ this.logout();
+ return cb(err);
+ }.bind(this)).$promise;
+ },
+
+ /**
+ * Change password
+ *
+ * @param {String} oldPassword
+ * @param {String} newPassword
+ * @param {Function} callback - optional
+ * @return {Promise}
+ */
+ changePassword: function (oldPassword, newPassword, callback) {
+ var cb = callback || angular.noop;
+
+ return User.changePassword({id: currentUser._id}, {
+ oldPassword: oldPassword,
+ newPassword: newPassword
+ }, function (user) {
+ return cb(user);
+ }, function (err) {
+ return cb(err);
+ }).$promise;
+ },
+
+ /**
+ * Change user parameter
+ *
+ * @param {Object} params
+ * @param {Function} callback - optional
+ * @return {Promise}
+ */
+ updateMe: function (params, callback) {
+ var cb = callback || angular.noop;
+
+ return User.updateMe(params, function (user) {
+ return cb(user);
+ }, function (err) {
+ return cb(err);
+ }).$promise;
+ },
+
+
+ /**
+ * Gets all available info on authenticated user
+ *
+ * @return {Object} user
+ */
+ getCurrentUser: function () {
+ return currentUser;
+ },
+
+ /**
+ * Check if a user is logged in
+ *
+ * @return {Boolean}
+ */
+ isLoggedIn: function () {
+ return currentUser.hasOwnProperty('role');
+ },
+
+ /**
+ * Waits for currentUser to resolve before checking if user is logged in
+ */
+ isLoggedInAsync: function (cb) {
+ if (currentUser.hasOwnProperty('$promise')) {
+ currentUser.$promise.then(function () {
+ cb(true);
+ }).catch(function () {
+ cb(false);
+ });
+ } else if (currentUser.hasOwnProperty('role')) {
+ cb(true);
+ } else {
+ cb(false);
+ }
+ },
+
+ /**
+ * Check if a user is an admin
+ *
+ * @return {Boolean}
+ */
+ isAdmin: function () {
+ return currentUser.role === 'admin';
+ },
+
+ /**
+ * Get auth token
+ */
+ getToken: function () {
+ return $cookieStore.get('token');
+ }
+ };
+ });
'use strict';
angular.module('liberValidApp')
- .factory('User', function ($resource) {
- return $resource('/api/users/:id/:controller', {
- id: '@_id'
- },
- {
- changePassword: {
- method: 'PUT',
- params: {
- controller:'password'
- }
- },
- get: {
- method: 'GET',
- params: {
- id:'me'
- }
- }
- });
- });
+ .factory('User', function ($resource) {
+ return $resource('/api/users/:id/:controller', {
+ id: '@_id'
+ },
+ {
+ changePassword: {
+ method: 'PUT',
+ params: {
+ controller: 'password'
+ }
+ },
+ updateMe: {
+ method: 'PUT',
+ params: {
+ id: 'me'
+ }
+ },
+ get: {
+ method: 'GET',
+ params: {
+ id: 'me'
+ }
+ }
+ });
+ });
'use strict';
angular.module('liberValidApp')
- .factory('socket', function(socketFactory) {
+ .factory('socket', function (socketFactory) {
- // socket.io now auto-configures its connection when we ommit a connection url
- var ioSocket = io('', {
- // Send auth token on connection, you will need to DI the Auth service above
- // 'query': 'token=' + Auth.getToken()
- path: '/socket.io-client'
- });
+ // socket.io now auto-configures its connection when we ommit a connection url
+ var ioSocket = io('', {
+ // Send auth token on connection, you will need to DI the Auth service above
+ // 'query': 'token=' + Auth.getToken()
+ path: '/socket.io-client'
+ });
- var socket = socketFactory({
- ioSocket: ioSocket
- });
+ var socket = socketFactory({
+ ioSocket: ioSocket
+ });
- return {
- socket: socket,
+ return {
+ socket: socket,
- /**
- * Register listeners to sync an array with updates on a model
- *
- * Takes the array we want to sync, the model name that socket updates are sent from,
- * and an optional callback function after new items are updated.
- *
- * @param {String} modelName
- * @param {Array} array
- * @param {Function} cb
- */
- syncUpdates: function (modelName, array, cb) {
- cb = cb || angular.noop;
+ /**
+ * Register listeners to sync an array with updates on a model
+ *
+ * Takes the array we want to sync, the model name that socket updates are sent from,
+ * and an optional callback function after new items are updated.
+ *
+ * @param {String} modelName
+ * @param {Array} array
+ * @param {Function} cb
+ */
+ syncUpdates: function (modelName, array, cb) {
+ cb = cb || angular.noop;
- /**
- * Syncs item creation/updates on 'model:save'
- */
- socket.on(modelName + ':save', function (item) {
- var oldItem = _.find(array, {_id: item._id});
- var index = array.indexOf(oldItem);
- var event = 'created';
+ /**
+ * Syncs item creation/updates on 'model:save'
+ */
+ socket.on(modelName + ':save', function (item) {
+ var oldItem = _.find(array, {_id: item._id});
+ var index = array.indexOf(oldItem);
+ var event = 'created';
- // replace oldItem if it exists
- // otherwise just add item to the collection
- if (oldItem) {
- array.splice(index, 1, item);
- event = 'updated';
- } else {
- array.push(item);
- }
+ // replace oldItem if it exists
+ // otherwise just add item to the collection
+ if (oldItem) {
+ array.splice(index, 1, item);
+ event = 'updated';
+ } else {
+ array.push(item);
+ }
- cb(event, item, array);
- });
+ cb(event, item, array);
+ });
- /**
- * Syncs removed items on 'model:remove'
- */
- socket.on(modelName + ':remove', function (item) {
- var event = 'deleted';
- _.remove(array, {_id: item._id});
- cb(event, item, array);
- });
- },
+ /**
+ * Syncs removed items on 'model:remove'
+ */
+ socket.on(modelName + ':remove', function (item) {
+ var event = 'deleted';
+ _.remove(array, {_id: item._id});
+ cb(event, item, array);
+ });
+ },
- /**
- * Removes listeners for a models updates on the socket
- *
- * @param modelName
- */
- unsyncUpdates: function (modelName) {
- socket.removeAllListeners(modelName + ':save');
- socket.removeAllListeners(modelName + ':remove');
- }
- };
- });
+ /**
+ * Removes listeners for a models updates on the socket
+ *
+ * @param modelName
+ */
+ unsyncUpdates: function (modelName) {
+ socket.removeAllListeners(modelName + ':save');
+ socket.removeAllListeners(modelName + ':remove');
+ }
+ };
+ });
router.get('/', auth.hasRole('admin'), controller.index);
router.delete('/:id', auth.hasRole('admin'), controller.destroy);
router.get('/me', auth.isAuthenticated(), controller.me);
+router.put('/me', auth.isAuthenticated(), controller.updateMe);
router.put('/:id/password', auth.isAuthenticated(), controller.changePassword);
router.get('/:id', auth.isAuthenticated(), controller.show);
router.post('/:id', auth.hasRole('admin'), controller.update);
var config = require('../../config/environment');
var jwt = require('jsonwebtoken');
-var validationError = function(res, err) {
- return res.status(422).json(err);
+var validationError = function (res, err) {
+ return res.status(422).json(err);
};
/**
* Get list of users
* restriction: 'admin'
*/
-exports.index = function(req, res) {
- User.find({}, '-salt -hashedPassword', function (err, users) {
- if(err) return res.status(500).send(err);
- res.status(200).json(users);
- });
+exports.index = function (req, res) {
+ User.find({}, '-salt -hashedPassword', function (err, users) {
+ if (err) return res.status(500).send(err);
+ res.status(200).json(users);
+ });
};
/**
* Creates a new user
*/
exports.create = function (req, res, next) {
- var newUser = new User(req.body);
- newUser.provider = 'local';
- //newUser.role = 'user';
- newUser.save(function(err, user) {
- if (err) return validationError(res, err);
- return res.status(200).json({_id: user._id});
- });
+ var newUser = new User(req.body);
+ newUser.provider = 'local';
+ //newUser.role = 'user';
+ newUser.save(function (err, user) {
+ if (err) return validationError(res, err);
+ return res.status(200).json({_id: user._id});
+ });
};
/**
* Update a user
*/
exports.update = function (req, res, next) {
- var user = new User(req.body);
- var userData = user.toObject();
- delete userData._id;
- User.update({_id: user._id}, userData, {upsert: true}, function(err) {
- console.log(err);
- if (err) {
- return res.status(500).send('11000');
- } else {
- return res.status(200).json(user.toObject());
- }
- });
+ var user = new User(req.body);
+ var userData = user.toObject();
+ delete userData._id;
+ User.update({_id: user._id}, userData, {upsert: true}, function (err) {
+ if (err) {
+ return res.status(500).send('11000');
+ } else {
+ return res.status(200).json(user.toObject());
+ }
+ });
};
/**
* Get a single user
*/
exports.show = function (req, res, next) {
- var userId = req.params.id;
+ var userId = req.params.id;
- User.findById(userId, function (err, user) {
- if (err) return next(err);
- if (!user) return res.status(401).send('Unauthorized');
- res.json(user.profile);
- });
+ User.findById(userId, function (err, user) {
+ if (err) return next(err);
+ if (!user) return res.status(401).send('Unauthorized');
+ res.json(user.profile);
+ });
};
/**
* Deletes a user
* restriction: 'admin'
*/
-exports.destroy = function(req, res) {
- User.findByIdAndRemove(req.params.id, function(err, user) {
- if(err) return res.status(500).send(err);
- return res.status(204).send('No Content');
- });
+exports.destroy = function (req, res) {
+ User.findByIdAndRemove(req.params.id, function (err, user) {
+ if (err) return res.status(500).send(err);
+ return res.status(204).send('No Content');
+ });
};
/**
* Change a users password
*/
-exports.changePassword = function(req, res, next) {
- var userId = req.user._id;
- var oldPass = String(req.body.oldPassword);
- var newPass = String(req.body.newPassword);
+exports.changePassword = function (req, res, next) {
+ var userId = req.user._id;
+ var oldPass = String(req.body.oldPassword);
+ var newPass = String(req.body.newPassword);
- User.findById(userId, function (err, user) {
- if(user.authenticate(oldPass)) {
- user.password = newPass;
- user.save(function(err) {
- if (err) return validationError(res, err);
- res.status(200).send('OK');
- });
- } else {
- res.status(403).send('Forbidden');
- }
- });
+ User.findById(userId, function (err, user) {
+ if (user.authenticate(oldPass)) {
+ user.password = newPass;
+ user.save(function (err) {
+ if (err) return validationError(res, err);
+ res.status(200).send('OK');
+ });
+ } else {
+ res.status(403).send('Forbidden');
+ }
+ });
};
/**
* Get my info
*/
-exports.me = function(req, res, next) {
- var userId = req.user._id;
- User.findOne({
- _id: userId
- }, '-salt -hashedPassword', function(err, user) { // don't ever give out the password or salt
- if (err) return next(err);
- if (!user) return res.status(401).send('Unauthorized');
- res.json(user);
- });
+exports.me = function (req, res, next) {
+ var userId = req.user._id;
+ User.findOne({
+ _id: userId
+ }, '-salt -hashedPassword', function (err, user) { // don't ever give out the password or salt
+ if (err) return next(err);
+ if (!user) return res.status(401).send('Unauthorized');
+ res.json(user);
+ });
+};
+
+/**
+ * Update my info
+ */
+exports.updateMe = function (req, res, next) {
+ var userId = req.user._id;
+ User.findOne({
+ _id: userId
+ }, '-salt -hashedPassword', function (err, user) { // don't ever give out the password or salt
+ if (err) return next(err);
+ if (!user) return res.status(401).send('Unauthorized');
+ user.referential = req.body.referential;
+ user.save(function (err) {
+ if (err) return validationError(res, err);
+ res.status(200).send('OK');
+ });
+ });
};
/**
* Authentication callback
*/
-exports.authCallback = function(req, res, next) {
- res.redirect('/');
+exports.authCallback = function (req, res, next) {
+ res.redirect('/');
};
var config = require('./environment');
var passport = require('passport');
-module.exports = function(app) {
- var env = app.get('env');
+module.exports = function (app) {
+ var env = app.get('env');
- app.set('views', config.root + '/server/views');
- app.set('view engine', 'jade');
- app.use(compression());
- app.use(bodyParser.urlencoded({ extended: false }));
- app.use(bodyParser.json());
- app.use(methodOverride());
- app.use(cookieParser());
- app.use(passport.initialize());
- if ('production' === env) {
- app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
- app.use(express.static(path.join(config.root, 'public')));
- app.set('appPath', path.join(config.root, 'public'));
- app.use(morgan('dev'));
- }
+ app.set('views', config.root + '/server/views');
+ app.set('view engine', 'jade');
+ app.use(compression());
+ app.use(bodyParser.urlencoded({extended: false}));
+ app.use(bodyParser.json());
+ app.use(methodOverride());
+ app.use(cookieParser());
+ app.use(passport.initialize());
+ if ('production' === env) {
+ app.use(favicon(path.join(config.root, 'public', 'favicon.ico')));
+ app.use(express.static(path.join(config.root, 'public')));
+ app.set('appPath', path.join(config.root, 'public'));
+ app.use(morgan('dev'));
+ }
- if ('development' === env || 'test' === env) {
- // Modif LH -> connect-livereload empêche le téléchargement de fichier PDF
- //app.use(require('connect-livereload')());
- app.use(express.static(path.join(config.root, '.tmp')));
- app.use(express.static(path.join(config.root, 'client')));
- app.set('appPath', path.join(config.root, 'client'));
- app.use(morgan('dev'));
- app.use(errorHandler()); // Error handler - has to be last
- }
+ if ('development' === env || 'test' === env) {
+ // Modif LH -> connect-livereload empêche le téléchargement de fichier PDF
+ app.use(require('connect-livereload')());
+ app.use(express.static(path.join(config.root, '.tmp')));
+ app.use(express.static(path.join(config.root, 'client')));
+ app.set('appPath', path.join(config.root, 'client'));
+ app.use(morgan('dev'));
+ app.use(errorHandler()); // Error handler - has to be last
+ }
};
\ No newline at end of file
// When the user connects.. perform this
function onConnect(socket) {
- // When the client emits 'info', this listens and executes
- socket.on('info', function (data) {
- console.info('[%s] %s', socket.address, JSON.stringify(data, null, 2));
- });
+ // When the client emits 'info', this listens and executes
+ socket.on('info', function (data) {
+ console.info('[%s] %s', socket.address, JSON.stringify(data, null, 2));
+ });
- // Insert sockets below
- require('../api/report/report.socket').register(socket);
+ // Insert sockets below
+ require('../api/report/report.socket').register(socket);
}
module.exports = function (socketio) {
- // socket.io (v1.x.x) is powered by debug.
- // In order to see all the debug output, set DEBUG (in server/config/local.env.js) to including the desired scope.
- //
- // ex: DEBUG: "http*,socket.io:socket"
-
- // We can authenticate socket.io users and access their token through socket.handshake.decoded_token
- //
- // 1. You will need to send the token in `client/components/socket/socket.service.js`
- //
- // 2. Require authentication here:
- // socketio.use(require('socketio-jwt').authorize({
- // secret: config.secrets.session,
- // handshake: true
- // }));
-
- socketio.on('connection', function (socket) {
- socket.connectedAt = new Date();
-
- // Call onDisconnect.
- socket.on('disconnect', function () {
- onDisconnect(socket);
- console.info('[%s] DISCONNECTED', socket.handshake.address);
+ // socket.io (v1.x.x) is powered by debug.
+ // In order to see all the debug output, set DEBUG (in server/config/local.env.js) to including the desired scope.
+ //
+ // ex: DEBUG: "http*,socket.io:socket"
+
+ // We can authenticate socket.io users and access their token through socket.handshake.decoded_token
+ //
+ // 1. You will need to send the token in `client/components/socket/socket.service.js`
+ //
+ // 2. Require authentication here:
+ // socketio.use(require('socketio-jwt').authorize({
+ // secret: config.secrets.session,
+ // handshake: true
+ // }));
+
+ socketio.on('connection', function (socket) {
+ socket.connectedAt = new Date();
+
+ // Call onDisconnect.
+ socket.on('disconnect', function () {
+ onDisconnect(socket);
+ console.info('[%s] DISCONNECTED', socket.handshake.address);
+ });
+
+ // Call onConnect.
+ onConnect(socket);
+ console.info('[%s] CONNECTED', socket.handshake.address);
});
-
- // Call onConnect.
- onConnect(socket);
- console.info('[%s] CONNECTED', socket.handshake.address);
- });
};