workstationState: AuthWsState = AuthWsState.PENDING;
- // Used by auth-checking resolvers
- redirectUrl: string;
-
// reference to active auth validity setTimeout handler.
pollTimeout: any;
import {StoreService} from '@eg/core/store.service';
import {OrgService} from '@eg/core/org.service';
+// Direct users to the AngJS splash page when no routeTo is provided.
+const SPLASH_PAGE_PATH = '/eg/staff/splash';
+
@Component({
templateUrl : './login.component.html'
})
-
export class StaffLoginComponent implements OnInit {
workstations: any[];
loginFailed: boolean;
+ routeTo: string;
args = {
username : '',
) {}
ngOnInit() {
+ this.routeTo = this.route.snapshot.queryParamMap.get('routeTo');
+
+ if (this.routeTo) {
+ if (this.routeTo.match(/^[a-z]+:\/\//i)) {
+ console.warn(
+ 'routeTo must contain only path information: ', this.routeTo);
+ this.routeTo = null;
+ }
+ }
+
// clear out any stale auth data
this.auth.logout();
handleSubmit() {
// post-login URL
- let url: string = this.auth.redirectUrl || '/staff/splash';
+ let url: string = this.routeTo || SPLASH_PAGE_PATH;
// prevent sending the user back to the login page
- if (url.startsWith('/staff/login')) {
- url = '/staff/splash';
- }
+ if (url.match('/staff/login')) { url = SPLASH_PAGE_PATH; }
const workstation: string = this.args.workstation;
this.loginFailed = false;
this.auth.login(this.args).then(
ok => {
- this.auth.redirectUrl = null;
if (this.auth.workstationState === AuthWsState.NOT_FOUND_SERVER) {
// User attempted to login with a workstation that is
// valid auth token and workstation.
window.location.href =
this.ngLocation.prepareExternalUrl(url);
-
});
}
},
// valid auth token. Send the caller back to the login page.
handleInvalidToken(state: RouterStateSnapshot): void {
console.debug('StaffResolver: authtoken is not valid');
- this.auth.redirectUrl = state.url;
- this.router.navigate([LOGIN_PATH]);
+ const url = this.ngLocation.prepareExternalUrl(state.url);
+ this.router.navigate([LOGIN_PATH], {queryParams: {routeTo: url}});
this.observer.error('invalid or no auth token');
}
import {Component, OnInit, NgZone, HostListener} from '@angular/core';
+import {Location} from '@angular/common';
import {Router, ActivatedRoute, NavigationEnd} from '@angular/router';
import {AuthService, AuthWsState} from '@eg/core/auth.service';
import {NetService} from '@eg/core/net.service';
constructor(
private router: Router,
private route: ActivatedRoute,
+ private ngLocation: Location,
private zone: NgZone,
private net: NetService,
private auth: AuthService,
}
console.debug('Auth session has expired. Redirecting to login');
- this.auth.redirectUrl = this.router.url;
+ const url = this.ngLocation.prepareExternalUrl(this.router.url);
// https://github.com/angular/angular/issues/18254
// When a tab redirects to a login page as a result of
// with the page. Fix it by wrapping it in zone.run().
// This is the only navigate() where I have seen this happen.
this.zone.run(() => {
- this.router.navigate([LOGIN_PATH]);
+ this.router.navigate([LOGIN_PATH], {queryParams: {routeTo: url}});
});
});