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';
import {StoreService} from '@eg/core/store.service';
import {SckoService} from './scko.service';
import {OrgService} from '@eg/core/org.service';
+import {EventService, EgEvent} from '@eg/core/event.service';
@Component({
selector: 'eg-scko-banner',
constructor(
private route: ActivatedRoute,
private store: StoreService,
+ private net: NetService,
private auth: AuthService,
+ private evt: EventService,
private ngLocation: Location,
private org: OrgService,
public scko: SckoService
submitPatronLogin() {
this.patronLoginFailed = false;
- this.scko.loadPatron(this.patronUsername, this.patronPassword)
- .finally(() => {
+ this.loadPatron().finally(() => {
this.patronLoginFailed = this.scko.patron === null;
});
}
+
+ loadPatron(): Promise<any> {
+ this.scko.patron = null;
+
+ if (!this.patronUsername) { return; }
+
+ let username;
+ let barcode;
+
+ if (this.patronUsername.match(this.scko.barcodeRegex)) {
+ barcode = this.patronUsername;
+ } else {
+ username = this.patronUsername;
+ }
+
+ if (this.scko.patronPasswordRequired) {
+ // TODO verify password
+
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.verify_user_password',
+ this.auth.token(), barcode, username, null, this.patronPassword)
+
+ .toPromise().then(verified => {
+ if (Number(verified) === 1) {
+ return this.fetchPatron(username, barcode);
+ } else {
+ return Promise.reject('Bad password');
+ }
+ });
+
+ } else {
+
+ return this.fetchPatron(username, barcode);
+ }
+ }
+
+ fetchPatron(username: string, barcode: string): Promise<any> {
+
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.user.retrieve_id_by_barcode_or_username',
+ this.auth.token(), barcode, username).toPromise()
+
+ .then(patronId => {
+
+ const evt = this.evt.parse(patronId);
+
+ if (evt || !patronId) {
+ console.error("Cannot find user: ", evt);
+ return Promise.reject('User not found');
+ }
+
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.user.fleshed.retrieve.authoritative',
+ this.auth.token(), patronId).toPromise()
+
+ }).then(patron => {
+
+ const evt = this.evt.parse(patron);
+
+ if (evt) {
+ console.error('fetchPatron()', evt);
+ return Promise.reject('User not found');
+ }
+
+ this.scko.patron = patron;
+ });
+ }
+
}
this.barcodeRegex = new RegExp(regPattern);
this.patronPasswordRequired =
sets['circ.selfcheck.patron_password_required'];
- });
- }
-
- loadPatron(username: string, password: string): Promise<any> {
- this.patron = null;
-
- if (!username) { return; }
-
- let barcode;
-
- if (username.match(this.barcodeRegex)) {
- barcode = username;
- username = null;
- }
-
- if (this.patronPasswordRequired) {
- // TODO verify password
-
- } else {
-
- return this.fetchPatron(username, barcode);
- }
- }
-
- fetchPatron(username: string, barcode: string): Promise<any> {
-
- return this.net.request(
- 'open-ils.actor',
- 'open-ils.actor.user.retrieve_id_by_barcode_or_username',
- this.auth.token(), barcode, username).toPromise()
-
- .then(patronId => {
-
- const evt = this.evt.parse(patronId);
-
- if (evt || !patronId) {
- console.error("Cannot find user: ", evt);
- return Promise.reject('User not found');
- }
-
- return this.net.request(
- 'open-ils.actor',
- 'open-ils.actor.user.fleshed.retrieve.authoritative',
- this.auth.token(), patronId).toPromise()
-
- }).then(patron => {
-
- const evt = this.evt.parse(patron);
-
- if (evt) {
- console.error('fetchPatron()', evt);
- return Promise.reject('User not found');
- }
-
- this.patron = patron;
+ console.log('REQ', this.patronPasswordRequired);
});
}
}