2015-02-20 23:15:48 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* User admin/settings page.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
2015-02-23 19:23:54 +00:00
|
|
|
pages.create('user-admin', 'user-admin.html', UserAdminCtrl, {
|
|
|
|
'title': 'User Settings'
|
|
|
|
});
|
2015-02-20 23:15:48 +00:00
|
|
|
}]);
|
|
|
|
|
|
|
|
function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, UserService, CookieService, KeyService,
|
|
|
|
$routeParams, $http, UIService, Features, Config) {
|
|
|
|
$scope.Features = Features;
|
|
|
|
|
|
|
|
if ($routeParams['migrate']) {
|
|
|
|
$('#migrateTab').tab('show')
|
|
|
|
}
|
|
|
|
|
|
|
|
UserService.updateUserIn($scope, function(user) {
|
|
|
|
$scope.cuser = jQuery.extend({}, user);
|
|
|
|
|
|
|
|
if ($scope.cuser.logins) {
|
|
|
|
for (var i = 0; i < $scope.cuser.logins.length; i++) {
|
|
|
|
var login = $scope.cuser.logins[i];
|
|
|
|
login.metadata = login.metadata || {};
|
|
|
|
|
|
|
|
if (login.service == 'github') {
|
|
|
|
$scope.hasGithubLogin = true;
|
|
|
|
$scope.githubLogin = login.metadata['service_username'];
|
|
|
|
$scope.githubEndpoint = KeyService['githubEndpoint'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (login.service == 'google') {
|
|
|
|
$scope.hasGoogleLogin = true;
|
|
|
|
$scope.googleLogin = login.metadata['service_username'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.readyForPlan = function() {
|
|
|
|
// Show the subscribe dialog if a plan was requested.
|
|
|
|
return $routeParams['plan'];
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.loading = true;
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
$scope.changePasswordSuccess = false;
|
|
|
|
$scope.changeEmailSent = false;
|
|
|
|
$scope.convertStep = 0;
|
|
|
|
$scope.org = {};
|
|
|
|
$scope.githubRedirectUri = KeyService.githubRedirectUri;
|
|
|
|
$scope.authorizedApps = null;
|
|
|
|
|
|
|
|
$scope.logsShown = 0;
|
|
|
|
$scope.invoicesShown = 0;
|
|
|
|
|
|
|
|
$scope.USER_PATTERN = USER_PATTERN;
|
|
|
|
|
|
|
|
$scope.loadAuthedApps = function() {
|
|
|
|
if ($scope.authorizedApps) { return; }
|
|
|
|
|
|
|
|
ApiService.listUserAuthorizations().then(function(resp) {
|
|
|
|
$scope.authorizedApps = resp['authorizations'];
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteAccess = function(accessTokenInfo) {
|
|
|
|
var params = {
|
|
|
|
'access_token_uuid': accessTokenInfo['uuid']
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.deleteUserAuthorization(null, params).then(function(resp) {
|
|
|
|
$scope.authorizedApps.splice($scope.authorizedApps.indexOf(accessTokenInfo), 1);
|
|
|
|
}, ApiService.errorDisplay('Could not revoke authorization'));
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.loadLogs = function() {
|
|
|
|
if (!$scope.hasPaidBusinessPlan) { return; }
|
|
|
|
$scope.logsShown++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.loadInvoices = function() {
|
|
|
|
$scope.invoicesShown++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.planChanged = function(plan) {
|
|
|
|
$scope.hasPaidPlan = plan && plan.price > 0;
|
|
|
|
$scope.hasPaidBusinessPlan = PlanService.isOrgCompatible(plan) && plan.price > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showConvertForm = function() {
|
|
|
|
if (Features.BILLING) {
|
|
|
|
PlanService.getMatchingBusinessPlan(function(plan) {
|
|
|
|
$scope.org.plan = plan;
|
|
|
|
});
|
|
|
|
|
|
|
|
PlanService.getPlans(function(plans) {
|
|
|
|
$scope.orgPlans = plans;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.convertStep = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.convertToOrg = function() {
|
|
|
|
$('#reallyconvertModal').modal({});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.reallyConvert = function() {
|
|
|
|
if (Config.AUTHENTICATION_TYPE != 'Database') { return; }
|
|
|
|
|
|
|
|
$scope.loading = true;
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
'adminUser': $scope.org.adminUser,
|
|
|
|
'adminPassword': $scope.org.adminPassword,
|
|
|
|
'plan': $scope.org.plan ? $scope.org.plan.stripeId : ''
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.convertUserToOrganization(data).then(function(resp) {
|
|
|
|
CookieService.putPermanent('quay.namespace', $scope.cuser.username);
|
|
|
|
UserService.load();
|
|
|
|
$location.path('/');
|
|
|
|
}, function(resp) {
|
|
|
|
$scope.loading = false;
|
|
|
|
if (resp.data.reason == 'invaliduser') {
|
|
|
|
$('#invalidadminModal').modal({});
|
|
|
|
} else {
|
|
|
|
$('#cannotconvertModal').modal({});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changeUsername = function() {
|
|
|
|
UserService.load();
|
|
|
|
|
|
|
|
$scope.updatingUser = true;
|
|
|
|
|
|
|
|
ApiService.changeUserDetails($scope.cuser).then(function() {
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
|
|
|
|
// Reset the form.
|
|
|
|
delete $scope.cuser['username'];
|
|
|
|
|
|
|
|
$scope.changeUsernameForm.$setPristine();
|
|
|
|
}, function(result) {
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
UIService.showFormError('#changeUsernameForm', result);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changeEmail = function() {
|
|
|
|
UIService.hidePopover('#changeEmailForm');
|
|
|
|
|
|
|
|
$scope.updatingUser = true;
|
|
|
|
$scope.changeEmailSent = false;
|
|
|
|
|
|
|
|
ApiService.changeUserDetails($scope.cuser).then(function() {
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
$scope.changeEmailSent = true;
|
|
|
|
$scope.sentEmail = $scope.cuser.email;
|
|
|
|
|
|
|
|
// Reset the form.
|
|
|
|
delete $scope.cuser['email'];
|
|
|
|
|
|
|
|
$scope.changeEmailForm.$setPristine();
|
|
|
|
}, function(result) {
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
UIService.showFormError('#changeEmailForm', result);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changePassword = function() {
|
|
|
|
UIService.hidePopover('#changePasswordForm');
|
|
|
|
|
|
|
|
$scope.updatingUser = true;
|
|
|
|
$scope.changePasswordSuccess = false;
|
|
|
|
|
|
|
|
ApiService.changeUserDetails($scope.cuser).then(function(resp) {
|
|
|
|
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
$scope.changePasswordSuccess = true;
|
|
|
|
|
|
|
|
// Reset the form
|
|
|
|
delete $scope.cuser['password']
|
|
|
|
delete $scope.cuser['repeatPassword']
|
|
|
|
|
|
|
|
$scope.changePasswordForm.$setPristine();
|
|
|
|
|
|
|
|
// Reload the user.
|
|
|
|
UserService.load();
|
|
|
|
}, function(result) {
|
|
|
|
$scope.updatingUser = false;
|
|
|
|
UIService.showFormError('#changePasswordForm', result);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.detachExternalLogin = function(kind) {
|
|
|
|
var params = {
|
|
|
|
'servicename': kind
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.detachExternalLogin(null, params).then(function() {
|
|
|
|
$scope.hasGithubLogin = false;
|
|
|
|
$scope.hasGoogleLogin = false;
|
|
|
|
UserService.load();
|
|
|
|
}, ApiService.errorDisplay('Count not detach service'));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|