blob: e1535a253b82f5c422b31f79d2ce1ac2bb37a6f6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { AuthService } from 'src/app/_services/auth.service';
import { UserInfoService } from 'src/app/_services/user-info.service';
import shared from '../../Shared';
import {AfterViewInit, ElementRef} from '@angular/core';
@Component({
selector: 'app-login-modal',
templateUrl: './login-modal.component.html',
styleUrls: ['./login-modal.component.css']
})
export class LoginModalComponent implements OnInit {
@ViewChild('closeButton') closeButton?: ElementRef;
username: string = '';
password: string = '';
wrongCreds: boolean = false;
constructor(
private authService: AuthService,
private cookie: CookieService,
private router: Router,
private userInfoService: UserInfoService
) { }
ngOnInit(): void {
}
doLogin() {
if (this.username.length > 0 && this.password.length > 0) {
this.authService.login(this.username, this.password).subscribe((response) => {
console.log(response);
if (response == "Username doesn't exist" || response == "Wrong password") {
this.wrongCreds = true;
this.password = '';
}
else {
this.authService.authenticate(response);
(<HTMLSelectElement>this.closeButton?.nativeElement).click();
this.userInfoService.getUserInfo().subscribe((response) => {
shared.photoId = response.photoId;
});
}
});
}
else {
this.wrongCreds = true;
this.password = '';
}
}
resetData() {
this.wrongCreds = false;
this.username = '';
this.password = '';
}
}
|