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

Commit d522788

Browse files
author
Panagis Tselentis
committed
Fix Glitch that prevented editing services or routes on first login #281
1 parent aecb1d2 commit d522788

File tree

4 files changed

+337
-336
lines changed

4 files changed

+337
-336
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
All notable changes to this project will be documented in this file.
44
## [0.12.3](https://github.com/pantsel/konga/releases/tag/0.12.3) - 26-09-2018
55
* **[Fix]** Solved some routing issues when running Konga behind a reverse proxy at a sub-path. [#278](https://github.com/pantsel/konga/issues/278)
6+
* **[Fix]** Fix Glitch that prevented editing services or routes on first login. [#281](https://github.com/pantsel/konga/issues/281)
67
* Other minor issues
78

89
## [0.12.2](https://github.com/pantsel/konga/releases/tag/0.12.2) - 22-08-2018

assets/js/app/core/auth/login/login.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
.login($scope.credentials)
5252
.then(
5353
function successCallback() {
54-
$(".login-form-container").hide()
54+
$(".login-form-container").remove();
5555
$state.go('dashboard');
5656
$scope.busy = false;
5757
},
Lines changed: 128 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
11
(function () {
2-
'use strict';
3-
4-
angular.module('frontend.core.auth.services')
5-
.factory('AuthService', [
6-
'$http', '$state', '$localStorage', '$rootScope',
7-
'AccessLevels', 'BackendConfig', 'MessageService',
8-
function factory($http, $state, $localStorage, $rootScope,
9-
AccessLevels, BackendConfig, MessageService) {
10-
return {
11-
/**
12-
* Method to authorize current user with given access level in application.
13-
*
14-
* @param {Number} accessLevel Access level to check
15-
*
16-
* @returns {Boolean}
17-
*/
18-
authorize: function authorize(accessLevel) {
19-
20-
21-
if (accessLevel === AccessLevels.user) {
22-
return this.isAuthenticated();
23-
} else if (accessLevel === AccessLevels.admin) {
24-
return this.isAuthenticated() && Boolean($localStorage.credentials.user.admin);
25-
} else {
26-
return accessLevel === AccessLevels.anon;
27-
}
28-
},
29-
30-
hasPermission: function (context, action) {
31-
32-
// If user is admin or context is not a permissions Object key, grant permission
33-
if (($localStorage.credentials && $localStorage.credentials.user.admin)
34-
|| Object.keys(KONGA_CONFIG.user_permissions).indexOf(context) < 0) {
35-
return true;
36-
}
37-
38-
action = action || 'read'; // Default action is 'read'
39-
40-
/**
41-
* ======================================================================================
42-
* Monkey patches.
43-
* ======================================================================================
44-
*/
45-
46-
// Transform 'edit' action to 'update'
47-
// because permissions object complies to CRUD naming.
48-
// ToDo : Change 'edit' route uri segments to 'update'
49-
if(action === 'edit') {
50-
action = 'update';
51-
}
52-
53-
/**
54-
* ======================================================================================
55-
* End monkey patches.
56-
* ======================================================================================
57-
*/
58-
59-
return KONGA_CONFIG.user_permissions[context]
60-
&& KONGA_CONFIG.user_permissions[context][action] === true
61-
62-
},
63-
64-
/**
65-
* Method to check if current user is authenticated or not. This will just
66-
* simply call 'Storage' service 'get' method and returns it results.
67-
*
68-
* @returns {Boolean}
69-
*/
70-
isAuthenticated: function isAuthenticated() {
71-
return Boolean($localStorage.credentials);
72-
},
73-
74-
75-
/**
76-
* Method to check if current user is an admin or not.
77-
*
78-
* @returns {Boolean}
79-
*/
80-
isAdmin : function isAdmin() {
81-
82-
return $localStorage.credentials && $localStorage.credentials.user && $localStorage.credentials.user.admin;
83-
84-
},
85-
86-
87-
token: function token() {
88-
return $localStorage.credentials ? $localStorage.credentials.token : null;
89-
},
90-
91-
/**
92-
* Method make login request to backend server. Successfully response from
93-
* server contains user data and JWT token as in JSON object. After successful
94-
* authentication method will store user data and JWT token to local storage
95-
* where those can be used.
96-
*
97-
* @param {*} credentials
98-
*
99-
* @returns {*|Promise}
100-
*/
101-
login: function login(credentials) {
102-
return $http
103-
.post('login', credentials, {withCredentials: true})
104-
.then(
105-
function (response) {
106-
MessageService.success('You have logged in successfully!');
107-
$localStorage.credentials = response.data;
108-
$rootScope.$broadcast('user.login', $localStorage.credentials)
109-
}
110-
)
111-
;
112-
},
113-
114-
/**
115-
* The backend doesn't care about actual user logout, just delete the token
116-
* and you're good to go.
117-
*
118-
* Question still: Should we make logout process to backend side?
119-
*/
120-
logout: function logout() {
121-
$localStorage.$reset();
122-
123-
MessageService.success('You have logged out.');
124-
125-
$state.go('auth.login');
126-
}
127-
};
2+
'use strict';
3+
4+
angular.module('frontend.core.auth.services')
5+
.factory('AuthService', [
6+
'$http', '$state', '$localStorage', '$rootScope',
7+
'AccessLevels', 'BackendConfig', 'MessageService',
8+
function factory($http, $state, $localStorage, $rootScope,
9+
AccessLevels, BackendConfig, MessageService) {
10+
return {
11+
/**
12+
* Method to authorize current user with given access level in application.
13+
*
14+
* @param {Number} accessLevel Access level to check
15+
*
16+
* @returns {Boolean}
17+
*/
18+
authorize: function authorize(accessLevel) {
19+
20+
21+
if (accessLevel === AccessLevels.user) {
22+
return this.isAuthenticated();
23+
} else if (accessLevel === AccessLevels.admin) {
24+
return this.isAuthenticated() && Boolean($localStorage.credentials.user.admin);
25+
} else {
26+
return accessLevel === AccessLevels.anon;
12827
}
129-
])
130-
;
28+
},
29+
30+
hasPermission: function (context, action) {
31+
32+
// If user is admin or context is not a permissions Object key, grant permission
33+
if (($localStorage.credentials && $localStorage.credentials.user.admin)
34+
|| Object.keys(KONGA_CONFIG.user_permissions).indexOf(context) < 0) {
35+
return true;
36+
}
37+
38+
action = action || 'read'; // Default action is 'read'
39+
40+
/**
41+
* ======================================================================================
42+
* Monkey patches.
43+
* ======================================================================================
44+
*/
45+
46+
// Transform 'edit' action to 'update'
47+
// because permissions object complies to CRUD naming.
48+
// ToDo : Change 'edit' route uri segments to 'update'
49+
if (action === 'edit') {
50+
action = 'update';
51+
}
52+
53+
/**
54+
* ======================================================================================
55+
* End monkey patches.
56+
* ======================================================================================
57+
*/
58+
59+
return KONGA_CONFIG.user_permissions[context]
60+
&& KONGA_CONFIG.user_permissions[context][action] === true
61+
62+
},
63+
64+
/**
65+
* Method to check if current user is authenticated or not. This will just
66+
* simply call 'Storage' service 'get' method and returns it results.
67+
*
68+
* @returns {Boolean}
69+
*/
70+
isAuthenticated: function isAuthenticated() {
71+
return Boolean($localStorage.credentials);
72+
},
73+
74+
75+
/**
76+
* Method to check if current user is an admin or not.
77+
*
78+
* @returns {Boolean}
79+
*/
80+
isAdmin: function isAdmin() {
81+
82+
return $localStorage.credentials && $localStorage.credentials.user && $localStorage.credentials.user.admin;
83+
84+
},
85+
86+
87+
token: function token() {
88+
return $localStorage.credentials ? $localStorage.credentials.token : null;
89+
},
90+
91+
/**
92+
* Method make login request to backend server. Successfully response from
93+
* server contains user data and JWT token as in JSON object. After successful
94+
* authentication method will store user data and JWT token to local storage
95+
* where those can be used.
96+
*
97+
* @param {*} credentials
98+
*
99+
* @returns {*|Promise}
100+
*/
101+
login: function login(credentials) {
102+
return $http
103+
.post('login', credentials, {withCredentials: true})
104+
.then(
105+
function (response) {
106+
MessageService.success('You have logged in successfully!');
107+
$localStorage.credentials = response.data;
108+
$rootScope.$broadcast('user.login', $localStorage.credentials)
109+
$rootScope.user = response.data.user;
110+
}
111+
)
112+
;
113+
},
114+
115+
/**
116+
* The backend doesn't care about actual user logout, just delete the token
117+
* and you're good to go.
118+
*
119+
* Question still: Should we make logout process to backend side?
120+
*/
121+
logout: function logout() {
122+
$localStorage.$reset();
123+
MessageService.success('You have logged out.');
124+
$rootScope.user = null;
125+
$state.go('auth.login');
126+
}
127+
};
128+
}
129+
])
130+
;
131131
}());

0 commit comments

Comments
 (0)