aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_pages/login-page/login-page.component.ts
blob: f8b429e375e228b817da51c922fb46dff1c8e610 (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
import { Component, OnInit } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { AuthService } from 'src/app/_services/auth.service';

@Component({
  selector: 'app-login-page',
  templateUrl: './login-page.component.html',
  styleUrls: ['./login-page.component.css']
})
export class LoginPageComponent implements OnInit {
  email: string = '';
  password: string = '';

  public wrongCreds: boolean = false;      //RAZMOTRITI
  //public notApproved: boolean = false;     //RAZMOTRITI

  pattEmail: RegExp = /^[a-zA-Z0-9]+([\.\-\+][a-zA-Z0-9]+)*\@([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}$/;

  constructor(
    private authService: AuthService,
    private cookie: CookieService
  ) { }

  ngOnInit(): void {
  }

  onSubmit() {
    if (!this.pattEmail.test(this.email)) {
      console.warn('Bad email!');
      return;
    }
    else {
      this.authService.login(this.email, this.password).subscribe((response) => {
        console.log(response);
        this.cookie.set('token', response);
      })
    }
  }

}