3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
21 .factory('PubKeys', PubKeys);
23 PubKeys.$inject = ['$resource', 'testapiApiUrl'];
26 * This is a provider for the user's uploaded public keys.
28 function PubKeys($resource, testapiApiUrl) {
29 return $resource(testapiApiUrl + '/user/pubkeys/:id', null, null);
34 .controller('ProfileController', ProfileController);
36 ProfileController.$inject = [
37 '$scope', '$http', 'testapiApiUrl', 'PubKeys',
38 '$uibModal', 'raiseAlert', '$state'
42 * TestAPI Profile Controller
43 * This controller handles user's profile page, where a user can view
44 * account-specific information.
46 function ProfileController($scope, $http, testapiApiUrl,
47 PubKeys, $uibModal, raiseAlert, $state) {
51 ctrl.updatePubKeys = updatePubKeys;
52 ctrl.openImportPubKeyModal = openImportPubKeyModal;
53 ctrl.openShowPubKeyModal = openShowPubKeyModal;
55 // Must be authenticated to view this page.
56 if (!$scope.auth.isAuthenticated) {
61 * This function will fetch all the user's public keys from the
62 * server and store them in an array.
64 function updatePubKeys() {
65 var keys = PubKeys.query(function() {
67 angular.forEach(keys, function (key) {
72 key.pubkey.slice(0, 10),
77 'comment': key.comment
84 * This function will open the modal that will give the user a form
85 * for importing a public key.
87 function openImportPubKeyModal() {
89 templateUrl: '/components/profile/importPubKeyModal.html',
92 controller: 'ImportPubKeyModalController as modal'
93 }).result.finally(function() {
99 * This function will open the modal that will give the full
100 * information regarding a specific public key.
101 * @param {Object} pubKey resource
103 function openShowPubKeyModal(pubKey) {
105 templateUrl: '/components/profile/showPubKeyModal.html',
107 windowClass: 'modal',
108 controller: 'ShowPubKeyModalController as modal',
114 }).result.finally(function() {
115 ctrl.updatePubKeys();
119 ctrl.authRequest = $scope.auth.doSignCheck().then(ctrl.updatePubKeys);
123 .module('testapiApp')
124 .controller('ImportPubKeyModalController', ImportPubKeyModalController);
126 ImportPubKeyModalController.$inject = [
127 '$uibModalInstance', 'PubKeys', 'raiseAlert'
131 * Import Pub Key Modal Controller
132 * This controller is for the modal that appears if a user wants to import
135 function ImportPubKeyModalController($uibModalInstance,
136 PubKeys, raiseAlert) {
140 ctrl.importPubKey = importPubKey;
141 ctrl.cancel = cancel;
144 * This function will save a new public key resource to the API server.
146 function importPubKey() {
147 var newPubKey = new PubKeys(
148 {raw_key: ctrl.raw_key, self_signature: ctrl.self_signature}
151 function(newPubKey_) {
152 raiseAlert('success', '', 'Public key saved successfully');
153 $uibModalInstance.close(newPubKey_);
157 httpResp.statusText, httpResp.data.title);
164 * This function will dismiss the modal.
167 $uibModalInstance.dismiss('cancel');
172 .module('testapiApp')
173 .controller('ShowPubKeyModalController', ShowPubKeyModalController);
175 ShowPubKeyModalController.$inject = [
176 '$uibModalInstance', 'raiseAlert', 'pubKey'
180 * Show Pub Key Modal Controller
181 * This controller is for the modal that appears if a user wants to see the
182 * full details of one of their public keys.
184 function ShowPubKeyModalController($uibModalInstance, raiseAlert, pubKey) {
187 ctrl.deletePubKey = deletePubKey;
188 ctrl.cancel = cancel;
190 ctrl.pubKey = pubKey.resource;
191 ctrl.rawKey = [pubKey.format, pubKey.pubkey, pubKey.comment].join('\n');
194 * This function will delete a public key resource.
196 function deletePubKey() {
198 {id: ctrl.pubKey.id},
200 raiseAlert('success',
201 '', 'Public key deleted successfully');
202 $uibModalInstance.close(ctrl.pubKey.id);
206 httpResp.statusText, httpResp.data.title);
213 * This method will dismiss the modal.
216 $uibModalInstance.dismiss('cancel');