aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/user/user-login/user-login.component.ts
blob: 3505d50b538743cb717a24fc4e70a13668f2bd08 (plain)
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
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';

import { InternalUserService } from '../internal-user-service/internal-user.service';

export type LoginMessage = 'nologin' | 'invalidlogin' | string | null | undefined;


@Component({
  selector: 'app-user-login',
  templateUrl: './user-login.component.html',
  styleUrls: ['./user-login.component.css']
})
export class UserLoginComponent implements OnInit {

  constructor(private route: ActivatedRoute, private userService: InternalUserService) { }

  message: LoginMessage;

  form = new FormGroup({
    username: new FormControl(''),
    password: new FormControl('')
  });

  ngOnInit() {
    this.message = this.route.snapshot.paramMap.get('reason');
  }

  onLoginButtonClick() {
    this.userService.tryLogin(this.form.value).subscribe(_ => {
      this.userService.userRouteNavigate(['success', { reason: 'login' }]);
    }, (error: Error) => this.message = error.message);
  }
}