aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_modals/login-modal/login-modal.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/app/_modals/login-modal/login-modal.component.ts')
-rw-r--r--frontend/src/app/_modals/login-modal/login-modal.component.ts53
1 files changed, 30 insertions, 23 deletions
diff --git a/frontend/src/app/_modals/login-modal/login-modal.component.ts b/frontend/src/app/_modals/login-modal/login-modal.component.ts
index 3a6fd8f1..c86c269a 100644
--- a/frontend/src/app/_modals/login-modal/login-modal.component.ts
+++ b/frontend/src/app/_modals/login-modal/login-modal.component.ts
@@ -1,11 +1,9 @@
import { Component, OnInit, ViewChild } from '@angular/core';
-import { FormControl, FormGroup } from '@angular/forms';
import { Router } from '@angular/router';
import { CookieService } from 'ngx-cookie-service';
import { AuthService } from 'src/app/_services/auth.service';
-import { ElementRef } from '@angular/core';
-
-declare var window: any;
+import { UserInfoService } from 'src/app/_services/user-info.service';
+import shared from '../../Shared';
@Component({
selector: 'app-login-modal',
@@ -14,38 +12,47 @@ declare var window: any;
})
export class LoginModalComponent implements OnInit {
- loginModal: any;
username: string = '';
password: string = '';
- public wrongCreds: boolean = false; //RAZMOTRITI
+ wrongCreds: boolean = false;
constructor(
private authService: AuthService,
private cookie: CookieService,
- private router: Router
+ private router: Router,
+ private userInfoService: UserInfoService
) { }
ngOnInit(): void {
- this.loginModal = new window.bootstrap.Modal(
- document.getElementById("modalForLogin")
- );
}
- openModal() {
- this.loginModal.show();
- //console.log("ok");
- //(<HTMLInputElement>document.getElementById("exampleModal")).style.display = "block";
- }
doLogin() {
- this.authService.login(this.username, this.password).subscribe((response) => { //ako nisu ok podaci, ne ide hide nego mora opet da ukucava!!!!podesi
- console.log(response);
- this.cookie.set('token', response);
- this.loginModal.hide(); //dodato
- this.router.navigate(['add-model']);
- });
+ 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>document.getElementById('closeButton')).click();
+ this.userInfoService.getUserInfo().subscribe((response) => {
+ shared.photoId = response.photoId;
+ });
+ }
+ });
+ }
+ else {
+ this.wrongCreds = true;
+ this.password = '';
+ }
}
- sendToRegister() {
-
+ resetData() {
+ this.wrongCreds = false;
+ this.username = '';
+ this.password = '';
}
}