|
| 1 | +module.controller('users.SsoUserEditDialogController', [ |
| 2 | + '$scope', |
| 3 | + '$uibModalInstance', |
| 4 | + 'UserService', |
| 5 | + 'Alert', |
| 6 | + 'user', |
| 7 | + '$q', |
| 8 | + function ($scope, $modalInstance, UserService, $alert, user, $q) { |
| 9 | + |
| 10 | + // currently selected user object |
| 11 | + $scope.user = user; |
| 12 | + |
| 13 | + // These are the provider types accepted in the API. |
| 14 | + $scope.providerTypes = [ |
| 15 | + 'ad', |
| 16 | + 'adfs', |
| 17 | + 'auth0', |
| 18 | + 'behance', |
| 19 | + 'bitbucket', |
| 20 | + 'dribbble', |
| 21 | + 'facebook', |
| 22 | + 'github', |
| 23 | + 'google-oauth2', |
| 24 | + 'linkedin', |
| 25 | + 'samlp', |
| 26 | + 'sfdc', |
| 27 | + 'stackoverflow', |
| 28 | + 'twitter' |
| 29 | + ]; |
| 30 | + |
| 31 | + // true if details are being loaded/saved |
| 32 | + $scope.isLoading = false; |
| 33 | + |
| 34 | + /** |
| 35 | + * Close dialog |
| 36 | + */ |
| 37 | + $scope.close = function () { |
| 38 | + $modalInstance.close(); |
| 39 | + }; |
| 40 | + |
| 41 | + /** |
| 42 | + * Load user profile. |
| 43 | + */ |
| 44 | + $scope.loadData = function () { |
| 45 | + $scope.isLoading = true; |
| 46 | + UserService |
| 47 | + .findById($scope.user.id) |
| 48 | + .then(function (data) { |
| 49 | + $scope.user.profile = {}; |
| 50 | + if (data.profile) { |
| 51 | + // we can't have all properties form profile as saving will fail. |
| 52 | + $scope.user.profile = { |
| 53 | + userId: data.profile.userId, |
| 54 | + providerType: data.profile.providerType, |
| 55 | + provider: data.profile.provider |
| 56 | + } |
| 57 | + } |
| 58 | + }) |
| 59 | + .catch(function (error) { |
| 60 | + $alert.error(error.error, $scope); |
| 61 | + }) |
| 62 | + . finally(function () { |
| 63 | + $scope.isLoading = false; |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Create or updates the user SSO profile. |
| 69 | + */ |
| 70 | + $scope.save = function () { |
| 71 | + $scope.isLoading = true; |
| 72 | + UserService |
| 73 | + .createOrUpdateSSOUserLogin($scope.user.id, $scope.user.profile) |
| 74 | + .then(function (data) { |
| 75 | + $scope.close(); |
| 76 | + }) |
| 77 | + .catch(function (error) { |
| 78 | + $alert.error(error.error, $scope); |
| 79 | + }) |
| 80 | + . finally(function () { |
| 81 | + $scope.isLoading = false; |
| 82 | + }); |
| 83 | + } |
| 84 | + |
| 85 | + $scope.loadData(); |
| 86 | + } |
| 87 | +]); |
0 commit comments