Commit ebc987b4 by Pablo Molina

Merged origin/master into master

parents 43f9b70f 66ed4620
...@@ -152,6 +152,8 @@ module.exports = { ...@@ -152,6 +152,8 @@ module.exports = {
// //
create: function(req, res) { create: function(req, res) {
var params = req.params.all(); var params = req.params.all();
delete params.email_confirm;
delete params.password_confirm;
Supervisor.create(params).exec(function (err, created) { Supervisor.create(params).exec(function (err, created) {
if (err) { if (err) {
...@@ -159,10 +161,13 @@ module.exports = { ...@@ -159,10 +161,13 @@ module.exports = {
return res.json(500, {error: 'User not created'}); return res.json(500, {error: 'User not created'});
} }
if (created) { if (created) {
// Send email confirmation // TODO: Send email confirmation
console.log("sending mail to user" ); // created.sendMail();
created.sendMail(); return res.json({
return res.json({user: created, token: sailsTokenAuth.issueToken(created.id)}); user: created,
token: sailsTokenAuth.issueToken(created.id)});
} else {
return res.json(500, {error: 'User not created'});
} }
}); });
}, },
......
...@@ -186,31 +186,32 @@ module.exports = { ...@@ -186,31 +186,32 @@ module.exports = {
// //
beforeCreate: function(attrs, next) { beforeCreate: function(attrs, next) {
// // We have to encryption AFTER checking user does not exist
// Check that user does not exist // so... we use async.series to ensure task completion
// NOTE: This is not needed as uniqueness is granted by DB
// async.series([
function(cb) { // check email is new
Supervisor.findByEmail(attrs.email).exec(function(err, users) { Supervisor.findByEmail(attrs.email).exec(function(err, users) {
if (err) if (err) return cb(err);
return next(err);
if (users.length > 0) if (users.length > 0)
return next(new Error('User exists')); return cb(new Error('User exists'));
cb();
}); });
},
// function(cb) { // encrypt password
// Encrypt password before insertion
//
var bcrypt = require('bcrypt-nodejs'); var bcrypt = require('bcrypt-nodejs');
bcrypt.genSalt(10, function(err, salt) { bcrypt.genSalt(10, function(err, salt) {
if (err) if (err) return cb(err);
return next(err);
bcrypt.hash(attrs.password, salt, null, function(err, hash) { bcrypt.hash(attrs.password, salt, null, function(err, hash) {
if (err) if (err) return cb(err);
return next(err);
attrs.password = hash; attrs.password = hash;
next(); cb();
});
}); });
}
], function(err) {
if (err) return next(err);
next();
}); });
}, },
...@@ -220,18 +221,24 @@ module.exports = { ...@@ -220,18 +221,24 @@ module.exports = {
// //
beforeUpdate: function(attrs, next) { beforeUpdate: function(attrs, next) {
async.series([
function(cb) {
// //
// Check that user email does not exist // Check that user email does not exist
// //
if(attrs.email){ if(attrs.email){
Supervisor.findByEmail(attrs.email).exec(function(err, users) { Supervisor.findByEmail(attrs.email).exec(function(err, users) {
if (err) if (err)
return next(err); return cb(err);
if (users.length > 0) if (users.length > 0)
return next(new Error('User email already exists')); return cb(new Error('User email already exists'));
cb();
}); });
} else {
return cb(new Error('No email in user attributes'));
} }
},
function(cb) {
// //
// Encrypt password before insertion // Encrypt password before insertion
// //
...@@ -239,18 +246,20 @@ module.exports = { ...@@ -239,18 +246,20 @@ module.exports = {
var bcrypt = require('bcrypt-nodejs'); var bcrypt = require('bcrypt-nodejs');
bcrypt.genSalt(10, function(err, salt) { bcrypt.genSalt(10, function(err, salt) {
if (err) if (err) return cb(err);
return next(err);
bcrypt.hash(attrs.password, salt, null, function(err, hash) { bcrypt.hash(attrs.password, salt, null, function(err, hash) {
if (err) if (err) return cb(err);
return next(err);
attrs.password = hash; attrs.password = hash;
next(); cb();
}); });
}); });
}else{ }else{
next(); cb();
} }
}], function(err) {
if (err) return next(err);
next();
});
}, },
// //
......

9.04 KB | W: | H:

4.5 KB | W: | H:

sails/src/assets/app/img/logo_pictogram.png
sails/src/assets/app/img/logo_pictogram.png
sails/src/assets/app/img/logo_pictogram.png
sails/src/assets/app/img/logo_pictogram.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -21,7 +21,7 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http, ...@@ -21,7 +21,7 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http,
lang: 'es' lang: 'es'
}; };
reCAPTCHA.setPublicKey('6LdkZwMTAAAAANDR_7_y9_ifEve1gLPcgneM_50o'); reCAPTCHA.setPublicKey('6LdLjh0TAAAAANblo_KUGNnmRZuIetOkdjdhj1b6');
/* NOT NECESSARY /* NOT NECESSARY
// Array of key terms to translate // Array of key terms to translate
...@@ -84,7 +84,7 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http, ...@@ -84,7 +84,7 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http,
$scope.alert = "alert-danger"; $scope.alert = "alert-danger";
$scope.message = "user_exists"; $scope.message = "user_exists";
console.log("Error from API: " + data.error); console.log("Error from API: " + status);
}); });
}; };
......
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