aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_modals/login-modal
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/app/_modals/login-modal')
-rw-r--r--frontend/src/app/_modals/login-modal/login-modal.component.html29
-rw-r--r--frontend/src/app/_modals/login-modal/login-modal.component.ts53
2 files changed, 41 insertions, 41 deletions
diff --git a/frontend/src/app/_modals/login-modal/login-modal.component.html b/frontend/src/app/_modals/login-modal/login-modal.component.html
index 22f50de2..d7836848 100644
--- a/frontend/src/app/_modals/login-modal/login-modal.component.html
+++ b/frontend/src/app/_modals/login-modal/login-modal.component.html
@@ -1,14 +1,9 @@
-<!-- Button trigger modal, OVO JE U STVARI DUGME U NAVBARU -->
-<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalForLogin" (click)="openModal()">
- Otvori login modal
-</button>
-
<!-- Modal -->
<div class="modal fade" id="modalForLogin" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
- <div class="modal-header bg-info">
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+ <div class="modal-header" style="background-color: #003459;">
+ <button id="closeButton" type="button" class="btn-close" style="background-color:white;" data-bs-dismiss="modal" aria-label="Close" (click)="resetData()"></button>
</div>
<div class="modal-body px-5" style="color:#003459">
<h1 class="text-center mt-2 mb-4">Prijavite se</h1>
@@ -25,25 +20,23 @@
<input [(ngModel)]="password" name="password" type="password" id="password"
class="form-control form-control" placeholder="Unesite lozinku..." />
</div>
-
- <div class="text-center text-lg-start mt-5 pt-2">
- <p *ngIf="wrongCreds" class="small fw-bold mt-2 pt-1 mb-0 text-danger">Lozinka ili e-mail su pogrešni
- </p>
- </div>
</form>
+
+ <div class="text-center text-lg-start mt-5">
+ <p *ngIf="wrongCreds" class="small fw-bold text-danger text-center">Unesite ispravan e-mail i lozinku.</p>
+ </div>
+
<div class="col-md-12 d-flex justify-content-center">
- <button type="button" class="btn btn-lg btn-info" style="color:white; border-color: #00a8e8; margin-right: 10px;" (click)="doLogin()">Prijavite se</button>
- <button type="button" class="btn btn-lg btn-outline-secondary" data-bs-dismiss="modal">Odustanite</button>
+ <button type="button" class="btn btn-lg" style="color:white; background-color: #003459; margin-right: 10px;" (click)="doLogin()">Prijavite se</button>
+ <button type="button" class="btn btn-lg btn-outline-secondary" data-bs-dismiss="modal" (click)="resetData()">Odustanite</button>
</div>
<br>
</div>
<div class="modal-footer justify-content-center">
<p class="small fw-bold">Još uvek nemate nalog?
- <a routerLink="/register" class="link-danger">Registrujte se</a>
+ <a data-bs-toggle="modal" data-bs-target="#modalForRegister" class="link-danger">Registrujte se</a>
</p>
</div>
</div>
</div>
-</div>
-
-
+</div> \ No newline at end of file
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 = '';
}
}