diff --git a/src/app/auth/register/register.page.html b/src/app/auth/register/register.page.html index 9ce0ad141718a58abf5d941363c4b1f34baf7abf..49983a6d199120b9ceb89e370573fce038b5970f 100644 --- a/src/app/auth/register/register.page.html +++ b/src/app/auth/register/register.page.html @@ -29,7 +29,7 @@ </ion-item> </div> - <div id="correctCredentialsmsg" padding *ngIf="correctCredentials"> + <div id="correctCredentialsmsg" padding *ngIf="correctCredentials"> Wrong Credentials ! </div> diff --git a/src/app/auth/register/register.page.ts b/src/app/auth/register/register.page.ts index 2809c34fc7b45562d57a936d8c5da0f8e2d15a5e..bfa94bb6f01b5d801e316b4612dfb350f9aa6a58 100644 --- a/src/app/auth/register/register.page.ts +++ b/src/app/auth/register/register.page.ts @@ -1,5 +1,8 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; +import { HttpClient } from '@angular/common/http'; +import { RestService } from 'src/app/rest.service'; +import { Router } from '@angular/router'; @Component({ selector: 'app-register', @@ -7,14 +10,33 @@ import { Observable } from 'rxjs'; styleUrls: ['./register.page.scss'], }) export class RegisterPage implements OnInit { - httpClient: any; + registerApi: Observable<any>; - restService: any; - router: any; + correctCredentials: boolean; - constructor() { } + email: ""; + password: ""; + lastName: ""; + firstName: ""; + constructor(private router: Router, public httpClient: HttpClient, public restService: RestService) { } ngOnInit() { } - + 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); + this.router.navigateByUrl('/login'); + }, (error) => { + console.log(error); + this.correctCredentials = true; + }); + } }