From 239fd9a6d02b3a27fd25e7ca11182b95ca45e5da Mon Sep 17 00:00:00 2001 From: dylan Date: Fri, 31 Jan 2025 15:38:42 +0100 Subject: [PATCH] Update api client and add redirects after logging in and on "/" --- src/app/app-routing.module.ts | 1 + src/app/components/login/login.component.ts | 18 ++- src/gen/.openapi-generator/FILES | 5 +- src/gen/api/api.ts | 8 +- src/gen/api/hello.service.ts | 153 ------------------ .../{session.service.ts => token.service.ts} | 2 +- src/gen/model/errorResponse.ts | 4 - src/gen/model/helloResponse.ts | 15 -- src/gen/model/models.ts | 1 - 9 files changed, 20 insertions(+), 187 deletions(-) delete mode 100644 src/gen/api/hello.service.ts rename src/gen/api/{session.service.ts => token.service.ts} (99%) delete mode 100644 src/gen/model/helloResponse.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index ec41246..ecc8be8 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import {SigningComponent} from './components/signing/signing.component'; import {LoginComponent} from './components/login/login.component'; const routes: Routes = [ + {path: "", redirectTo: "signing-request/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", pathMatch: "full"}, {path: "login", component: LoginComponent}, {path: "signing-request/:id", component: SigningComponent} ]; diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 4d5d472..c38a8f6 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -1,6 +1,7 @@ -import {Component} from '@angular/core'; -import {CreateSessionRequest, CreateSessionResponse, SessionService} from '../../../gen'; +import {Component, OnInit} from '@angular/core'; +import {CreateSessionRequest, CreateSessionResponse, TokenService} from '../../../gen'; import {AuthService} from '../../services/auth.service'; +import {Router} from '@angular/router'; @Component({ selector: 'app-login', @@ -9,19 +10,26 @@ import {AuthService} from '../../services/auth.service'; templateUrl: './login.component.html', styleUrl: './login.component.css' }) -export class LoginComponent { +export class LoginComponent implements OnInit { createSessionRequest: CreateSessionRequest = { username: "", password: "" } - constructor(private sessionService: SessionService, private authService: AuthService) { + constructor(private tokenService: TokenService, private authService: AuthService, private router: Router) { + } + + ngOnInit(): void { + if (this.authService.getToken() != null) { + this.router.navigate(["/"]); + } } onSubmit(): void { - this.sessionService.createToken(this.createSessionRequest).subscribe({ + this.tokenService.createToken(this.createSessionRequest).subscribe({ next: (response: CreateSessionResponse): void => { this.authService.setToken(response.token); + this.router.navigate(["/"]); }, error: (err: Error): void => { console.log(err); diff --git a/src/gen/.openapi-generator/FILES b/src/gen/.openapi-generator/FILES index fe9b6af..3fc30b5 100644 --- a/src/gen/.openapi-generator/FILES +++ b/src/gen/.openapi-generator/FILES @@ -1,11 +1,11 @@ .gitignore +.openapi-generator-ignore README.md api.module.ts api/api.ts -api/hello.service.ts -api/session.service.ts api/signingRequest.service.ts api/signingRequestDocument.service.ts +api/token.service.ts configuration.ts encoder.ts git_push.sh @@ -15,7 +15,6 @@ model/createSessionResponse.ts model/errorResponse.ts model/getSigningRequestResponse.ts model/getSigningRequestResponseSigningRequestDocument.ts -model/helloResponse.ts model/models.ts model/patchOperation.ts param.ts diff --git a/src/gen/api/api.ts b/src/gen/api/api.ts index 1e104f3..1a08cf7 100644 --- a/src/gen/api/api.ts +++ b/src/gen/api/api.ts @@ -1,9 +1,7 @@ -export * from './hello.service'; -import { HelloService } from './hello.service'; -export * from './session.service'; -import { SessionService } from './session.service'; export * from './signingRequest.service'; import { SigningRequestService } from './signingRequest.service'; export * from './signingRequestDocument.service'; import { SigningRequestDocumentService } from './signingRequestDocument.service'; -export const APIS = [HelloService, SessionService, SigningRequestService, SigningRequestDocumentService]; +export * from './token.service'; +import { TokenService } from './token.service'; +export const APIS = [SigningRequestService, SigningRequestDocumentService, TokenService]; diff --git a/src/gen/api/hello.service.ts b/src/gen/api/hello.service.ts deleted file mode 100644 index 90ae370..0000000 --- a/src/gen/api/hello.service.ts +++ /dev/null @@ -1,153 +0,0 @@ -/** - * swisssign-challenge - dlmw - * - * Contact: dylan@dlmw.ch - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ -/* tslint:disable:no-unused-variable member-ordering */ - -import { Inject, Injectable, Optional } from '@angular/core'; -import { HttpClient, HttpHeaders, HttpParams, - HttpResponse, HttpEvent, HttpParameterCodec, HttpContext - } from '@angular/common/http'; -import { CustomHttpParameterCodec } from '../encoder'; -import { Observable } from 'rxjs'; - -// @ts-ignore -import { HelloResponse } from '../model/helloResponse'; - -// @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; -import { Configuration } from '../configuration'; - - - -@Injectable({ - providedIn: 'root' -}) -export class HelloService { - - protected basePath = 'http://localhost'; - public defaultHeaders = new HttpHeaders(); - public configuration = new Configuration(); - public encoder: HttpParameterCodec; - - constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string|string[], @Optional() configuration: Configuration) { - if (configuration) { - this.configuration = configuration; - } - if (typeof this.configuration.basePath !== 'string') { - const firstBasePath = Array.isArray(basePath) ? basePath[0] : undefined; - if (firstBasePath != undefined) { - basePath = firstBasePath; - } - - if (typeof basePath !== 'string') { - basePath = this.basePath; - } - this.configuration.basePath = basePath; - } - this.encoder = this.configuration.encoder || new CustomHttpParameterCodec(); - } - - - // @ts-ignore - private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams { - if (typeof value === "object" && value instanceof Date === false) { - httpParams = this.addToHttpParamsRecursive(httpParams, value); - } else { - httpParams = this.addToHttpParamsRecursive(httpParams, value, key); - } - return httpParams; - } - - private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams { - if (value == null) { - return httpParams; - } - - if (typeof value === "object") { - if (Array.isArray(value)) { - (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key)); - } else if (value instanceof Date) { - if (key != null) { - httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10)); - } else { - throw Error("key may not be null if value is Date"); - } - } else { - Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive( - httpParams, value[k], key != null ? `${key}.${k}` : k)); - } - } else if (key != null) { - httpParams = httpParams.append(key, value); - } else { - throw Error("key may not be null if value is not object or array"); - } - return httpParams; - } - - /** - * Get a hello from me - * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. - * @param reportProgress flag to report request and response progress. - */ - public getHello(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public getHello(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getHello(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getHello(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { - - let localVarHeaders = this.defaultHeaders; - - let localVarHttpHeaderAcceptSelected: string | undefined = options && options.httpHeaderAccept; - if (localVarHttpHeaderAcceptSelected === undefined) { - // to determine the Accept header - const httpHeaderAccepts: string[] = [ - 'application/json' - ]; - localVarHttpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts); - } - if (localVarHttpHeaderAcceptSelected !== undefined) { - localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); - } - - let localVarHttpContext: HttpContext | undefined = options && options.context; - if (localVarHttpContext === undefined) { - localVarHttpContext = new HttpContext(); - } - - let localVarTransferCache: boolean | undefined = options && options.transferCache; - if (localVarTransferCache === undefined) { - localVarTransferCache = true; - } - - - let responseType_: 'text' | 'json' | 'blob' = 'json'; - if (localVarHttpHeaderAcceptSelected) { - if (localVarHttpHeaderAcceptSelected.startsWith('text')) { - responseType_ = 'text'; - } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { - responseType_ = 'json'; - } else { - responseType_ = 'blob'; - } - } - - let localVarPath = `/hello`; - return this.httpClient.request('get', `${this.configuration.basePath}${localVarPath}`, - { - context: localVarHttpContext, - responseType: responseType_, - withCredentials: this.configuration.withCredentials, - headers: localVarHeaders, - observe: observe, - transferCache: localVarTransferCache, - reportProgress: reportProgress - } - ); - } - -} diff --git a/src/gen/api/session.service.ts b/src/gen/api/token.service.ts similarity index 99% rename from src/gen/api/session.service.ts rename to src/gen/api/token.service.ts index ecb48c5..9a318f6 100644 --- a/src/gen/api/session.service.ts +++ b/src/gen/api/token.service.ts @@ -32,7 +32,7 @@ import { Configuration } from '../configurat @Injectable({ providedIn: 'root' }) -export class SessionService { +export class TokenService { protected basePath = 'http://localhost'; public defaultHeaders = new HttpHeaders(); diff --git a/src/gen/model/errorResponse.ts b/src/gen/model/errorResponse.ts index 69e4672..4c5ed77 100644 --- a/src/gen/model/errorResponse.ts +++ b/src/gen/model/errorResponse.ts @@ -18,9 +18,5 @@ export interface ErrorResponse { * Machine-readable error code */ code: number; - /** - * Additional error details when available - */ - details?: object; } diff --git a/src/gen/model/helloResponse.ts b/src/gen/model/helloResponse.ts deleted file mode 100644 index 1c9e08a..0000000 --- a/src/gen/model/helloResponse.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * swisssign-challenge - dlmw - * - * Contact: dylan@dlmw.ch - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -export interface HelloResponse { - value?: string; -} - diff --git a/src/gen/model/models.ts b/src/gen/model/models.ts index b8ec8c4..fe17ce5 100644 --- a/src/gen/model/models.ts +++ b/src/gen/model/models.ts @@ -3,5 +3,4 @@ export * from './createSessionResponse'; export * from './errorResponse'; export * from './getSigningRequestResponse'; export * from './getSigningRequestResponseSigningRequestDocument'; -export * from './helloResponse'; export * from './patchOperation';