Merge pull request #2189 from stianst/master
KEYCLOAK-2430 Load resource bundle before bootstrapping Angular
This commit is contained in:
commit
f28f87b050
2 changed files with 39 additions and 18 deletions
|
@ -831,6 +831,7 @@ additional-grants=Additional Grants
|
||||||
revoke=Revoke
|
revoke=Revoke
|
||||||
new-password=New Password
|
new-password=New Password
|
||||||
password-confirmation=Password Confirmation
|
password-confirmation=Password Confirmation
|
||||||
|
reset-password=Reset Password
|
||||||
credentials.temporary.tooltip=If enabled user is required to change password on next login
|
credentials.temporary.tooltip=If enabled user is required to change password on next login
|
||||||
remove-totp=Remove TOTP
|
remove-totp=Remove TOTP
|
||||||
credentials.remove-totp.tooltip=Remove one time password generator for user.
|
credentials.remove-totp.tooltip=Remove one time password generator for user.
|
||||||
|
|
|
@ -6,6 +6,8 @@ consoleBaseUrl = consoleBaseUrl + "/console";
|
||||||
var configUrl = consoleBaseUrl + "/config";
|
var configUrl = consoleBaseUrl + "/config";
|
||||||
|
|
||||||
var auth = {};
|
var auth = {};
|
||||||
|
var resourceBundle;
|
||||||
|
var locale = 'en';
|
||||||
|
|
||||||
var module = angular.module('keycloak', [ 'keycloak.services', 'keycloak.loaders', 'ui.bootstrap', 'ui.select2', 'angularFileUpload', 'angularTreeview', 'pascalprecht.translate', 'ngCookies', 'ngSanitize']);
|
var module = angular.module('keycloak', [ 'keycloak.services', 'keycloak.loaders', 'ui.bootstrap', 'ui.select2', 'angularFileUpload', 'angularTreeview', 'pascalprecht.translate', 'ngCookies', 'ngSanitize']);
|
||||||
var resourceRequests = 0;
|
var resourceRequests = 0;
|
||||||
|
@ -34,6 +36,25 @@ angular.element(document).ready(function () {
|
||||||
req.send();
|
req.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function loadResourceBundle(success, error) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
req.open('GET', consoleBaseUrl + '/messages.json?lang=' + locale, true);
|
||||||
|
req.setRequestHeader('Accept', 'application/json');
|
||||||
|
|
||||||
|
req.onreadystatechange = function () {
|
||||||
|
if (req.readyState == 4) {
|
||||||
|
if (req.status == 200) {
|
||||||
|
var data = JSON.parse(req.responseText);
|
||||||
|
success && success(data);
|
||||||
|
} else {
|
||||||
|
error && error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.send();
|
||||||
|
}
|
||||||
|
|
||||||
function hasAnyAccess(user) {
|
function hasAnyAccess(user) {
|
||||||
return user && user['realm_access'];
|
return user && user['realm_access'];
|
||||||
}
|
}
|
||||||
|
@ -45,6 +66,10 @@ angular.element(document).ready(function () {
|
||||||
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
|
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
|
||||||
auth.authz = keycloakAuth;
|
auth.authz = keycloakAuth;
|
||||||
|
|
||||||
|
if (auth.authz.idTokenParsed.locale) {
|
||||||
|
locale = auth.authz.idTokenParsed.locale;
|
||||||
|
}
|
||||||
|
|
||||||
auth.refreshPermissions = function(success, error) {
|
auth.refreshPermissions = function(success, error) {
|
||||||
whoAmI(function(data) {
|
whoAmI(function(data) {
|
||||||
auth.user = data;
|
auth.user = data;
|
||||||
|
@ -57,6 +82,9 @@ angular.element(document).ready(function () {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
loadResourceBundle(function(data) {
|
||||||
|
resourceBundle = data;
|
||||||
|
|
||||||
auth.refreshPermissions(function () {
|
auth.refreshPermissions(function () {
|
||||||
module.factory('Auth', function () {
|
module.factory('Auth', function () {
|
||||||
return auth;
|
return auth;
|
||||||
|
@ -66,8 +94,7 @@ angular.element(document).ready(function () {
|
||||||
injector.get('$translate')('consoleTitle').then(function (consoleTitle) {
|
injector.get('$translate')('consoleTitle').then(function (consoleTitle) {
|
||||||
document.title = consoleTitle;
|
document.title = consoleTitle;
|
||||||
});
|
});
|
||||||
}, function() {
|
});
|
||||||
window.location.reload();
|
|
||||||
});
|
});
|
||||||
}).error(function () {
|
}).error(function () {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -99,15 +126,8 @@ module.factory('authInterceptor', function($q, Auth) {
|
||||||
|
|
||||||
module.config(['$translateProvider', function($translateProvider) {
|
module.config(['$translateProvider', function($translateProvider) {
|
||||||
$translateProvider.useSanitizeValueStrategy('sanitizeParameters');
|
$translateProvider.useSanitizeValueStrategy('sanitizeParameters');
|
||||||
|
|
||||||
var locale = auth.authz.idTokenParsed.locale;
|
|
||||||
if (locale !== undefined) {
|
|
||||||
$translateProvider.preferredLanguage(locale);
|
$translateProvider.preferredLanguage(locale);
|
||||||
} else {
|
$translateProvider.translations(locale, resourceBundle);
|
||||||
$translateProvider.preferredLanguage('en');
|
|
||||||
}
|
|
||||||
|
|
||||||
$translateProvider.useUrlLoader('messages.json');
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
module.config([ '$routeProvider', function($routeProvider) {
|
module.config([ '$routeProvider', function($routeProvider) {
|
||||||
|
|
Loading…
Reference in a new issue