[frontend] Add confirmation component logic
This commit is contained in:
parent
8beabb9031
commit
165263e559
|
@ -13,10 +13,12 @@ import { ApiModule } from './core/api/api.module';
|
||||||
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||||
import { BASE_PATH } from './core/api/variables';
|
import { BASE_PATH } from './core/api/variables';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
import { LoginComponent } from './login/login.component';
|
import { LoginComponent } from './auth/login/login.component';
|
||||||
import { RegisterComponent } from './register/register.component';
|
import { RegisterComponent } from './auth/register/register.component';
|
||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { AuthTokenInterceptor } from './core/auth/auth-token.interceptor';
|
import { AuthTokenInterceptor } from './core/auth/auth-token.interceptor';
|
||||||
|
import { ConfirmComponent } from './auth/confirm/confirm.component';
|
||||||
|
import { ErrorInterceptor } from './core/auth/error.interceptor';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -27,6 +29,7 @@ import { AuthTokenInterceptor } from './core/auth/auth-token.interceptor';
|
||||||
HoodspageComponent,
|
HoodspageComponent,
|
||||||
LoginComponent,
|
LoginComponent,
|
||||||
RegisterComponent,
|
RegisterComponent,
|
||||||
|
ConfirmComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
@ -40,6 +43,7 @@ import { AuthTokenInterceptor } from './core/auth/auth-token.interceptor';
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: BASE_PATH, useValue: environment.API_BASE_PATH },
|
{ provide: BASE_PATH, useValue: environment.API_BASE_PATH },
|
||||||
{ provide: HTTP_INTERCEPTORS, useClass: AuthTokenInterceptor, multi: true },
|
{ provide: HTTP_INTERCEPTORS, useClass: AuthTokenInterceptor, multi: true },
|
||||||
|
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ConfirmComponent } from './confirm.component';
|
||||||
|
|
||||||
|
describe('ConfirmComponent', () => {
|
||||||
|
let component: ConfirmComponent;
|
||||||
|
let fixture: ComponentFixture<ConfirmComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ConfirmComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ConfirmComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
40
kibicara-frontend/src/app/auth/confirm/confirm.component.ts
Normal file
40
kibicara-frontend/src/app/auth/confirm/confirm.component.ts
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { AdminService } from '../../core/api';
|
||||||
|
import { first } from 'rxjs/operators';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-confirm',
|
||||||
|
templateUrl: './confirm.component.html',
|
||||||
|
styleUrls: ['./confirm.component.scss'],
|
||||||
|
})
|
||||||
|
export class ConfirmComponent implements OnInit {
|
||||||
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private adminService: AdminService,
|
||||||
|
private router: Router
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit(): void {
|
||||||
|
const token = this.route.snapshot.queryParams['token'];
|
||||||
|
if (token) {
|
||||||
|
this.adminService
|
||||||
|
.confirm(token)
|
||||||
|
.pipe(first())
|
||||||
|
.subscribe(
|
||||||
|
(data) => {
|
||||||
|
this.router.navigate(['/login'], {
|
||||||
|
queryParams: { registered: true },
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.router.navigate(['/register'], {
|
||||||
|
queryParams: { error: true },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/register']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue