From 60641fbfee245152b1e29b58368a73b681f330ae Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 3 Nov 2024 01:10:04 -0500 Subject: [PATCH] nice --- client/admin/package-lock.json | 25 ++++++ client/admin/package.json | 2 + client/admin/src/app/app.component.html | 83 ++++++++++++++----- client/admin/src/app/app.component.ts | 12 ++- client/admin/src/app/home/home.component.html | 4 +- client/admin/src/app/home/home.component.ts | 3 +- .../auth.service.spec.ts} | 0 .../{api.service.ts => login/auth.service.ts} | 12 ++- .../admin/src/app/login/login.component.html | 2 + client/admin/src/app/login/login.component.ts | 4 +- 10 files changed, 115 insertions(+), 32 deletions(-) rename client/admin/src/app/{api.service.spec.ts => login/auth.service.spec.ts} (100%) rename client/admin/src/app/{api.service.ts => login/auth.service.ts} (78%) diff --git a/client/admin/package-lock.json b/client/admin/package-lock.json index 6bc06a5..001805d 100644 --- a/client/admin/package-lock.json +++ b/client/admin/package-lock.json @@ -16,6 +16,8 @@ "@angular/platform-browser": "^18.2.0", "@angular/platform-browser-dynamic": "^18.2.0", "@angular/router": "^18.2.0", + "@ng-icons/core": "^29.6.1", + "@ng-icons/ionicons": "^29.6.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -3599,6 +3601,29 @@ "win32" ] }, + "node_modules/@ng-icons/core": { + "version": "29.6.1", + "resolved": "https://registry.npmjs.org/@ng-icons/core/-/core-29.6.1.tgz", + "integrity": "sha512-PyDLfmBA8rvMm2edQmSHV4fyPz0aImOW6/183YD8tIovDaWyk9imr3v2qSxlc1BjEnE355uPtPLXnvLs5hkEbQ==", + "license": "MIT", + "dependencies": { + "tslib": "^2.2.0" + }, + "peerDependencies": { + "@angular/common": ">=18.0.0", + "@angular/core": ">=18.0.0", + "rxjs": "^6.5.3 || ^7.4.0" + } + }, + "node_modules/@ng-icons/ionicons": { + "version": "29.6.1", + "resolved": "https://registry.npmjs.org/@ng-icons/ionicons/-/ionicons-29.6.1.tgz", + "integrity": "sha512-+ZIDHjFuqfVTexFfyw5vtasbxqpsQFcur5hKesOzzRqnq6o4KatNsCPjwY8GUoNviY/FKGwPSUXfsWj6YOnoDQ==", + "license": "MIT", + "dependencies": { + "tslib": "^2.2.0" + } + }, "node_modules/@ngtools/webpack": { "version": "18.2.10", "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-18.2.10.tgz", diff --git a/client/admin/package.json b/client/admin/package.json index ed8a8c3..9d72825 100644 --- a/client/admin/package.json +++ b/client/admin/package.json @@ -18,6 +18,8 @@ "@angular/platform-browser": "^18.2.0", "@angular/platform-browser-dynamic": "^18.2.0", "@angular/router": "^18.2.0", + "@ng-icons/core": "^29.6.1", + "@ng-icons/ionicons": "^29.6.1", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" diff --git a/client/admin/src/app/app.component.html b/client/admin/src/app/app.component.html index 76d1a6c..654db75 100644 --- a/client/admin/src/app/app.component.html +++ b/client/admin/src/app/app.component.html @@ -1,26 +1,63 @@ - -
- -
- -
- + +
-
- -
+ +
+ + +
+ +
diff --git a/client/admin/src/app/app.component.ts b/client/admin/src/app/app.component.ts index 039c2b7..0e83e90 100644 --- a/client/admin/src/app/app.component.ts +++ b/client/admin/src/app/app.component.ts @@ -1,13 +1,19 @@ -import { Component } from '@angular/core'; -import { RouterOutlet } from '@angular/router'; +import { Component, inject } from '@angular/core'; +import { RouterModule, RouterOutlet, RouterLink } from '@angular/router'; +import { CommonModule } from '@angular/common'; +import { AuthService } from './login/auth.service'; +import { NgIconComponent, provideIcons } from '@ng-icons/core'; +import { ionMenuOutline, ionChatbubbles, ionNewspaperOutline, ionAlertCircleOutline, ionRadioOutline, ionHome, ionMegaphoneOutline } from '@ng-icons/ionicons'; @Component({ selector: 'app-root', standalone: true, - imports: [RouterOutlet], + imports: [CommonModule, RouterOutlet, RouterModule, RouterLink, NgIconComponent], templateUrl: './app.component.html', styleUrl: './app.component.css', + providers: [ provideIcons({ ionMenuOutline, ionChatbubbles, ionNewspaperOutline, ionAlertCircleOutline, ionRadioOutline, ionHome, ionMegaphoneOutline })], }) export class AppComponent { + auth: AuthService = inject(AuthService); title = 'admin'; } diff --git a/client/admin/src/app/home/home.component.html b/client/admin/src/app/home/home.component.html index 98d12dd..d21c1f0 100644 --- a/client/admin/src/app/home/home.component.html +++ b/client/admin/src/app/home/home.component.html @@ -1 +1,3 @@ -

