dashboard
This commit is contained in:
@@ -1,2 +1 @@
|
||||
<router-outlet></router-outlet>
|
||||
iodsuj
|
||||
<router-outlet></router-outlet>
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import { LoginComponent } from './auth/login/login.component';
|
||||
import { RegisterComponent } from './auth/register/register.component';
|
||||
import { DashboardComponent } from './dashboard/dashboard.component';
|
||||
|
||||
export const routes: Routes = [
|
||||
{ path: 'login', component: LoginComponent },
|
||||
{ path: 'register', component: RegisterComponent },
|
||||
{ path: 'dashboard', component: DashboardComponent },
|
||||
{ path: '', component: LoginComponent },
|
||||
];
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<i class="login__icon fas fa-lock safe"></i>
|
||||
<input type="password" formControlName="password" class="login__input" placeholder="Password">
|
||||
</div>
|
||||
<button class="button login__submit" (click)="login()" [disabled]="!client_id || loginForm.invalid || isLoading">
|
||||
<button class="button login__submit" (click)="login()" [disabled]="loginForm.invalid || isLoading">
|
||||
<span class="button__text">Log In Now</span>
|
||||
<i class="button__icon fas fa-chevron-right"></i>
|
||||
</button>
|
||||
|
||||
@@ -35,7 +35,7 @@ export class LoginComponent {
|
||||
}
|
||||
|
||||
loginWithSessionId() {
|
||||
const id = window.localStorage.getItem("auth_sesion_key");
|
||||
const id = window.localStorage.getItem("auth_session_key");
|
||||
if (!id ||id.length < 2) { return; }
|
||||
|
||||
this.http.post('api/auth/login-with-session-id', {
|
||||
@@ -50,7 +50,15 @@ export class LoginComponent {
|
||||
).subscribe({
|
||||
next: (data) => {
|
||||
if (data["code"] != null) {
|
||||
location.href = this.redirectUri + "?code=" + data["code"];
|
||||
if (this.redirectUri) {
|
||||
location.href = this.redirectUri + "?code=" + data["code"];
|
||||
} else {
|
||||
if (data['user'] && data['user']['access']) {
|
||||
sessionStorage.setItem('access', data['user']['access']);
|
||||
this.router.navigate(['dashboard'])
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
@@ -91,8 +99,15 @@ export class LoginComponent {
|
||||
.subscribe({
|
||||
next: (data) => {
|
||||
if (data["code"] != null) {
|
||||
window.localStorage.setItem("auth_sesion_key", data["session_key"]);
|
||||
location.href = this.redirectUri + "?code=" + data["code"];
|
||||
window.localStorage.setItem("auth_session_key", data["session_key"]);
|
||||
if (this.redirectUri) {
|
||||
location.href = this.redirectUri + "?code=" + data["code"];
|
||||
} else {
|
||||
if (data['user'] && data['user']['access']) {
|
||||
sessionStorage.setItem('access', data['user']['access']);
|
||||
this.router.navigate(['dashboard'])
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
|
||||
1
idp_client/src/app/dashboard/dashboard.component.html
Normal file
1
idp_client/src/app/dashboard/dashboard.component.html
Normal file
@@ -0,0 +1 @@
|
||||
<p>dashboard works!</p>
|
||||
23
idp_client/src/app/dashboard/dashboard.component.spec.ts
Normal file
23
idp_client/src/app/dashboard/dashboard.component.spec.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { DashboardComponent } from './dashboard.component';
|
||||
|
||||
describe('DashboardComponent', () => {
|
||||
let component: DashboardComponent;
|
||||
let fixture: ComponentFixture<DashboardComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [DashboardComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(DashboardComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
52
idp_client/src/app/dashboard/dashboard.component.ts
Normal file
52
idp_client/src/app/dashboard/dashboard.component.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Component, inject, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { User } from '../model/user.interface';
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
standalone: true,
|
||||
imports: [],
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrl: './dashboard.component.scss'
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
private router: Router = inject(Router);
|
||||
private http: HttpClient = inject(HttpClient);
|
||||
private user: User;
|
||||
|
||||
accessToken: string;
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
|
||||
const refresh = sessionStorage.getItem('access');
|
||||
if (!refresh || refresh.length == 0) {
|
||||
this.router.navigate(['login']);
|
||||
} else {
|
||||
this.accessToken = refresh;
|
||||
this.refreshToken(refresh);
|
||||
this.getClients();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
refreshToken(token: string) {
|
||||
this.http.post('api/auth/verify', { access_token: token}).subscribe({
|
||||
next: res => {
|
||||
console.log(res)
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
getClients() {
|
||||
this.http.get('api/client', {headers: { auth: 'Bearer ' + this.accessToken}}).subscribe({
|
||||
next: result => {
|
||||
console.log(result);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
7
idp_client/src/app/model/user.interface.ts
Normal file
7
idp_client/src/app/model/user.interface.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export interface User {
|
||||
id: string;
|
||||
username: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
createdAt: string;
|
||||
}
|
||||
Reference in New Issue
Block a user