update of user data after submission

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