register.page.ts 1.16 KB
Newer Older
gap95's avatar
gap95 committed
1
2
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
gap95's avatar
gap95 committed
3
4
5
import { HttpClient } from '@angular/common/http';
import { RestService } from 'src/app/rest.service';
import { Router } from '@angular/router';
gap95's avatar
gap95 committed
6
7
8
9
10
11
12

@Component({
  selector: 'app-register',
  templateUrl: './register.page.html',
  styleUrls: ['./register.page.scss'],
})
export class RegisterPage implements OnInit {
gap95's avatar
gap95 committed
13
 
gap95's avatar
gap95 committed
14
  registerApi: Observable<any>;
gap95's avatar
gap95 committed
15
 
gap95's avatar
gap95 committed
16
  correctCredentials: boolean;
gap95's avatar
gap95 committed
17
18
19
20
21
  email: "";
  password: "";
  lastName: "";
  firstName: "";
  constructor(private router: Router, public httpClient: HttpClient, public restService: RestService) { }
gap95's avatar
gap95 committed
22
23
24

  ngOnInit() {
  }
gap95's avatar
gap95 committed
25
26
27
28
29
30
31
32
33
34
35
  submitRegister() {
    this.registerApi = this.httpClient.post('http://193.196.52.237:8081/register', {
      "email": this.email,
      "password": this.password,
      "firstname": this.firstName,
      "lastname": this.lastName
    });
    this.registerApi
      .subscribe((data) => {
        console.log('my data: ', data);
        this.restService.setToken(data.token);
gap95's avatar
gap95 committed
36
        this.router.navigateByUrl('/login');
gap95's avatar
gap95 committed
37
38
39
40
41
      }, (error) => {
        console.log(error);
        this.correctCredentials = true;
      });
  }
gap95's avatar
gap95 committed
42
}