Redirect to a previous page after login
This commit is contained in:
parent
f9088daccd
commit
75bb8cc6b2
@ -110,24 +110,34 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time
|
|||||||
lastPublicDashboardId = null;
|
lastPublicDashboardId = null;
|
||||||
userTokenAccessEnabled = false;
|
userTokenAccessEnabled = false;
|
||||||
allowedDashboardIds = [];
|
allowedDashboardIds = [];
|
||||||
|
var deferred = $q.defer();
|
||||||
if (!jwtToken) {
|
if (!jwtToken) {
|
||||||
clearTokenData();
|
clearTokenData();
|
||||||
if (notify) {
|
if (notify) {
|
||||||
$rootScope.$broadcast('unauthenticated', doLogout);
|
$rootScope.$broadcast('unauthenticated', doLogout);
|
||||||
|
deferred.reject();
|
||||||
}
|
}
|
||||||
|
deferred.resolve();
|
||||||
} else {
|
} else {
|
||||||
updateAndValidateToken(jwtToken, 'jwt_token', true);
|
updateAndValidateToken(jwtToken, 'jwt_token', true);
|
||||||
updateAndValidateToken(refreshToken, 'refresh_token', true);
|
updateAndValidateToken(refreshToken, 'refresh_token', true);
|
||||||
if (notify) {
|
if (notify) {
|
||||||
loadUser(false).then(function success() {
|
loadUser(false).then(function success() {
|
||||||
$rootScope.$broadcast('authenticated');
|
$rootScope.$broadcast('authenticated');
|
||||||
|
deferred.resolve();
|
||||||
}, function fail() {
|
}, function fail() {
|
||||||
$rootScope.$broadcast('unauthenticated');
|
$rootScope.$broadcast('unauthenticated');
|
||||||
|
deferred.reject();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
loadUser(false);
|
loadUser(false).then(function success() {
|
||||||
|
deferred.resolve();
|
||||||
|
}, function fail() {
|
||||||
|
deferred.reject();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAuthenticated() {
|
function isAuthenticated() {
|
||||||
|
|||||||
@ -27,7 +27,6 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
|||||||
// ie11 fix
|
// ie11 fix
|
||||||
}
|
}
|
||||||
|
|
||||||
var unauthorizedDialog = null;
|
|
||||||
var forbiddenDialog = null;
|
var forbiddenDialog = null;
|
||||||
|
|
||||||
$rootScope.iframeMode = false;
|
$rootScope.iframeMode = false;
|
||||||
@ -125,11 +124,17 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
|||||||
reloadUserFromPublicId();
|
reloadUserFromPublicId();
|
||||||
} else if (to.module === 'private') {
|
} else if (to.module === 'private') {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
/*
|
||||||
if (to.url === '/home' || to.url === '/') {
|
if (to.url === '/home' || to.url === '/') {
|
||||||
$state.go('login', params);
|
$state.go('login', params);
|
||||||
} else {
|
} else {
|
||||||
showUnauthorizedDialog();
|
showUnauthorizedDialog();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
var redirectParams = {};
|
||||||
|
redirectParams.toName = to.name;
|
||||||
|
redirectParams.params = params;
|
||||||
|
$state.go('login', redirectParams);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -159,31 +164,6 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
|||||||
userService.gotoDefaultPlace(params);
|
userService.gotoDefaultPlace(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showUnauthorizedDialog() {
|
|
||||||
if (unauthorizedDialog === null) {
|
|
||||||
$translate(['access.unauthorized-access',
|
|
||||||
'access.unauthorized-access-text',
|
|
||||||
'access.unauthorized',
|
|
||||||
'action.cancel',
|
|
||||||
'action.sign-in']).then(function (translations) {
|
|
||||||
if (unauthorizedDialog === null) {
|
|
||||||
unauthorizedDialog = $mdDialog.confirm()
|
|
||||||
.title(translations['access.unauthorized-access'])
|
|
||||||
.textContent(translations['access.unauthorized-access-text'])
|
|
||||||
.ariaLabel(translations['access.unauthorized'])
|
|
||||||
.cancel(translations['action.cancel'])
|
|
||||||
.ok(translations['action.sign-in']);
|
|
||||||
$mdDialog.show(unauthorizedDialog).then(function () {
|
|
||||||
unauthorizedDialog = null;
|
|
||||||
$state.go('login');
|
|
||||||
}, function () {
|
|
||||||
unauthorizedDialog = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showForbiddenDialog() {
|
function showForbiddenDialog() {
|
||||||
if (forbiddenDialog === null) {
|
if (forbiddenDialog === null) {
|
||||||
$translate(['access.access-forbidden',
|
$translate(['access.access-forbidden',
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import logoSvg from '../../svg/logo_title_white.svg';
|
|||||||
/* eslint-enable import/no-unresolved, import/default */
|
/* eslint-enable import/no-unresolved, import/default */
|
||||||
|
|
||||||
/*@ngInject*/
|
/*@ngInject*/
|
||||||
export default function LoginController(toast, loginService, userService/*, $rootScope, $log, $translate*/) {
|
export default function LoginController(toast, loginService, userService, $state, $stateParams, $rootScope) {
|
||||||
var vm = this;
|
var vm = this;
|
||||||
|
|
||||||
vm.logoSvg = logoSvg;
|
vm.logoSvg = logoSvg;
|
||||||
@ -30,13 +30,22 @@ export default function LoginController(toast, loginService, userService/*, $roo
|
|||||||
password: ''
|
password: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
vm.params = $stateParams;
|
||||||
vm.login = login;
|
vm.login = login;
|
||||||
|
|
||||||
function doLogin() {
|
function doLogin() {
|
||||||
loginService.login(vm.user).then(function success(response) {
|
loginService.login(vm.user).then(function success(response) {
|
||||||
var token = response.data.token;
|
var token = response.data.token;
|
||||||
var refreshToken = response.data.refreshToken;
|
var refreshToken = response.data.refreshToken;
|
||||||
userService.setUserFromJwtToken(token, refreshToken, true);
|
userService.setUserFromJwtToken(token, refreshToken, true).then(function() {
|
||||||
|
if (vm.params.toName && vm.params.toName !== 'login') {
|
||||||
|
if (vm.params.toName == 'home.dashboards.dashboard' && $rootScope.forceFullscreen) {
|
||||||
|
$state.go('dashboard', vm.params.params)
|
||||||
|
} else {
|
||||||
|
$state.go(vm.params.toName, vm.params.params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}, function fail(/*response*/) {
|
}, function fail(/*response*/) {
|
||||||
/*if (response && response.data && response.data.message) {
|
/*if (response && response.data && response.data.message) {
|
||||||
toast.showError(response.data.message);
|
toast.showError(response.data.message);
|
||||||
|
|||||||
@ -27,6 +27,10 @@ export default function LoginRoutes($stateProvider) {
|
|||||||
$stateProvider.state('login', {
|
$stateProvider.state('login', {
|
||||||
url: '/login',
|
url: '/login',
|
||||||
module: 'public',
|
module: 'public',
|
||||||
|
params: {
|
||||||
|
params: null,
|
||||||
|
toName: null
|
||||||
|
},
|
||||||
views: {
|
views: {
|
||||||
"@": {
|
"@": {
|
||||||
controller: 'LoginController',
|
controller: 'LoginController',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user