diff --git a/docs-parent/TODO b/docs-parent/TODO index 717b181e..7f44b95f 100644 --- a/docs-parent/TODO +++ b/docs-parent/TODO @@ -1,4 +1,3 @@ -- List opened sessions and ability to close them (client) - Display logs (client) - Reordering files and add new files to the end (server) - Tag stats (client/server) diff --git a/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java b/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java index 60c44796..ce152af2 100644 --- a/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java +++ b/docs-web/src/main/java/com/sismics/docs/rest/resource/UserResource.java @@ -548,6 +548,16 @@ public class UserResource extends BaseResource { throw new ForbiddenClientException(); } + // Get the value of the session token + String authToken = null; + if (request.getCookies() != null) { + for (Cookie cookie : request.getCookies()) { + if (TokenBasedSecurityFilter.COOKIE_NAME.equals(cookie.getName())) { + authToken = cookie.getValue(); + } + } + } + JSONObject response = new JSONObject(); List sessions = new ArrayList(); @@ -559,6 +569,7 @@ public class UserResource extends BaseResource { if (authenticationToken.getLastConnectionDate() != null) { session.put("last_connection_date", authenticationToken.getLastConnectionDate().getTime()); } + session.put("current", authenticationToken.getId().equals(authToken)); sessions.add(session); } response.put("sessions", sessions); diff --git a/docs-web/src/main/webapp/index.html b/docs-web/src/main/webapp/index.html index 4402e2b0..bb5b69b8 100644 --- a/docs-web/src/main/webapp/index.html +++ b/docs-web/src/main/webapp/index.html @@ -38,6 +38,9 @@ + + + @@ -57,7 +60,7 @@ diff --git a/docs-web/src/main/webapp/js/app.js b/docs-web/src/main/webapp/js/app.js index 8b512d11..45ffeb67 100644 --- a/docs-web/src/main/webapp/js/app.js +++ b/docs-web/src/main/webapp/js/app.js @@ -31,6 +31,7 @@ var App = angular.module('docs', ['ui.state', 'ui.bootstrap', 'ui.route', 'ui.ke }) .state('settings', { url: '/settings', + abstract: true, views: { 'page': { templateUrl: 'partial/settings.html', @@ -38,6 +39,33 @@ var App = angular.module('docs', ['ui.state', 'ui.bootstrap', 'ui.route', 'ui.ke } } }) + .state('settings.default', { + url: '', + views: { + 'settings': { + templateUrl: 'partial/settings.default.html', + controller: 'SettingsDefault' + } + } + }) + .state('settings.account', { + url: '/account', + views: { + 'settings': { + templateUrl: 'partial/settings.account.html', + controller: 'SettingsAccount' + } + } + }) + .state('settings.session', { + url: '/session', + views: { + 'settings': { + templateUrl: 'partial/settings.session.html', + controller: 'SettingsSession' + } + } + }) .state('document', { url: '/document', abstract: true, diff --git a/docs-web/src/main/webapp/js/controller/Settings.js b/docs-web/src/main/webapp/js/controller/Settings.js index 5bbcdd03..e5cf7026 100644 --- a/docs-web/src/main/webapp/js/controller/Settings.js +++ b/docs-web/src/main/webapp/js/controller/Settings.js @@ -4,25 +4,4 @@ * Settings controller. */ App.controller('Settings', function($scope, Restangular) { - $scope.editUserAlert = false; - - // Alerts - $scope.alerts = []; - - /** - * Close an alert. - */ - $scope.closeAlert = function(index) { - $scope.alerts.splice(index, 1); - }; - - /** - * Edit user. - */ - $scope.editUser = function() { - Restangular.one('user').post('', $scope.user).then(function() { - $scope.user = {}; - $scope.alerts.push({ type: 'success', msg: 'Account successfully updated' }); - }); - }; }); \ No newline at end of file diff --git a/docs-web/src/main/webapp/js/controller/SettingsAccount.js b/docs-web/src/main/webapp/js/controller/SettingsAccount.js new file mode 100644 index 00000000..55c90452 --- /dev/null +++ b/docs-web/src/main/webapp/js/controller/SettingsAccount.js @@ -0,0 +1,28 @@ +'use strict'; + +/** + * Settings account controller. + */ +App.controller('SettingsAccount', function($scope, Restangular) { + $scope.editUserAlert = false; + + // Alerts + $scope.alerts = []; + + /** + * Close an alert. + */ + $scope.closeAlert = function(index) { + $scope.alerts.splice(index, 1); + }; + + /** + * Edit user. + */ + $scope.editUser = function() { + Restangular.one('user').post('', $scope.user).then(function() { + $scope.user = {}; + $scope.alerts.push({ type: 'success', msg: 'Account successfully updated' }); + }); + }; +}); \ No newline at end of file diff --git a/docs-web/src/main/webapp/js/controller/SettingsDefault.js b/docs-web/src/main/webapp/js/controller/SettingsDefault.js new file mode 100644 index 00000000..0e37dbc0 --- /dev/null +++ b/docs-web/src/main/webapp/js/controller/SettingsDefault.js @@ -0,0 +1,7 @@ +'use strict'; + +/** + * Settings default page controller. + */ +App.controller('SettingsDefault', function($scope, Restangular) { +}); \ No newline at end of file diff --git a/docs-web/src/main/webapp/js/controller/SettingsSession.js b/docs-web/src/main/webapp/js/controller/SettingsSession.js new file mode 100644 index 00000000..72f7f267 --- /dev/null +++ b/docs-web/src/main/webapp/js/controller/SettingsSession.js @@ -0,0 +1,26 @@ +'use strict'; + +/** + * Settings session controller. + */ +App.controller('SettingsSession', function($scope, Restangular) { + /** + * Load sessions. + */ + $scope.loadSession = function() { + Restangular.one('user').getList('session').then(function(data) { + $scope.sessions = data.sessions; + }); + }; + + /** + * Clear all active sessions. + */ + $scope.deleteSession = function() { + Restangular.one('user/session').remove().then(function() { + $scope.loadSession(); + }) + }; + + $scope.loadSession(); +}); \ No newline at end of file diff --git a/docs-web/src/main/webapp/partial/settings.account.html b/docs-web/src/main/webapp/partial/settings.account.html new file mode 100644 index 00000000..a1a7fb19 --- /dev/null +++ b/docs-web/src/main/webapp/partial/settings.account.html @@ -0,0 +1,28 @@ +

