Skip to content

Commit

Permalink
Adiciona e melhora mensagens de erro, e cria o logout
Browse files Browse the repository at this point in the history
Signed-off-by: DaviMarinho <[email protected]>
  • Loading branch information
DaviMarinho committed Nov 16, 2023
1 parent f18415b commit 12e8a9e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,7 +46,8 @@ import { MessageService } from 'primeng/api';
BrowserAnimationsModule,
OAuthModule.forRoot(),
InputTextModule,
DropdownModule
DropdownModule,
ButtonModule,
],
declarations: [
AppComponent,
Expand Down Expand Up @@ -76,7 +78,7 @@ import { MessageService } from 'primeng/api';
},
{ provide: OAuthStorage, useValue: localStorage },
MessageService,
ConfirmationService,
ConfirmationService
],
bootstrap: [AppComponent],
})
Expand Down
14 changes: 9 additions & 5 deletions src/app/pages/active-account/active-account.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<form [formGroup]="userForm" class="text-center">
<div class="mb-4">
<input
pInputText
class="w-64 h-8 border rounded-lg border-gray-300 pl-4 md:w-96 md:h-10"
type="email"
formControlName="email"
Expand All @@ -12,6 +13,7 @@
</div>
<div *ngIf="activeCode" class="mb-4">
<input
pInputText
class="w-64 h-8 border rounded-lg border-gray-300 pl-4 md:w-96 md:h-10"
type="text"
formControlName="code"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ export class CheckCodeRestPasswordComponent {
}

sendEmail() {
console.log(this.userForm.value);
console.log({email: this.userForm.value.email});

if (this.userForm.value.email) {
this.authService.sendEmailPassword({email: this.userForm.value.email}).subscribe({
next: (data) => {
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 {
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/app/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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<any> {
return this.http.post(`${this.usersAPIURL}/auth/register`, user);
Expand All @@ -25,7 +26,7 @@ export class AuthService {
}

resendCode(email: any): Observable<any> {
return this.http.post(`${this.usersAPIURL}/auth/resend-code`, email);
return this.http.post(`${this.usersAPIURL}/auth/resend-code`, { email });
}

sendEmailPassword(email: any): Observable<any> {
Expand All @@ -47,5 +48,6 @@ export class AuthService {

logout(): void {
localStorage.removeItem('token');
this.router.navigate(['/login']);
}
}

0 comments on commit 12e8a9e

Please sign in to comment.