Skip to content

Commit

Permalink
Merge branch 'feat/change-password'
Browse files Browse the repository at this point in the history
  • Loading branch information
gicaz committed Jun 8, 2016
2 parents 26f1491 + 574780e commit c18c44c
Show file tree
Hide file tree
Showing 16 changed files with 1,116 additions and 686 deletions.
134 changes: 84 additions & 50 deletions api/controllers/OperatorController.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
/**
* OperatorController
*
* @description :: Server-side logic for managing operators
* @help :: See http://links.sailsjs.org/docs/controllers
*/
* OperatorController
*
* @description :: Server-side logic for managing operators
* @help :: See http://links.sailsjs.org/docs/controllers
*/

/* jshint node: true */
/* globals _, sails, Subject, Sample, Data, DataType, SubjectService, BiobankService, SampleService, TokenService, QueryService, DataService, PassportService */
'use strict';

var BluebirdPromise = require("bluebird");
var createUser = BluebirdPromise.promisify(PassportService.protocols.local.createUser);
const ControllerOut = require('xtens-utils').ControllerOut;
const crudManager = sails.hooks.persistence.crudManager;
const BluebirdPromise = require('bluebird');
const createUser = BluebirdPromise.promisify(PassportService.protocols.local.createUser);
const updatePassword = BluebirdPromise.promisify(PassportService.protocols.local.updatePassword);
const ValidationError = require('xtens-utils').Errors.ValidationError;

var OperatorController = {

create: function(req, res) {
console.log(req.allParams());
return createUser(req.allParams())

.then(function(operator) {
// set a password field (for Backbone)

// set a password field (for Backbone)
operator.password = true;

console.log(operator);
Expand All @@ -26,59 +34,85 @@ var OperatorController = {

},

addGroupToOperator: function(req,res,next) {
/**
* @method
* @name patchPassword
* @description given a correct old password and a new password (with confirmation)
* updates the local stored password
*/
patchPassword: function(req, res) {
const co = new ControllerOut(res);
const idOperator = TokenService.getToken(req).id;
if (idOperator) {

return updatePassword(req.allParams(), idOperator)

.then(function() {

return res.json(204, null);

}).catch(function(error) {
console.log(error.message);
return co.error(error);
});
} else {
return res.json(400, 'Operator not Found');
}

},

addGroupToOperator: function(req, res, next) {

/* Operator.findOne(req.param('operator_id')).populate('groups').exec(function(err,bean){
if(err) return next(err);
if(!bean) return next();
bean.groups.add(req.param('group_id'));
bean.save(function(err) {
if(err) return next(err);
res.redirect('/operator');
});
});*/
if(err) return next(err);
if(!bean) return next();
bean.groups.add(req.param('group_id'));
bean.save(function(err) {
if(err) return next(err);
res.redirect('/operator');
});
});*/
}


/*removeGroupFromOperator: function(req,res,next){
}
/**
* `OperatorController.create()`
/*removeGroupFromOperator: function(req,res,next){
}
/**
* `OperatorController.create()`
create: function (req, res) {
res.view();
},
*/
create: function (req, res) {
res.view();
},
*/

/**
* `OperatorController.destroy()`
/**
* `OperatorController.destroy()`
destroy: function (req, res) {
return res.json({
todo: 'destroy() is not implemented yet!'
});
},
destroy: function (req, res) {
return res.json({
todo: 'destroy() is not implemented yet!'
});
},
/**
* `OperatorController.tag()`
/**
* `OperatorController.tag()`
tag: function (req, res) {
return res.json({
todo: 'tag() is not implemented yet!'
});
},
tag: function (req, res) {
return res.json({
todo: 'tag() is not implemented yet!'
});
},
/**
* `OperatorController.like()`
/**
* `OperatorController.like()`
like: function (req, res) {
return res.json({
todo: 'like() is not implemented yet!'
});
}*/
like: function (req, res) {
return res.json({
todo: 'like() is not implemented yet!'
});
}*/
};

module.exports = OperatorController;

Loading

0 comments on commit c18c44c

Please sign in to comment.