2016-09-08 22:43:50 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Update user page.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
|
|
|
pages.create('update-user', 'update-user.html', UpdateUserCtrl, {
|
|
|
|
'title': 'Confirm Username'
|
|
|
|
});
|
|
|
|
}]);
|
|
|
|
|
|
|
|
function UpdateUserCtrl($scope, UserService, $location, ApiService) {
|
|
|
|
$scope.state = 'loading';
|
2016-11-04 21:57:55 +00:00
|
|
|
$scope.metadata = {};
|
2016-09-08 22:43:50 +00:00
|
|
|
|
|
|
|
UserService.updateUserIn($scope, function(user) {
|
2016-11-09 00:15:11 +00:00
|
|
|
if (!user.anonymous) {
|
2016-09-08 22:43:50 +00:00
|
|
|
if (!user.prompts || !user.prompts.length) {
|
|
|
|
$location.path('/');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.state = 'editing';
|
|
|
|
$scope.username = user.username;
|
2016-11-09 00:15:11 +00:00
|
|
|
}
|
2016-09-08 22:43:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var confirmUsername = function(username) {
|
|
|
|
if (username == $scope.user.username) {
|
|
|
|
$scope.state = 'confirmed';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.state = 'confirming';
|
|
|
|
var params = {
|
|
|
|
'username': username
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.getUserInformation(null, params).then(function() {
|
|
|
|
$scope.state = 'existing';
|
|
|
|
}, function(resp) {
|
|
|
|
if (resp.status == 404) {
|
|
|
|
$scope.state = 'confirmed';
|
|
|
|
} else {
|
|
|
|
$scope.state = 'error';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-11-04 21:57:55 +00:00
|
|
|
$scope.updateUser = function(data) {
|
|
|
|
$scope.state = 'updating';
|
|
|
|
ApiService.changeUserDetails(data).then(function() {
|
|
|
|
UserService.load(function(updated) {
|
2017-01-24 17:16:03 +00:00
|
|
|
if (updated && updated.prompts && updated.prompts.length) {
|
2016-11-04 21:57:55 +00:00
|
|
|
$scope.state = 'editing';
|
|
|
|
} else {
|
|
|
|
$location.url('/');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, ApiService.errorDisplay('Could not update user information'));
|
2016-09-08 22:43:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.hasPrompt = function(user, prompt_name) {
|
2017-10-09 18:02:36 +00:00
|
|
|
if (!user || !user.prompts) {
|
2016-09-08 22:43:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < user.prompts.length; ++i) {
|
|
|
|
if (user.prompts[i] == prompt_name) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('username', function(username) {
|
|
|
|
if (!username) {
|
|
|
|
$scope.state = 'editing';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmUsername(username);
|
|
|
|
});
|
|
|
|
}
|
2017-01-24 17:16:03 +00:00
|
|
|
})();
|