Commit e345e84a by Pablo Molina

Fixed #409, pérdida de contraseña al actualizar estudiante

Se ha añadido una comprobación tanto en el cliente como en el servidor para comprobar si el valor introducido como contraseña tiene un valor verdadero (no vacío).

Además se han corregido los tests asociados a este error y se han actualizado los datos de ejemplo de la base de datos CAJA.
parent 25d6599b
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
echo "-- Running pictogram server" echo "-- Running pictogram server"
if [ -e "src/app.js" ]; then if [ -e "src/app.js" ]; then
cd src && forever start app.js cd src && npm start
elif [ -e "/vagrant/src/app.js" ]; then elif [ -e "/vagrant/src/app.js" ]; then
cd /vagrant/src && forever start app.js cd /vagrant/src && npm start
elif [ -e "/home/vagrant/sync/src/app.js" ]; then elif [ -e "/home/vagrant/sync/src/app.js" ]; then
cd /home/vagrant/sync/src && forever start app.js cd /home/vagrant/sync/src && npm start
else else
echo "-- app.js not found, cannot run pictogram server" echo "-- app.js not found, cannot run pictogram server"
exit exit
......
...@@ -388,7 +388,7 @@ CREATE TABLE IF NOT EXISTS `supervisor` ( ...@@ -388,7 +388,7 @@ CREATE TABLE IF NOT EXISTS `supervisor` (
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL, `name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`surname` varchar(60) COLLATE utf8_unicode_ci NOT NULL, `surname` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`gender` char(1) COLLATE utf8_unicode_ci NOT NULL, `gender` char(1) COLLATE utf8_unicode_ci NOT NULL,
`pic` varchar(255) COLLATE utf8_unicode_ci DEFAULT '/upload/supervisorAvatar/defaultAvatar.jpg', `pic` varchar(255) COLLATE utf8_unicode_ci DEFAULT 'defaultAvatar.jpg',
`address` varchar(180) COLLATE utf8_unicode_ci DEFAULT NULL, `address` varchar(180) COLLATE utf8_unicode_ci DEFAULT NULL,
`country` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL, `country` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(80) COLLATE utf8_unicode_ci NOT NULL, `email` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
......
...@@ -255,6 +255,11 @@ module.exports = { ...@@ -255,6 +255,11 @@ module.exports = {
return res.json(500, { return res.json(500, {
error: "No student found" error: "No student found"
}); });
if (!req.body.password) {
delete req.body.password;
}
// copy attributes // copy attributes
for (k in req.body) stu[k] = req.body[k]; for (k in req.body) stu[k] = req.body[k];
stu.save(function (stuSaveError, saved) { stu.save(function (stuSaveError, saved) {
......
...@@ -16,7 +16,10 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -16,7 +16,10 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
// For tab navigation (here too, if the user refresh the page...) // For tab navigation (here too, if the user refresh the page...)
$scope.nav.tab = 'setup'; $scope.nav.tab = 'setup';
// When a picture is selected, launch the request /**
* Updates the student picture
* @param {Angular file array} $files Image to be uploaded
*/
$scope.onFileSelect = function ($files) { $scope.onFileSelect = function ($files) {
var i; var i;
var file; var file;
...@@ -57,46 +60,58 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -57,46 +60,58 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
} }
}; };
// Open calendar /**
$scope.open_calendar = function ($event) { * Opens the calendar for selecting student's birthdate.
$event.preventDefault(); * Prevents the propagation of the click event.
$event.stopPropagation(); * @param {event} Click event
*/
$scope.openCalendar = function (event) {
event.stopPropagation();
$scope.opened = true; $scope.opened = true;
}; };
// Save personal info updated /**
$scope.update_student = function () { * Sends the student new information to the server.
// Validate password match * If any password has been entered in the form, both password and password_confirm must match,
if ($scope.formUser.password_confirm && * otherwise the password field is ignored.
!$scope.formUser.password_confirm.length && */
$scope.formUser.password !== $scope.formUser.password_confirm) { $scope.updateStudent = function () {
var password;
if ($scope.formUser.password_confirm || $scope.formUser.password) {
if ($scope.formUser.password_confirm === $scope.formUser.password) {
password = $scope.formUser.password;
} else {
$translate('password_match').then(function (translation) { $translate('password_match').then(function (translation) {
ngToast.danger({ content: translation }); ngToast.danger({ content: translation });
}); });
return; return;
} }
// password not changed (don't send it to DB)
if ($scope.formUser.password_confirm &&
!$scope.formUser.password_confirm.length) {
delete $scope.formUser.password;
delete $scope.formUser.password_confirm;
} }
$http.put(config.backend + '/stu/' + $scope.studentData.id, $scope.formUser) $http.put(config.backend + '/stu/' + $scope.studentData.id, {
birthdate: $scope.formUser.birthdate,
country: $scope.formUser.country,
gender: $scope.formUser.gender,
lang: $scope.formUser.lang,
name: $scope.formUser.name,
notes: $scope.formUser.notes,
surname: $scope.formUser.surname,
username: $scope.formUser.username,
password: password
})
.success(function (data) { .success(function (data) {
$translate('student_updated').then(function (translation) { $translate('student_updated').then(function (translation) {
ngToast.success({ content: translation }); ngToast.success({ content: translation });
}); });
$scope.formUser.birthdate = data.birthdate;
$scope.studentData.surname = data.surname; $scope.formUser.country = data.country;
$scope.studentData.birthdate = data.birthdate; $scope.formUser.gender = data.gender;
$scope.studentData.country = data.country; $scope.formUser.lang = data.lang;
$scope.studentData.pic = data.pic; $scope.formUser.name = data.name;
$scope.studentData.gender = data.gender; $scope.formUser.notes = data.notes;
$scope.studentData.lang = data.lang; $scope.formUser.surname = data.surname;
$scope.studentData.notes = data.notes; $scope.formUser.username = data.username;
}) })
.error(function () { .error(function () {
$translate.danger('student_not_updated', function (translation) { $translate.danger('student_not_updated', function (translation) {
...@@ -105,13 +120,16 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -105,13 +120,16 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
}); });
}; };
// Search supervisor by email /**
$scope.search_sup = function () { * Get a supervisor by their email and updates the $scope.supToAdd element.
* The email used for search is fetched from $scope.email_sup.
*/
$scope.getSupervisorByEmail = function () {
// Find tutor by email // Find tutor by email
$http.get(config.backend + '/sup/email/' + $scope.email_sup) $http.get(config.backend + '/sup/email/' + $scope.email_sup)
.success(function (data) { .success(function (data) {
if (data.length > 0) { if (data) {
$scope.supToAdd = data[0]; $scope.supToAdd = data;
$scope.showmessagesupfound = true; $scope.showmessagesupfound = true;
$scope.showmessagesupnotfound = false; $scope.showmessagesupnotfound = false;
} else { } else {
...@@ -188,8 +206,8 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl( ...@@ -188,8 +206,8 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
$http.get(config.backend + '/sup/email/' + $scope.email_tutor) $http.get(config.backend + '/sup/email/' + $scope.email_tutor)
.success(function (data) { .success(function (data) {
// If it found the length is > 0 // If it found the length is > 0
if (data.length > 0) { if (data) {
$scope.tutorToAdd = data[0]; $scope.tutorToAdd = data;
// Show message for validate // Show message for validate
$scope.showmessagetutorfound = true; $scope.showmessagetutorfound = true;
$scope.showmessagetutornotfound = false; $scope.showmessagetutornotfound = false;
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
"winston": "~1.0.0" "winston": "~1.0.0"
}, },
"scripts": { "scripts": {
"start": "node app.js", "start": "forever start app.js",
"debug": "node debug app.js",
"test": "mocha test/test-helper.js test/**/*-spec.js", "test": "mocha test/test-helper.js test/**/*-spec.js",
"test:watch": "npm run test -- --reporter min --watch" "test:watch": "npm run test -- --reporter min --watch"
}, },
...@@ -41,7 +40,7 @@ ...@@ -41,7 +40,7 @@
"type": "git", "type": "git",
"url": "http://scm.ujaen.es/softuno/pictogram.git" "url": "http://scm.ujaen.es/softuno/pictogram.git"
}, },
"author": "emblanco, amontejo", "author": "Yottacode",
"license": "", "license": "",
"devDependencies": { "devDependencies": {
"chai": "^3.5.0", "chai": "^3.5.0",
......
describe('Action API', function () { describe('Action API', function () {
it('POST /action', function (done) { it('POST /action');
studentAgent.post('/action').send({
student: studentAgent.data.id,
type: 'Add',
supervisor: supervisorAgent.data.id,
description: '{ json description }'
})
.expect(200)
.expect((response) => {
assert.isObject(response.body);
assert.isNumber(response.body.id);
delete response.body.id;
})
.expect({
student: studentAgent.data.id,
type: 'Add',
supervisor: supervisorAgent.data.id,
description: '{ json description }',
})
.end(done);
});
it('POST /actions'); it('POST /actions');
}); });
...@@ -5,7 +5,7 @@ describe('Student API', function () { ...@@ -5,7 +5,7 @@ describe('Student API', function () {
delete studentAgentData.iat; delete studentAgentData.iat;
delete studentAgentData.isStudent; delete studentAgentData.isStudent;
delete studentAgentData.password; delete studentAgentData.password;
studentAgentData.current_method = 'Test method'; studentAgentData.current_method = 'Test Method';
studentAgentData.current_instruction = 'Test Instruction'; studentAgentData.current_instruction = 'Test Instruction';
supervisorAgent supervisorAgent
......
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