better handling of errors in supervisor signin

parent 8cd04f26
......@@ -2,16 +2,8 @@
Changes to be performed manually in servers to upgrade
## AngularJS
(already done in dev & pre)
- angular-re-captcha has been replaced by angular-recaptcha, so bower has to be run
- reinstall ui-bootstrap
- replace angular-file-upload by ng-file-upload
`bower install`
## Database
- Delete active column from scene table (deleted from `already done in dev` sql `create scene table` statement)
`alter table scene drop active;`
......@@ -54,29 +46,3 @@ Changes to be performed manually in servers to upgrade
- Reload enrolments trigger
`source /vagrant/roles/database/files/triggers-enrolments-integrity-constraints.sql`
(already done in dev & pre)
- add new column to license:
`alter table license add column creator varchar(40) DEFAULT NULL;`
- add arasaac to source table
`INSERT INTO `source` (`id`, `name`, `description`) VALUES (3, 'Arasaac', 'Arasaac pictograms collection');`
- alter table supervisor add arasaac license:
`ALTER TABLE supervisor ADD COLUMN arasaac_license BOOLEAN DEFAULT FALSE;`
- load arasaac.sql into MySQL
- load pictocat_tree_populate.sql
`source /vagrant/roles/database/files/pictocat_tree_populate.sql;`
- reload trigers-enrolments-integrity-constraints.sql
- alter table supervisor to add postal_code:
`alter table supervisor add column `postal_code` char(10) COLLATE utf8_unicode_ci NOT NULL;`
- alter table office to add postal_code:
`alter table office add column `postal_code` char(10) COLLATE utf8_unicode_ci NOT NULL;`
- remove max_students and current_students columns from offices:
`alter table office drop column max_students;`
`alter table office drop column current_students;`
- copy postal_code value from office to its supervisors
`update supervisor as sup inner join office as off on off.id = sup.id_off set sup.postal_code = off.postal_code;`
- alter table office
`alter table office modify logo_url varchar(240) default null;`
......@@ -330,7 +330,7 @@ module.exports = {
email: params.email,
pic: sails.config.pictogram.paths.defaultAvatarFileName,
address: params.address || '',
postalCode: params.postalCode || '',
postal_code: params.postalCode || '',
country: params.country || '',
phone: params.phone || '',
lang: params.lang || 'es-es',
......@@ -338,6 +338,7 @@ module.exports = {
if (params.id_off)
supData.id_off = params.id_off;
console.log(JSON.stringify(supData));
Supervisor.create(supData)
.then(function (sup) {
......@@ -369,11 +370,13 @@ module.exports = {
supervisor = sup;
sendConfirmationMail((err) => {
if (err) throw err;
if (err) return res.serverError("Confirmation mail could not be sent: " + err);
return res.ok();
});
})
.catch(err => {throw err});
.catch((err) => {
return res.serverError("Supervisor could not be created: " + err);
});
} else
return res.badRequest("Invalid role");
}).catch(function (err) {
......@@ -474,12 +477,12 @@ module.exports = {
update: function (req, res) {
Supervisor.findOne({ id: req.params.id })
.then(function (supervisor) {
if (supervisor) {
if (req.body.password) {
if (!supervisor)
return res.notFound();
if (req.body.password && req.body.password.length > 0)
supervisor.password = req.body.password;
} else {
else
delete supervisor.password;
}
supervisor.name = req.body.name || supervisor.name;
supervisor.surname = req.body.surname || supervisor.surname;
supervisor.gender = req.body.gender || supervisor.gender;
......@@ -493,18 +496,12 @@ module.exports = {
supervisor.ttsEngine = req.body.ttsEngine || supervisor.ttsEngine;
supervisor.office = req.body.office || supervisor.office;
supervisor.save(function (error) {
if (error) {
res.serverError();
} else {
res.ok(supervisor);
}
if (error) throw error;
return res.ok(supervisor);
});
} else {
res.notFound();
}
})
.catch(function () {
res.serverError();
.catch(function (err) {
return res.serverError(err);
});
},
......
......@@ -44,7 +44,7 @@ module.exports = {
lang: {
required: true,
type: "string",
size: 2
size: 5
},
contactPerson: {
columnName: "contact_person",
......@@ -88,6 +88,7 @@ module.exports = {
collection: "Student",
via: 'office'
},
toJSON: function() {
var office = this.toObject();
if (!office.logoUrl)
......
......@@ -74,7 +74,7 @@ module.exports = {
lang: {
required: true,
type: "string",
size: 2
size: 5
},
ttsEngine: {
columnName: 'tts_engine',
......@@ -143,7 +143,7 @@ module.exports = {
//
beforeCreate: function (attrs, next) {
var async = require('async');
console.log("-->\n" + JSON.stringify(attrs));
async.series(
[
function (cb) {
......@@ -203,7 +203,8 @@ module.exports = {
var bcrypt = require('bcrypt-nodejs');
if (attrs.password && attrs.password.length > 0) {
attrs.password = bcrypt.hashSync(attrs.password, bcrypt.genSaltSync());
}
} else
delete attrs.password;
cb();
}
],
......
......@@ -21,7 +21,7 @@ function SignInCtrl($scope,
name: '',
surname: '',
address: '',
postal_code: '',
postalCode: '',
country: '00',
phone: '',
gender: 'F',
......
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