From dd51d62485962597089853fc16b9f810dcca8461 Mon Sep 17 00:00:00 2001 From: Mehdii909 <76838172+Mehdii909@users.noreply.github.com> Date: Thu, 8 Dec 2022 23:22:41 +0100 Subject: [PATCH] add register --- .../components/navbar/navbar.component.html | 34 +++--------------- src/app/components/navbar/navbar.component.ts | 2 +- src/app/pages/login/login.component.html | 2 +- .../pages/register/register.component.html | 8 ++--- src/app/pages/register/register.component.ts | 35 +++++++++++++++++-- src/app/services/auth.service.ts | 2 ++ src/app/services/user.service.service.ts | 5 ++- 7 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/app/components/navbar/navbar.component.html b/src/app/components/navbar/navbar.component.html index 533724cf..a82554f5 100644 --- a/src/app/components/navbar/navbar.component.html +++ b/src/app/components/navbar/navbar.component.html @@ -2,18 +2,7 @@
{{getTitle()}} - - +
diff --git a/src/app/pages/register/register.component.html b/src/app/pages/register/register.component.html index 965900a2..d3439c45 100644 --- a/src/app/pages/register/register.component.html +++ b/src/app/pages/register/register.component.html @@ -44,7 +44,7 @@

Welcome!

- +
@@ -52,7 +52,7 @@

Welcome!

- +
@@ -60,7 +60,7 @@

Welcome!

- +
password strength: strong
@@ -75,7 +75,7 @@

Welcome!

- +
diff --git a/src/app/pages/register/register.component.ts b/src/app/pages/register/register.component.ts index 21cfa54e..565a9d69 100644 --- a/src/app/pages/register/register.component.ts +++ b/src/app/pages/register/register.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { AuthService } from 'src/app/services/auth.service'; @Component({ selector: 'app-register', @@ -7,9 +9,38 @@ import { Component, OnInit } from '@angular/core'; }) export class RegisterComponent implements OnInit { - constructor() { } + form: any = { + username: null, + email: null, + password: null + }; + isSuccessful = false; + isSignUpFailed = false; + errorMessage = ''; - ngOnInit() { + constructor(private authService: AuthService,private router:Router) { } + + ngOnInit(): void { } + onSubmit(): void { + const { username, email, password } = this.form; + this.authService.register(username, email, password).subscribe( + data => { + console.log(data); + this.isSuccessful = true; + this.isSignUpFailed = false; + console.log('ok'); + this.router.navigate(['/login'] ); + }, + err => { + this.errorMessage = err.error.message; + this.isSignUpFailed = true; + } + ); + } } + + + + diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index c1c8dbbf..209ea218 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -23,6 +23,8 @@ export class AuthService { } register(username: string, email: string, password: string): Observable { + console.log(username,email,password); + return this.http.post(AUTH_API + 'register', { username, email, diff --git a/src/app/services/user.service.service.ts b/src/app/services/user.service.service.ts index 97fa5f49..dd91265e 100644 --- a/src/app/services/user.service.service.ts +++ b/src/app/services/user.service.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; -const API_URL = 'http://localhost:8080/api/tsst/'; +const API_URL = 'http://localhost:8080/api/auth/'; @Injectable({ providedIn: 'root' @@ -17,6 +17,9 @@ export class UserService { getUserBoard(): Observable { return this.http.get(API_URL + 'user', { responseType: 'text' }); } + getUser(): Observable { + return this.http.get(API_URL + 'login', { responseType: 'text' }); + } getModeratorBoard(): Observable { return this.http.get(API_URL + 'mod', { responseType: 'text' });