update of user data after submission

parent ceb18c42
......@@ -67,7 +67,8 @@ module.exports = {
if (!email || !password)
return res.badRequest('Missing parameters');
Supervisor.findOneByEmail(email).then(function (supervisor) {
Supervisor.findOneByEmail(email)
.then(function (supervisor) {
if (!supervisor)
throw new Error("Supervisor not found")
......@@ -78,10 +79,6 @@ module.exports = {
if (supervisor.active == 0)
throw new Error("This account has not been activated");
return (supervisor);
}).then(function (supervisor) {
return res.ok({
user: supervisor,
server_time: (new Date()).getTime(),
......
......@@ -18,13 +18,11 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
config,
CONSTANTS) {
$scope.user = $rootScope.user;
// Don't show the message at the begining
$scope.showmessage = false;
// Restore user values from sessionStorage
$scope.formdata = JSON.parse($window.sessionStorage.user);;
$scope.formdata = JSON.parse(JSON.stringify($scope.user));
$scope.changeImg = function () {
......@@ -77,8 +75,6 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
// Form submit
$scope.setup = function () {
var supervisor;
var actualEmail;
if ($scope.formdata.password && $scope.formdata.password !== $scope.formdata.password_confirm) {
ngToast.danger({ content: $translate.instant('password_match') });
......@@ -95,15 +91,13 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
return;
}
supervisor = $scope.formdata;
var supervisor = JSON.parse(JSON.stringify($scope.formdata));
if (supervisor.password && supervisor.password.length == 0)
delete supervisor.password;
actualEmail = JSON.parse($window.sessionStorage.user).email;
// Comprobation for new email
// If no change, it is deleted from supervisor object
if (supervisor.email === actualEmail) {
if (supervisor.email === $scope.user.email) {
delete supervisor.email;
}
......@@ -112,12 +106,9 @@ dashboardControllers.controller('SetupCtrl', function SetupCtrl(
$http.put(config.backend + '/sup/' + supervisor.id, supervisor)
.success(function (data) {
ngToast.success({ content: $translate.instant('data_saved') });
delete data.password;
delete data.password_confirm;
$scope.user = JSON.parse(JSON.stringify(data));
$window.sessionStorage.user = JSON.stringify($scope.user);
ngToast.success({ content: $translate.instant('data_saved') });
})
.error(function () {
ngToast.danger({ content: $translate.instant('data_no_saved') });
......
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