From d52278847adb570eef2844f2cdb958570eeb554b Mon Sep 17 00:00:00 2001 From: Panagis Tselentis Date: Thu, 27 Sep 2018 15:48:44 +0300 Subject: [PATCH] Fix Glitch that prevented editing services or routes on first login #281 --- CHANGELOG.md | 1 + assets/js/app/core/auth/login/login.js | 2 +- .../js/app/core/auth/services/AuthService.js | 256 +++++------ views/layout.ejs | 414 +++++++++--------- 4 files changed, 337 insertions(+), 336 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 068f4ce11..d05997946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. ## [0.12.3](https://github.com/pantsel/konga/releases/tag/0.12.3) - 26-09-2018 * **[Fix]** Solved some routing issues when running Konga behind a reverse proxy at a sub-path. [#278](https://github.com/pantsel/konga/issues/278) +* **[Fix]** Fix Glitch that prevented editing services or routes on first login. [#281](https://github.com/pantsel/konga/issues/281) * Other minor issues ## [0.12.2](https://github.com/pantsel/konga/releases/tag/0.12.2) - 22-08-2018 diff --git a/assets/js/app/core/auth/login/login.js b/assets/js/app/core/auth/login/login.js index 9f292ac65..dc4480965 100644 --- a/assets/js/app/core/auth/login/login.js +++ b/assets/js/app/core/auth/login/login.js @@ -51,7 +51,7 @@ .login($scope.credentials) .then( function successCallback() { - $(".login-form-container").hide() + $(".login-form-container").remove(); $state.go('dashboard'); $scope.busy = false; }, diff --git a/assets/js/app/core/auth/services/AuthService.js b/assets/js/app/core/auth/services/AuthService.js index bc22f2791..797f5d9a7 100644 --- a/assets/js/app/core/auth/services/AuthService.js +++ b/assets/js/app/core/auth/services/AuthService.js @@ -1,131 +1,131 @@ (function () { - 'use strict'; - - angular.module('frontend.core.auth.services') - .factory('AuthService', [ - '$http', '$state', '$localStorage', '$rootScope', - 'AccessLevels', 'BackendConfig', 'MessageService', - function factory($http, $state, $localStorage, $rootScope, - AccessLevels, BackendConfig, MessageService) { - return { - /** - * Method to authorize current user with given access level in application. - * - * @param {Number} accessLevel Access level to check - * - * @returns {Boolean} - */ - authorize: function authorize(accessLevel) { - - - if (accessLevel === AccessLevels.user) { - return this.isAuthenticated(); - } else if (accessLevel === AccessLevels.admin) { - return this.isAuthenticated() && Boolean($localStorage.credentials.user.admin); - } else { - return accessLevel === AccessLevels.anon; - } - }, - - hasPermission: function (context, action) { - - // If user is admin or context is not a permissions Object key, grant permission - if (($localStorage.credentials && $localStorage.credentials.user.admin) - || Object.keys(KONGA_CONFIG.user_permissions).indexOf(context) < 0) { - return true; - } - - action = action || 'read'; // Default action is 'read' - - /** - * ====================================================================================== - * Monkey patches. - * ====================================================================================== - */ - - // Transform 'edit' action to 'update' - // because permissions object complies to CRUD naming. - // ToDo : Change 'edit' route uri segments to 'update' - if(action === 'edit') { - action = 'update'; - } - - /** - * ====================================================================================== - * End monkey patches. - * ====================================================================================== - */ - - return KONGA_CONFIG.user_permissions[context] - && KONGA_CONFIG.user_permissions[context][action] === true - - }, - - /** - * Method to check if current user is authenticated or not. This will just - * simply call 'Storage' service 'get' method and returns it results. - * - * @returns {Boolean} - */ - isAuthenticated: function isAuthenticated() { - return Boolean($localStorage.credentials); - }, - - - /** - * Method to check if current user is an admin or not. - * - * @returns {Boolean} - */ - isAdmin : function isAdmin() { - - return $localStorage.credentials && $localStorage.credentials.user && $localStorage.credentials.user.admin; - - }, - - - token: function token() { - return $localStorage.credentials ? $localStorage.credentials.token : null; - }, - - /** - * Method make login request to backend server. Successfully response from - * server contains user data and JWT token as in JSON object. After successful - * authentication method will store user data and JWT token to local storage - * where those can be used. - * - * @param {*} credentials - * - * @returns {*|Promise} - */ - login: function login(credentials) { - return $http - .post('login', credentials, {withCredentials: true}) - .then( - function (response) { - MessageService.success('You have logged in successfully!'); - $localStorage.credentials = response.data; - $rootScope.$broadcast('user.login', $localStorage.credentials) - } - ) - ; - }, - - /** - * The backend doesn't care about actual user logout, just delete the token - * and you're good to go. - * - * Question still: Should we make logout process to backend side? - */ - logout: function logout() { - $localStorage.$reset(); - - MessageService.success('You have logged out.'); - - $state.go('auth.login'); - } - }; + 'use strict'; + + angular.module('frontend.core.auth.services') + .factory('AuthService', [ + '$http', '$state', '$localStorage', '$rootScope', + 'AccessLevels', 'BackendConfig', 'MessageService', + function factory($http, $state, $localStorage, $rootScope, + AccessLevels, BackendConfig, MessageService) { + return { + /** + * Method to authorize current user with given access level in application. + * + * @param {Number} accessLevel Access level to check + * + * @returns {Boolean} + */ + authorize: function authorize(accessLevel) { + + + if (accessLevel === AccessLevels.user) { + return this.isAuthenticated(); + } else if (accessLevel === AccessLevels.admin) { + return this.isAuthenticated() && Boolean($localStorage.credentials.user.admin); + } else { + return accessLevel === AccessLevels.anon; } - ]) - ; + }, + + hasPermission: function (context, action) { + + // If user is admin or context is not a permissions Object key, grant permission + if (($localStorage.credentials && $localStorage.credentials.user.admin) + || Object.keys(KONGA_CONFIG.user_permissions).indexOf(context) < 0) { + return true; + } + + action = action || 'read'; // Default action is 'read' + + /** + * ====================================================================================== + * Monkey patches. + * ====================================================================================== + */ + + // Transform 'edit' action to 'update' + // because permissions object complies to CRUD naming. + // ToDo : Change 'edit' route uri segments to 'update' + if (action === 'edit') { + action = 'update'; + } + + /** + * ====================================================================================== + * End monkey patches. + * ====================================================================================== + */ + + return KONGA_CONFIG.user_permissions[context] + && KONGA_CONFIG.user_permissions[context][action] === true + + }, + + /** + * Method to check if current user is authenticated or not. This will just + * simply call 'Storage' service 'get' method and returns it results. + * + * @returns {Boolean} + */ + isAuthenticated: function isAuthenticated() { + return Boolean($localStorage.credentials); + }, + + + /** + * Method to check if current user is an admin or not. + * + * @returns {Boolean} + */ + isAdmin: function isAdmin() { + + return $localStorage.credentials && $localStorage.credentials.user && $localStorage.credentials.user.admin; + + }, + + + token: function token() { + return $localStorage.credentials ? $localStorage.credentials.token : null; + }, + + /** + * Method make login request to backend server. Successfully response from + * server contains user data and JWT token as in JSON object. After successful + * authentication method will store user data and JWT token to local storage + * where those can be used. + * + * @param {*} credentials + * + * @returns {*|Promise} + */ + login: function login(credentials) { + return $http + .post('login', credentials, {withCredentials: true}) + .then( + function (response) { + MessageService.success('You have logged in successfully!'); + $localStorage.credentials = response.data; + $rootScope.$broadcast('user.login', $localStorage.credentials) + $rootScope.user = response.data.user; + } + ) + ; + }, + + /** + * The backend doesn't care about actual user logout, just delete the token + * and you're good to go. + * + * Question still: Should we make logout process to backend side? + */ + logout: function logout() { + $localStorage.$reset(); + MessageService.success('You have logged out.'); + $rootScope.user = null; + $state.go('auth.login'); + } + }; + } + ]) + ; }()); diff --git a/views/layout.ejs b/views/layout.ejs index 77c2dccdf..8813fc1e9 100644 --- a/views/layout.ejs +++ b/views/layout.ejs @@ -30,15 +30,15 @@ - - - - - - - - - + + + + + + + + + @@ -98,204 +98,204 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +