diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 5bcefb1a..9352c56e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc'; import { InputTextModule } from 'primeng/inputtext'; import { DropdownModule } from 'primeng/dropdown'; +import { ButtonModule } from 'primeng/button'; // Declaration import { NgModule } from '@angular/core'; @@ -45,7 +46,8 @@ import { MessageService } from 'primeng/api'; BrowserAnimationsModule, OAuthModule.forRoot(), InputTextModule, - DropdownModule + DropdownModule, + ButtonModule, ], declarations: [ AppComponent, @@ -76,7 +78,7 @@ import { MessageService } from 'primeng/api'; }, { provide: OAuthStorage, useValue: localStorage }, MessageService, - ConfirmationService, + ConfirmationService ], bootstrap: [AppComponent], }) diff --git a/src/app/pages/active-account/active-account.component.ts b/src/app/pages/active-account/active-account.component.ts index a1890800..c8a51522 100644 --- a/src/app/pages/active-account/active-account.component.ts +++ b/src/app/pages/active-account/active-account.component.ts @@ -30,15 +30,17 @@ export class ActiveAccountComponent implements OnInit { if (this.userForm.valid) { this.authService.activeAccount(this.userForm.value).subscribe({ next: (data) => { - console.log(data); if (data.status === "error") { this.alertService.showMessage("error", "Erro", data.message); this.navigator("/login"); + } else { + this.alertService.showMessage("success", "Sucesso", "Email ativado com sucesso!"); + this.navigator("/login"); } - this.navigator("/login"); }, error: (error) => { - console.error(error); + console.log(error); + this.alertService.showMessage("error", "Erro", "Seu email ou senha estão inválidos, preencha os campos corretamente."); }, }); } else { @@ -48,12 +50,14 @@ export class ActiveAccountComponent implements OnInit { resendCode() { if (this.userForm.value.email) { + console.log(this.userForm.value.email); this.authService.resendCode(this.userForm.value.email).subscribe({ next: (data) => { - console.log(data); + this.alertService.showMessage("success", "Sucesso", "Email reenviado com sucesso!"); }, error: (error) => { - console.error(error); + console.log(error); + this.alertService.showMessage("error", "Erro", error.error.detail); }, }); } else { diff --git a/src/app/pages/check-code-rest-password/check-code-rest-password.component.html b/src/app/pages/check-code-rest-password/check-code-rest-password.component.html index 70e9d9b4..80d92427 100644 --- a/src/app/pages/check-code-rest-password/check-code-rest-password.component.html +++ b/src/app/pages/check-code-rest-password/check-code-rest-password.component.html @@ -2,6 +2,7 @@
{ - console.log(data); - this.activeCode = true + this.alertService.showMessage("success", "Sucesso", "Email enviado para realizar a troca de senha."); + this.activeCode = true; }, error: (error) => { - console.error(error); + this.alertService.showMessage("error", "Erro", "Email inválido!"); }, }); } else { @@ -53,11 +50,11 @@ export class CheckCodeRestPasswordComponent { if (this.userForm.valid) { this.authService.verifyCodePassword(this.userForm.value).subscribe({ next: (data) => { - console.log(data); + this.alertService.showMessage("success", "Sucesso", "Código válido!"); this.navigator('/changePassword'); }, error: (error) => { - console.error(error); + this.alertService.showMessage("error", "Erro", error.error.detail); }, }); } else { diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 7f4a6a3a..c91004b4 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { environment } from '../environment/environment'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; +import { Router } from '@angular/router'; @Injectable({ @@ -10,7 +11,7 @@ import { Observable } from 'rxjs'; export class AuthService { public usersAPIURL = environment.usersAPIURL; - constructor(private http: HttpClient) { } + constructor(private http: HttpClient, private router: Router) { } registerUser(user: any): Observable { return this.http.post(`${this.usersAPIURL}/auth/register`, user); @@ -25,7 +26,7 @@ export class AuthService { } resendCode(email: any): Observable { - return this.http.post(`${this.usersAPIURL}/auth/resend-code`, email); + return this.http.post(`${this.usersAPIURL}/auth/resend-code`, { email }); } sendEmailPassword(email: any): Observable { @@ -47,5 +48,6 @@ export class AuthService { logout(): void { localStorage.removeItem('token'); + this.router.navigate(['/login']); } }