LP1904036 Clear password in Verify Credentials after submitting
[evergreen-equinox.git] / Open-ILS / src / eg2 / src / app / staff / circ / patron / test-password.component.ts
1 import {Component, Input, OnInit, AfterViewInit, ViewChild} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {from, empty, range} from 'rxjs';
4 import {concatMap, tap, takeLast} from 'rxjs/operators';
5 import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
6 import {IdlObject} from '@eg/core/idl.service';
7 import {EventService} from '@eg/core/event.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {NetService} from '@eg/core/net.service';
10 import {PcrudService, PcrudContext} from '@eg/core/pcrud.service';
11 import {AuthService} from '@eg/core/auth.service';
12 import {PatronService} from '@eg/staff/share/patron/patron.service';
13 import {PatronContextService} from './patron.service';
14
15 @Component({
16   templateUrl: 'test-password.component.html',
17   selector: 'eg-patron-test-password'
18 })
19 export class TestPatronPasswordComponent implements OnInit, AfterViewInit {
20
21     @Input() patronId: number;
22     patron: IdlObject;
23     username = '';
24     barcode = '';
25     password = '';
26     verified = null;
27     notFound = false;
28
29     constructor(
30         private router: Router,
31         private evt: EventService,
32         private net: NetService,
33         private auth: AuthService,
34         public patronService: PatronService
35     ) {}
36
37     ngOnInit() {
38
39         if (this.patronId) {
40             this.patronService.getById(this.patronId,
41                 {flesh: 1, flesh_fields: {au: ['card']}})
42             .then(p => {
43                 this.patron = p;
44                 this.username = p.usrname();
45                 this.barcode = p.card().barcode();
46             });
47         }
48     }
49
50     ngAfterViewInit() {
51         let domId = 'password-input';
52         if (!this.patronId) { domId = 'username-input'; }
53         const node = document.getElementById(domId) as HTMLInputElement;
54         if (node) { node.focus(); }
55     }
56
57     retrieve() {
58         this.verified = null;
59         this.notFound = false;
60
61         this.net.request(
62             'open-ils.actor',
63             'open-ils.actor.user.retrieve_id_by_barcode_or_username',
64             this.auth.token(), this.barcode, this.username
65         ).subscribe(resp => {
66             if (this.evt.parse(resp)) {
67                 this.notFound = true;
68             } else {
69                 this.router.navigate(['/staff/circ/patron/', resp, 'checkout']);
70             }
71         });
72     }
73
74     verify() {
75         if (!this.username && !this.barcode) { return; }
76
77         this.net.request('open-ils.actor',
78             'open-ils.actor.verify_user_password', this.auth.token(),
79             this.barcode, this.username, null, this.password)
80
81         .subscribe(resp => {
82             const evt = this.evt.parse(resp);
83
84             this.password = null;
85
86             if (evt) {
87                 console.error(evt);
88                 alert(evt);
89             } else if (Number(resp) === 1) {
90                 this.verified = true;
91             } else {
92                 this.verified = false;
93             }
94         });
95     }
96 }
97