1 import {Component, OnInit, Renderer2} from '@angular/core';
2 import {Location} from '@angular/common';
3 import {Router, ActivatedRoute} from '@angular/router';
4 import {AuthService, AuthWsState} from '@eg/core/auth.service';
5 import {StoreService} from '@eg/core/store.service';
6 import {OrgService} from '@eg/core/org.service';
9 templateUrl : './login.component.html'
12 export class StaffLoginComponent implements OnInit {
25 private router: Router,
26 private route: ActivatedRoute,
27 private ngLocation: Location,
28 private renderer: Renderer2,
29 private auth: AuthService,
30 private org: OrgService,
31 private store: StoreService
35 // clear out any stale auth data
39 this.renderer.selectRootElement('#username').focus();
41 this.store.getWorkstations()
43 this.workstations = wsList;
44 return this.store.getDefaultWorkstation();
46 this.args.workstation = def;
47 this.applyWorkstation();
52 const wanted = this.route.snapshot.queryParamMap.get('workstation');
53 if (!wanted) { return; } // use the default
55 const exists = this.workstations.filter(w => w.name === wanted)[0];
57 this.args.workstation = wanted;
59 console.error(`Unknown workstation requested: ${wanted}`);
66 let url: string = this.auth.redirectUrl || '/staff/splash';
68 // prevent sending the user back to the login page
69 if (url.startsWith('/staff/login')) {
70 url = '/staff/splash';
73 const workstation: string = this.args.workstation;
75 this.loginFailed = false;
76 this.auth.login(this.args).then(
78 this.auth.redirectUrl = null;
80 if (this.auth.workstationState === AuthWsState.NOT_FOUND_SERVER) {
81 // User attempted to login with a workstation that is
82 // unknown to the server. Redirect to the WS admin page.
83 // Reset the WS state to avoid looping back to WS removal
84 // page before the new workstation can be activated.
85 this.auth.workstationState = AuthWsState.PENDING;
87 [`/staff/admin/workstation/workstations/remove/${workstation}`]);
91 // Initial login clears cached org unit settings.
92 this.org.clearCachedSettings().then(_ => {
94 // Force reload of the app after a successful login.
95 // This allows the route resolver to re-run with a
96 // valid auth token and workstation.
98 // Temporarily redirect to AngularJS splash page
99 // (LP#1848550/LP#1835128)
100 window.location.href = '/eg/staff/splash';
101 // this.ngLocation.prepareExternalUrl(url);
107 this.loginFailed = true;