diff --git a/src/app/profile/controller/profile_token_new_controller.js b/src/app/profile/controller/profile_token_new_controller.js new file mode 100644 index 00000000..6dba9671 --- /dev/null +++ b/src/app/profile/controller/profile_token_new_controller.js @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/** + * Issue token controller. + */ +angular.module('sb.profile').controller('ProfileTokenNewController', + function ($q, $log, $scope, $modalInstance, UserToken, user) { + 'use strict'; + + /** + * Flag for the UI to indicate that we're saving. + * + * @type {boolean} + */ + $scope.isSaving = false; + + /** + * The new token. + * + * @type {UserToken} + */ + $scope.token = new UserToken({ + user_id: user.id, + expires_in: 3600 + }); + + /** + * Saves the project group + */ + $scope.save = function () { + $scope.isSaving = true; + $scope.token.$create( + function (token) { + $modalInstance.close(token); + $scope.isSaving = false; + }, + function () { + $scope.isSaving = false; + } + ); + }; + + /** + * Close this modal without saving. + */ + $scope.close = function () { + $modalInstance.dismiss('cancel'); + }; + }); \ No newline at end of file diff --git a/src/app/profile/controller/profile_tokens_controller.js b/src/app/profile/controller/profile_tokens_controller.js new file mode 100644 index 00000000..51846874 --- /dev/null +++ b/src/app/profile/controller/profile_tokens_controller.js @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014 Hewlett-Packard Development Company, L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ + +/** + * User profile controller for all of a user's auth tokens. + */ +angular.module('sb.profile').controller('ProfileTokensController', + function ($scope, UserToken, tokens, $modal) { + 'use strict'; + + $scope.tokens = tokens; + + $scope.deleteToken = function (token) { + token.$delete(function () { + var idx = $scope.tokens.indexOf(token); + if (idx > -1) { + $scope.tokens.splice(idx, 1); + } + }); + }; + + $scope.issueToken = function () { + $modal.open({ + templateUrl: 'app/profile/template/token_new.html', + controller: 'ProfileTokenNewController', + resolve: { + user: function (CurrentUser) { + return CurrentUser.resolve(); + } + } + }).result.then(function (token) { + // On success, append the token. + $scope.tokens.push(token); + }); + }; + }); + + +/** + * Controller for a single token row within the profile token view. + */ +angular.module('sb.profile').controller('ProfileTokenItemController', + function ($scope, AccessToken) { + 'use strict'; + + var now = new Date(); + + // Render the expiration date. + $scope.created = new Date($scope.token.created_at); + $scope.expires = new Date($scope.token.created_at); + $scope.expires.setSeconds($scope.expires.getSeconds() + + $scope.token.expires_in); + + $scope.expired = $scope.expires.getTime() < now.getTime(); + $scope.current = + $scope.token.access_token === AccessToken.getAccessToken(); + }); \ No newline at end of file diff --git a/src/app/profile/module.js b/src/app/profile/module.js index d4f74f89..1e13517e 100644 --- a/src/app/profile/module.js +++ b/src/app/profile/module.js @@ -23,8 +23,8 @@ * @author Michael Krotscheck */ angular.module('sb.profile', - ['sb.services', 'sb.templates', 'sb.auth', 'ui.router', 'ui.bootstrap'] - ) + ['sb.services', 'sb.templates', 'sb.auth', 'ui.router', 'ui.bootstrap'] +) .config(function ($stateProvider, SessionResolver, $urlRouterProvider) { 'use strict'; @@ -40,7 +40,7 @@ angular.module('sb.profile', isLoggedIn: SessionResolver.requireLoggedIn, currentUser: SessionResolver.requireCurrentUser }, - views : { + views: { 'submenu@': { templateUrl: 'app/profile/template/profile_submenu.html' }, @@ -53,5 +53,32 @@ angular.module('sb.profile', url: '/preferences', templateUrl: 'app/profile/template/preferences.html', controller: 'ProfilePreferencesController' + }) + .state('profile.tokens', { + url: '/tokens', + templateUrl: 'app/profile/template/tokens.html', + controller: 'ProfileTokensController', + resolve: { + tokens: function (CurrentUser, UserToken, $q) { + var deferred = $q.defer(); + + CurrentUser.resolve().then( + function (currentUser) { + UserToken.query({ + user_id: currentUser.id + }, function (results) { + deferred.resolve(results); + }, function (error) { + deferred.reject(error); + } + ); + }, + function (error) { + deferred.reject(error); + } + ); + return deferred.promise; + } + } }); }); \ No newline at end of file diff --git a/src/app/profile/template/preferences.html b/src/app/profile/template/preferences.html index f75342dc..d15bf939 100644 --- a/src/app/profile/template/preferences.html +++ b/src/app/profile/template/preferences.html @@ -17,7 +17,7 @@
Authorize and deauthorize authentication tokens + for StoryBoard.
+Token | +Issued | +Expires | ++ |
---|---|---|---|
+ + Current + + + Expired + + + Active + + {{token.access_token}} + | ++ | + | + + | +