Hi

+

+This will be a dashboard someday. +

diff --git a/client/admin/src/app/home/home.component.ts b/client/admin/src/app/home/home.component.ts index 14c5108..40cb439 100644 --- a/client/admin/src/app/home/home.component.ts +++ b/client/admin/src/app/home/home.component.ts @@ -7,4 +7,5 @@ import { Component } from '@angular/core'; templateUrl: './home.component.html', styleUrl: './home.component.css', }) -export class HomeComponent {} +export class HomeComponent { +} diff --git a/client/admin/src/app/api.service.spec.ts b/client/admin/src/app/login/auth.service.spec.ts similarity index 100% rename from client/admin/src/app/api.service.spec.ts rename to client/admin/src/app/login/auth.service.spec.ts diff --git a/client/admin/src/app/api.service.ts b/client/admin/src/app/login/auth.service.ts similarity index 78% rename from client/admin/src/app/api.service.ts rename to client/admin/src/app/login/auth.service.ts index 0249ef7..1ed781d 100644 --- a/client/admin/src/app/api.service.ts +++ b/client/admin/src/app/login/auth.service.ts @@ -11,11 +11,18 @@ export class Jwt { @Injectable({ providedIn: 'root', }) -export class APIService { +export class AuthService { + loggedIn: boolean = false; constructor( private http: HttpClient, private _router: Router, - ) {} + ) { + let ssJWT = sessionStorage.getItem('jwt'); + if (ssJWT) { + this.loggedIn = true; + this._router.navigateByUrl('/home'); + } + } login(username: string, password: string): Observable> { return this.http @@ -28,6 +35,7 @@ export class APIService { tap((event) => { if (event.status == 200) { sessionStorage.setItem('jwt', event.body?.jwt.toString() ?? ''); + this.loggedIn = true; this._router.navigateByUrl('/home'); } }), diff --git a/client/admin/src/app/login/login.component.html b/client/admin/src/app/login/login.component.html index 511ceae..d8981fe 100644 --- a/client/admin/src/app/login/login.component.html +++ b/client/admin/src/app/login/login.component.html @@ -8,6 +8,7 @@ [(ngModel)]="username" class="grow" placeholder="login" + (keyup.enter)="onSubmit()" />
diff --git a/client/admin/src/app/login/login.component.ts b/client/admin/src/app/login/login.component.ts index 9446408..ec9e8c5 100644 --- a/client/admin/src/app/login/login.component.ts +++ b/client/admin/src/app/login/login.component.ts @@ -1,6 +1,6 @@ import { Component, inject } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { APIService } from '../api.service'; +import { AuthService } from '../login/auth.service'; import { catchError, of } from 'rxjs'; import { Router } from '@angular/router'; @@ -12,7 +12,7 @@ import { Router } from '@angular/router'; styleUrl: './login.component.css', }) export class LoginComponent { - apiService: APIService = inject(APIService); + apiService: AuthService = inject(AuthService); router: Router = inject(Router); username: string = ''; password: string = '';