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;
|
||||
userTokenAccessEnabled = false;
|
||||
allowedDashboardIds = [];
|
||||
var deferred = $q.defer();
|
||||
if (!jwtToken) {
|
||||
clearTokenData();
|
||||
if (notify) {
|
||||
$rootScope.$broadcast('unauthenticated', doLogout);
|
||||
deferred.reject();
|
||||
}
|
||||
deferred.resolve();
|
||||
} else {
|
||||
updateAndValidateToken(jwtToken, 'jwt_token', true);
|
||||
updateAndValidateToken(refreshToken, 'refresh_token', true);
|
||||
if (notify) {
|
||||
loadUser(false).then(function success() {
|
||||
$rootScope.$broadcast('authenticated');
|
||||
deferred.resolve();
|
||||
}, function fail() {
|
||||
$rootScope.$broadcast('unauthenticated');
|
||||
deferred.reject();
|
||||
});
|
||||
} else {
|
||||
loadUser(false);
|
||||
loadUser(false).then(function success() {
|
||||
deferred.resolve();
|
||||
}, function fail() {
|
||||
deferred.reject();
|
||||
});
|
||||
}
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function isAuthenticated() {
|
||||
|
||||
@ -27,7 +27,6 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
||||
// ie11 fix
|
||||
}
|
||||
|
||||
var unauthorizedDialog = null;
|
||||
var forbiddenDialog = null;
|
||||
|
||||
$rootScope.iframeMode = false;
|
||||
@ -125,11 +124,17 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
||||
reloadUserFromPublicId();
|
||||
} else if (to.module === 'private') {
|
||||
evt.preventDefault();
|
||||
/*
|
||||
if (to.url === '/home' || to.url === '/') {
|
||||
$state.go('login', params);
|
||||
} else {
|
||||
showUnauthorizedDialog();
|
||||
}
|
||||
*/
|
||||
var redirectParams = {};
|
||||
redirectParams.toName = to.name;
|
||||
redirectParams.params = params;
|
||||
$state.go('login', redirectParams);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -159,31 +164,6 @@ export default function AppRun($rootScope, $window, $injector, $location, $log,
|
||||
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() {
|
||||
if (forbiddenDialog === null) {
|
||||
$translate(['access.access-forbidden',
|
||||
|
||||
@ -20,7 +20,7 @@ import logoSvg from '../../svg/logo_title_white.svg';
|
||||
/* eslint-enable import/no-unresolved, import/default */
|
||||
|
||||
/*@ngInject*/
|
||||
export default function LoginController(toast, loginService, userService/*, $rootScope, $log, $translate*/) {
|
||||
export default function LoginController(toast, loginService, userService, $state, $stateParams, $rootScope) {
|
||||
var vm = this;
|
||||
|
||||
vm.logoSvg = logoSvg;
|
||||
@ -30,13 +30,22 @@ export default function LoginController(toast, loginService, userService/*, $roo
|
||||
password: ''
|
||||
};
|
||||
|
||||
vm.params = $stateParams;
|
||||
vm.login = login;
|
||||
|
||||
function doLogin() {
|
||||
loginService.login(vm.user).then(function success(response) {
|
||||
var token = response.data.token;
|
||||
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*/) {
|
||||
/*if (response && response.data && response.data.message) {
|
||||
toast.showError(response.data.message);
|
||||
|
||||
@ -27,6 +27,10 @@ export default function LoginRoutes($stateProvider) {
|
||||
$stateProvider.state('login', {
|
||||
url: '/login',
|
||||
module: 'public',
|
||||
params: {
|
||||
params: null,
|
||||
toName: null
|
||||
},
|
||||
views: {
|
||||
"@": {
|
||||
controller: 'LoginController',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user