Commit b09aa89f by sawit

Set token

parent b7dfe12f
......@@ -6,7 +6,7 @@
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-8">
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/myhr-plus/dashboard">
(click)="checkAppToken('myhr-plus')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/myhr-plus.jpg" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -16,7 +16,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/myhr-lite/dashboard">
(click)="checkAppToken('myhr-lite')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/myHR-Lite-logo-new.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -26,7 +26,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/zeeme/dashboard">
(click)="checkAppToken('zeeme')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/zeemePlus.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -36,7 +36,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/myface/dashboard">
(click)="checkAppToken('myface')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/logo_myface.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -46,7 +46,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/mylearn/mylearn-pdpa-manage">
(click)="checkAppToken('mylearn')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/mylearn-logo.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -56,7 +56,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/myjob/pdpa-manage">
(click)="checkAppToken('myjob')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/logo_myjob.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......@@ -66,7 +66,7 @@
</a>
<a class="card bg-white rounded-xl p-8 text-center shadow-lg transition-all duration-300 ease-in-out transform hover:scale-105 hover:shadow-xl hover:bg-gradient-to-br from-blue-50 to-blue-100"
routerLink="/myskill-x/portal-category-list">
(click)="checkAppToken('myskill-x')">
<div class="card-icon text-5xl text-indigo-700 mb-4 transition-transform duration-300 ease-in-out group-hover:scale-110">
<img src="./assets/images/logoallHR/mySkill-x.png" alt="miscrosoft"
class="leading-[1.75] text-2xl !h-[5rem] align-middle flex justify-center mx-auto">
......
import { Component } from '@angular/core';
import { Router, RouterLink } from '@angular/router';
import { TokenService } from '../../shared/services/token.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.scss'],
standalone: true,
imports: [RouterLink]
// imports: [RouterLink]
})
export class HomeComponent {
constructor(private router: Router) { }
constructor(
private router: Router,
private tokenService: TokenService,
) { }
logout() {
localStorage.removeItem('authToken'); // Clear the authentication token
this.router.navigate(['/auth/login']); // Navigate to the login page
}
checkAppToken(appmodule:string){
this.tokenService.saveAppToken(appmodule)
this.router.navigate(['/'+appmodule])
}
}
......@@ -32,8 +32,8 @@ export class HttpRequestInterceptor {
// ใช้ fixed token หาก url เป็น portal.myhr.co.th
if (fullUrl.startsWith(environment.url)) {
token = `Bearer ${environment.portalFixedToken}`;
} else if (this.tokenService.getToken()) {
token = `Bearer ${this.tokenService.getToken()}`;
} else if (this.tokenService.getAppToken()) {
token = `Bearer ${this.tokenService.getAppToken()}`;
}
let authReq = req.clone({ url: fullUrl });
......
......@@ -5,9 +5,11 @@ import { jwtDecode } from "jwt-decode";
import { ProfileModel, UserModel } from "../user-auth.model";
import { UserProfileModel } from "../../DPU/models/user.model";
import { CompanyModel } from "../../DPU/models/company.model";
import { environment } from "../../../environments/environment";
// import jwt_decode from "jwt-decode";
const TOKEN_KEY = 'auth-token';
const APP_TOKEN_KEY = 'app-token';
const REFRESHTOKEN_KEY = 'auth-refreshtoken';
const USER_KEY = 'auth-user';
const USER_DATA_KEY = 'auth-user-data';
......@@ -17,6 +19,18 @@ const COMPANY = 'company';
providedIn: "root",
})
export class TokenService {
static getAppTokenModule(arg0: string) {
throw new Error('Method not implemented.');
}
apptoken: any = {
"myhr-plus" : "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJBdXRoIiwidWlkIjoiOGFhNDUzMzAtMzE0Yy0xMWU3LWJhZjMtMmQ3ZDA5ODc3NzQ0Iiwicm9sZXMiOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGl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iOlsiYWRtaW4iXSwiaXNzIjoiQ29tcHV0ZXIgU2NpZW5jZSBDb3Jwb3JhdGlvbiBMaW1pdGVkIiwidXNlcm5hbWUiOiJhZG1pbiJ9.Um39_CTM01n1g4XpFyuAa3VPxOozNPnJ0mu7kxU6KUs",
}
constructor(private router: Router) { }
signOut(): void {
......@@ -90,4 +104,14 @@ export class TokenService {
return new CompanyModel();
}
public saveAppToken(module: string): void {
let tokenkey = this.apptoken[module]
window.localStorage.removeItem(APP_TOKEN_KEY);
window.localStorage.setItem(APP_TOKEN_KEY, tokenkey);
}
public getAppToken(): string | null {
return window.localStorage.getItem(APP_TOKEN_KEY);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment