diff --git a/package-lock.json b/package-lock.json index 6e8a15e5..e5894f48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,12 +16,14 @@ "@angular/platform-browser": "^15.2.0", "@angular/platform-browser-dynamic": "^15.2.0", "@angular/router": "^15.2.0", + "angular-oauth2-oidc": "^15.0.1", "jwt-decode": "^3.1.2", "postcss-cli": "^10.1.0", "postcss-import": "^15.1.0", "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.2.0", "postcss-scss": "^4.0.9", + "primeicons": "^6.0.1", "primeng": "^15.4.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", @@ -4809,6 +4811,18 @@ "ajv": "^8.8.2" } }, + "node_modules/angular-oauth2-oidc": { + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/angular-oauth2-oidc/-/angular-oauth2-oidc-15.0.1.tgz", + "integrity": "sha512-5gpqO9QL+qFqMItYFHe8F6H5nOIEaowcNUc9iTDs3P1bfVYnoKoVAaijob53PuPTF4YwzdfwKWZi4Mq6P7GENQ==", + "dependencies": { + "tslib": "^2.0.0" + }, + "peerDependencies": { + "@angular/common": ">=14.0.0", + "@angular/core": ">=14.0.0" + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -11292,6 +11306,11 @@ "node": ">= 0.8" } }, + "node_modules/primeicons": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/primeicons/-/primeicons-6.0.1.tgz", + "integrity": "sha512-KDeO94CbWI4pKsPnYpA1FPjo79EsY9I+M8ywoPBSf9XMXoe/0crjbUK7jcQEDHuc0ZMRIZsxH3TYLv4TUtHmAA==" + }, "node_modules/primeng": { "version": "15.4.1", "resolved": "https://registry.npmjs.org/primeng/-/primeng-15.4.1.tgz", diff --git a/package.json b/package.json index 37ef0b0e..6db2f4d3 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,14 @@ "@angular/platform-browser": "^15.2.0", "@angular/platform-browser-dynamic": "^15.2.0", "@angular/router": "^15.2.0", + "angular-oauth2-oidc": "^15.0.1", "jwt-decode": "^3.1.2", "postcss-cli": "^10.1.0", "postcss-import": "^15.1.0", "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.2.0", "postcss-scss": "^4.0.9", + "primeicons": "^6.0.1", "primeng": "^15.4.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", diff --git a/src/app/app.component.html b/src/app/app.component.html index 6382efb8..62cd2d16 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,3 +1,5 @@ + + diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0afeb240..5bcefb1a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,9 +1,18 @@ -import { NgModule } from '@angular/core'; +// Import import { BrowserModule } from '@angular/platform-browser'; -import { ReactiveFormsModule } from '@angular/forms'; +import { AppRoutingModule } from './app-routing.module'; import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { ReactiveFormsModule } from '@angular/forms'; +import { ToastModule } from 'primeng/toast'; +import { ConfirmDialogModule } from 'primeng/confirmdialog'; +import { ConfirmationService } from 'primeng/api'; +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 { AppRoutingModule } from './app-routing.module'; +// Declaration +import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { LoginComponent } from './pages/login/login.component'; import { RegisterComponent } from './pages/register/register.component'; @@ -12,7 +21,6 @@ import { VideoViewerComponent } from './pages/video-viewer/video-viewer.componen import { SafePipe } from './pipes/safe.pipe'; import { BackgroundComponent } from './components/background/background.component'; import { LoginSocialComponent } from './pages/login-social/login-social.component'; - import { ActiveAccountComponent } from './pages/active-account/active-account.component'; import { HomePageComponent } from './pages/home-page/home-page.component'; import { ProfileComponent } from './pages/profile/profile.component'; @@ -27,6 +35,18 @@ import { ParticipateComponent } from './pages/participate/participate.component' import { MessageService } from 'primeng/api'; @NgModule({ + imports: [ + BrowserModule, + AppRoutingModule, + HttpClientModule, + ReactiveFormsModule, + ToastModule, + ConfirmDialogModule, + BrowserAnimationsModule, + OAuthModule.forRoot(), + InputTextModule, + DropdownModule + ], declarations: [ AppComponent, LoginComponent, @@ -46,23 +66,18 @@ import { MessageService } from 'primeng/api'; SuggestAgendaComponent, ParticipateComponent, ], - imports: [ - BrowserModule, - AppRoutingModule, - HttpClientModule, - ReactiveFormsModule, - HttpClientModule - ], providers: [ - AuthGuard, + { provide: 'authGuard', useClass: AuthGuard }, AuthService, { provide: HTTP_INTERCEPTORS, useClass: UserTokenInterceptor, multi: true, }, - MessageService + { provide: OAuthStorage, useValue: localStorage }, + MessageService, + ConfirmationService, ], bootstrap: [AppComponent], }) -export class AppModule { } +export class AppModule {} diff --git a/src/app/pages/active-account/active-account.component.html b/src/app/pages/active-account/active-account.component.html index c9a6f320..95080acc 100644 --- a/src/app/pages/active-account/active-account.component.html +++ b/src/app/pages/active-account/active-account.component.html @@ -2,10 +2,10 @@
- +
- +
diff --git a/src/app/pages/edit-user/edit-user.component.html b/src/app/pages/edit-user/edit-user.component.html index 38514dd9..929e53a9 100644 --- a/src/app/pages/edit-user/edit-user.component.html +++ b/src/app/pages/edit-user/edit-user.component.html @@ -2,10 +2,10 @@
- +
- +
+
- +
Esqueceu a senha? diff --git a/src/app/pages/login/login.component.ts b/src/app/pages/login/login.component.ts index f8ceeb32..b87adb2b 100644 --- a/src/app/pages/login/login.component.ts +++ b/src/app/pages/login/login.component.ts @@ -37,7 +37,7 @@ export class LoginComponent implements OnInit { this.navigator('/profile'); }, error: (error) => { - console.error(error); + this.alertService.showMessage("error", "Erro", error.error); }, }); } else { diff --git a/src/app/pages/profile/profile.component.ts b/src/app/pages/profile/profile.component.ts index 74f5549b..3fa27686 100644 --- a/src/app/pages/profile/profile.component.ts +++ b/src/app/pages/profile/profile.component.ts @@ -41,13 +41,6 @@ export class ProfileComponent { } navigatorEdit(): void { - - const navigationExtras: NavigationExtras = { - state: { - user: this.user - } - }; - this.router.navigate([`/editUser`], navigationExtras); + this.router.navigate([`/editUser/${this.user.id}`]); } - } diff --git a/src/app/pages/register/register.component.html b/src/app/pages/register/register.component.html index 820ea2f4..076a33a5 100644 --- a/src/app/pages/register/register.component.html +++ b/src/app/pages/register/register.component.html @@ -2,24 +2,23 @@
- +
- +
- +
- +
- +
diff --git a/src/app/pages/register/register.component.spec.ts b/src/app/pages/register/register.component.spec.ts index af78b8bd..2fc969bf 100644 --- a/src/app/pages/register/register.component.spec.ts +++ b/src/app/pages/register/register.component.spec.ts @@ -6,6 +6,8 @@ import { FormBuilder, ReactiveFormsModule } from '@angular/forms'; import { of, throwError } from 'rxjs'; import { RouterTestingModule } from '@angular/router/testing'; import { ActiveAccountComponent } from '../active-account/active-account.component'; +import { AlertService } from 'src/app/services/alert.service'; +import { DropdownModule } from 'primeng/dropdown'; const mockData: any = { "name": "Mario", @@ -22,21 +24,29 @@ class AuthServiceMock { } } +class AlertServiceMock { + constructor() { } + showMessage() { + return of({ success: true }); + } +} + describe('RegisterComponent', () => { let component: RegisterComponent; let fixture: ComponentFixture; let authService: AuthService; + let alertService: AlertService; beforeEach(async () => { await TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, ReactiveFormsModule, + imports: [HttpClientTestingModule, ReactiveFormsModule, DropdownModule, RouterTestingModule.withRoutes( [ { path: 'activateAccount', component: ActiveAccountComponent }, ] ) ], - providers: [{ provide: AuthService, useValue: new AuthServiceMock() }, FormBuilder], + providers: [{ provide: AuthService, useValue: new AuthServiceMock() }, FormBuilder, {provide: AlertService, useValue: new AlertServiceMock()}], declarations: [RegisterComponent] }) .compileComponents(); @@ -44,6 +54,7 @@ describe('RegisterComponent', () => { fixture = TestBed.createComponent(RegisterComponent); component = fixture.componentInstance; authService = TestBed.inject(AuthService); + alertService = TestBed.inject(AlertService); fixture.detectChanges(); }); @@ -70,19 +81,6 @@ describe('RegisterComponent', () => { expect(component.register).toHaveBeenCalled(); }); - it('should call alert when form is not valid', () => { - spyOn(component, 'register').and.callThrough(); - const alertSpy = spyOn(window, 'alert'); - fixture.detectChanges(); - - const submitButton = fixture.nativeElement.querySelector( - 'button[type="submit"]' - ); - submitButton.click(); - - expect(alertSpy).toHaveBeenCalledWith('Preencha todos os campos corretamente!'); - }); - it('should call register and return an error', () => { fixture.detectChanges(); const form = component.userForm; @@ -92,4 +90,13 @@ describe('RegisterComponent', () => { expect(mySpy).toHaveBeenCalled(); }); + // it('test AlertService', () => { + // fixture.detectChanges(); + // const form = component.userForm; + // form.setValue(mockData); + // const mySpy = spyOn(alertService, 'showMessage').and.callThrough(); + // component.register(); + // expect(mySpy).toHaveBeenCalled(); + // }); + }); diff --git a/src/app/pages/register/register.component.ts b/src/app/pages/register/register.component.ts index 4c7eb7c1..147db421 100644 --- a/src/app/pages/register/register.component.ts +++ b/src/app/pages/register/register.component.ts @@ -2,8 +2,9 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { MustMatch } from 'src/app/helper/must-match.validator'; -import { AuthService } from '../../services/auth.service'; import { AlertService } from 'src/app/services/alert.service'; +import { UserService } from '../../services/user.service'; +import { AuthService } from 'src/app/services/auth.service'; @Component({ selector: 'app-register', @@ -12,35 +13,56 @@ import { AlertService } from 'src/app/services/alert.service'; }) export class RegisterComponent implements OnInit { userForm!: FormGroup; + vinculo: any = {}; constructor( private router: Router, private fb: FormBuilder, + private userService: UserService, private authService: AuthService, - private alertService: AlertService, + private alertService: AlertService ) {} ngOnInit(): void { + this.getVinculo(); this.userForm = this.fb.group( { name: ['', [Validators.required]], email: ['', [Validators.email, Validators.required]], - connection: ['', [Validators.required]], + connection: [[], [Validators.required]], password: ['', [Validators.required]], confirmPassword: ['', [Validators.required]], - }, - { + },{ validator: MustMatch('password', 'confirmPassword'), } ); } + getVinculo() { + this.userService.getVinculo().subscribe({ + next: (data) => { + this.vinculo = data.map((name: any) => { + return { + name: name, + } + }); + }, + error: (error) => { + console.error(error); + }, + }); + } + register() { if (this.userForm.valid) { - this.authService.registerUser(this.userForm.value).subscribe({ + const data = {...this.userForm.value, connection: this.userForm.value.connection.name}; + this.authService.registerUser(data).subscribe({ next: (data) => { - console.log(data); - this.alertService.showMessage("success", "Sucesso", "Usuário cadastrado com sucesso!"); + this.alertService.showMessage( + 'success', + 'Sucesso', + 'Usuário cadastrado com sucesso!' + ); this.navigator('/activeAccount'); }, error: (error) => { @@ -48,7 +70,11 @@ export class RegisterComponent implements OnInit { }, }); } else { - this.alertService.showMessage("info", "Alerta", "Preencha todos os campos corretamente!"); + this.alertService.showMessage( + 'info', + 'Alerta', + 'Preencha todos os campos corretamente!' + ); } } diff --git a/src/app/pages/reset-password/reset-password.component.html b/src/app/pages/reset-password/reset-password.component.html index 94ffa173..c4229ae4 100644 --- a/src/app/pages/reset-password/reset-password.component.html +++ b/src/app/pages/reset-password/reset-password.component.html @@ -2,16 +2,16 @@
- +
- +
- +
- +
diff --git a/src/app/pages/suggest-agenda/suggest-agenda.component.html b/src/app/pages/suggest-agenda/suggest-agenda.component.html index 53e492f6..4f292f22 100644 --- a/src/app/pages/suggest-agenda/suggest-agenda.component.html +++ b/src/app/pages/suggest-agenda/suggest-agenda.component.html @@ -2,13 +2,13 @@

Sugestão de Pautas

- + - - - - - + + + + +