User account

+
+
+ +
+ + Required + Too short + Too long +
+
+
+ +
+ + Password and password confirmation must match +
+
+
+ +
+
+{{ alert.msg }} \ No newline at end of file diff --git a/docs-web/src/main/webapp/partial/settings.default.html b/docs-web/src/main/webapp/partial/settings.default.html new file mode 100644 index 00000000..52b633af --- /dev/null +++ b/docs-web/src/main/webapp/partial/settings.default.html @@ -0,0 +1 @@ +

Settings

diff --git a/docs-web/src/main/webapp/partial/settings.html b/docs-web/src/main/webapp/partial/settings.html index ad0339f7..e4d12fc1 100644 --- a/docs-web/src/main/webapp/partial/settings.html +++ b/docs-web/src/main/webapp/partial/settings.html @@ -3,39 +3,13 @@
-

User account

-
-
- -
- - Required - Too short - Too long -
-
-
- -
- - Password and password confirmation must match -
-
-
- -
-
- {{ alert.msg }} +
\ No newline at end of file diff --git a/docs-web/src/main/webapp/partial/settings.session.html b/docs-web/src/main/webapp/partial/settings.session.html new file mode 100644 index 00000000..b56ff1df --- /dev/null +++ b/docs-web/src/main/webapp/partial/settings.session.html @@ -0,0 +1,20 @@ +

Opened sessions

+ + + + + + + + + + + + + + + +
Created dateLast connection dateCurrent
{{ session.create_date | date: 'yyyy-MM-dd HH:mm' }}{{ session.last_connection_date | date: 'yyyy-MM-dd HH:mm' }}
+
+ +
\ No newline at end of file