Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
Fix Glitch that prevented editing services or routes on first login #281
Browse files Browse the repository at this point in the history
  • Loading branch information
Panagis Tselentis committed Sep 27, 2018
1 parent aecb1d2 commit d522788
Show file tree
Hide file tree
Showing 4 changed files with 337 additions and 336 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion assets/js/app/core/auth/login/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
.login($scope.credentials)
.then(
function successCallback() {
$(".login-form-container").hide()
$(".login-form-container").remove();
$state.go('dashboard');
$scope.busy = false;
},
Expand Down
256 changes: 128 additions & 128 deletions assets/js/app/core/auth/services/AuthService.js
Original file line number Diff line number Diff line change
@@ -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');
}
};
}
])
;
}());
Loading

0 comments on commit d522788

Please sign in to comment.