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 @@
echo "-- Running pictogram server"
if [ -e "src/app.js" ]; then
cd src && forever start app.js
cd src && npm start
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
cd /home/vagrant/sync/src && forever start app.js
cd /home/vagrant/sync/src && npm start
else
echo "-- app.js not found, cannot run pictogram server"
exit
......
......@@ -388,7 +388,7 @@ CREATE TABLE IF NOT EXISTS `supervisor` (
`name` varchar(40) COLLATE utf8_unicode_ci NOT NULL,
`surname` varchar(60) 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,
`country` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`email` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
......
......@@ -255,6 +255,11 @@ module.exports = {
return res.json(500, {
error: "No student found"
});
if (!req.body.password) {
delete req.body.password;
}
// copy attributes
for (k in req.body) stu[k] = req.body[k];
stu.save(function (stuSaveError, saved) {
......
......@@ -16,7 +16,10 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
// For tab navigation (here too, if the user refresh the page...)
$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) {
var i;
var file;
......@@ -57,46 +60,58 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
}
};
// Open calendar
$scope.open_calendar = function ($event) {
$event.preventDefault();
$event.stopPropagation();
/**
* Opens the calendar for selecting student's birthdate.
* Prevents the propagation of the click event.
* @param {event} Click event
*/
$scope.openCalendar = function (event) {
event.stopPropagation();
$scope.opened = true;
};
// Save personal info updated
$scope.update_student = function () {
// Validate password match
if ($scope.formUser.password_confirm &&
!$scope.formUser.password_confirm.length &&
$scope.formUser.password !== $scope.formUser.password_confirm) {
$translate('password_match').then(function (translation) {
ngToast.danger({ content: translation });
});
return;
}
/**
* Sends the student new information to the server.
* If any password has been entered in the form, both password and password_confirm must match,
* otherwise the password field is ignored.
*/
$scope.updateStudent = function () {
var password;
// 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;
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) {
ngToast.danger({ content: translation });
});
return;
}
}
$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) {
$translate('student_updated').then(function (translation) {
ngToast.success({ content: translation });
});
$scope.studentData.surname = data.surname;
$scope.studentData.birthdate = data.birthdate;
$scope.studentData.country = data.country;
$scope.studentData.pic = data.pic;
$scope.studentData.gender = data.gender;
$scope.studentData.lang = data.lang;
$scope.studentData.notes = data.notes;
$scope.formUser.birthdate = data.birthdate;
$scope.formUser.country = data.country;
$scope.formUser.gender = data.gender;
$scope.formUser.lang = data.lang;
$scope.formUser.name = data.name;
$scope.formUser.notes = data.notes;
$scope.formUser.surname = data.surname;
$scope.formUser.username = data.username;
})
.error(function () {
$translate.danger('student_not_updated', function (translation) {
......@@ -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
$http.get(config.backend + '/sup/email/' + $scope.email_sup)
.success(function (data) {
if (data.length > 0) {
$scope.supToAdd = data[0];
if (data) {
$scope.supToAdd = data;
$scope.showmessagesupfound = true;
$scope.showmessagesupnotfound = false;
} else {
......@@ -188,8 +206,8 @@ dashboardControllers.controller('StudentSetupCtrl', function StudentSetupCtrl(
$http.get(config.backend + '/sup/email/' + $scope.email_tutor)
.success(function (data) {
// If it found the length is > 0
if (data.length > 0) {
$scope.tutorToAdd = data[0];
if (data) {
$scope.tutorToAdd = data;
// Show message for validate
$scope.showmessagetutorfound = true;
$scope.showmessagetutornotfound = false;
......
......@@ -31,8 +31,7 @@
"winston": "~1.0.0"
},
"scripts": {
"start": "node app.js",
"debug": "node debug app.js",
"start": "forever start app.js",
"test": "mocha test/test-helper.js test/**/*-spec.js",
"test:watch": "npm run test -- --reporter min --watch"
},
......@@ -41,7 +40,7 @@
"type": "git",
"url": "http://scm.ujaen.es/softuno/pictogram.git"
},
"author": "emblanco, amontejo",
"author": "Yottacode",
"license": "",
"devDependencies": {
"chai": "^3.5.0",
......
describe('Action API', function () {
it('POST /action', function (done) {
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 /action');
it('POST /actions');
});
......@@ -5,7 +5,7 @@ describe('Student API', function () {
delete studentAgentData.iat;
delete studentAgentData.isStudent;
delete studentAgentData.password;
studentAgentData.current_method = 'Test method';
studentAgentData.current_method = 'Test Method';
studentAgentData.current_instruction = 'Test Instruction';
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