implement token exp
This commit is contained in:
parent
d8dc510742
commit
f86f727ac7
|
@ -13,7 +13,7 @@
|
|||
href="https://allbestsistem.com/"
|
||||
target="_blank"
|
||||
style="background-color: #000000 !important;"
|
||||
>Smart Building Management Systems (V@2024-07-9.01)
|
||||
>Smart Building Management Systems (V@2024-07-9.02)
|
||||
</a></span
|
||||
>
|
||||
</p>
|
||||
|
|
|
@ -7,6 +7,7 @@ import "chartist-plugin-tooltips";
|
|||
import { ModalExportComponent } from "./modal-export/modal-export.component";
|
||||
import { TableexcelService } from "src/app/_services/tableexcel.service";
|
||||
import { ToastrService } from "ngx-toastr";
|
||||
import { LoginService } from "../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-cost-management",
|
||||
|
@ -49,9 +50,11 @@ export class CostManagementComponent implements OnInit {
|
|||
private modalService: NgbModal,
|
||||
private tableexcelService: TableexcelService,
|
||||
private toastr: ToastrService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Cost Management",
|
||||
links: [
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
|
|||
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { CostManagementService } from "../../service/cost-management.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-modal-add-actual",
|
||||
|
@ -22,12 +23,14 @@ export class ModalAddActualComponent {
|
|||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private fb: FormBuilder,
|
||||
private costService: CostManagementService
|
||||
private costService: CostManagementService,
|
||||
private authService: LoginService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
const currentDate = new Date();
|
||||
this.dateCurrent = currentDate.toISOString().slice(0, 7);
|
||||
this.dateFormat();
|
||||
|
|
|
@ -3,6 +3,7 @@ import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
|||
import { DeviceService } from "../../service/device.service";
|
||||
import { CostManagementService } from "../../service/cost-management.service";
|
||||
import { TableexcelService } from "src/app/_services/tableexcel.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-modal-export",
|
||||
|
@ -24,10 +25,12 @@ export class ModalExportComponent {
|
|||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private costService: CostManagementService,
|
||||
private tableexcelService: TableexcelService
|
||||
private tableexcelService: TableexcelService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
const dateRow = this.convertToUTC7(this.dataRow.endDate)
|
||||
this.formattedEndDate = dateRow.slice(0, 7);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms";
|
|||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { BlockUI, NgBlockUI } from "ng-block-ui";
|
||||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-add-edit-device",
|
||||
|
@ -36,9 +37,11 @@ export class AddEditDeviceComponent implements OnInit{
|
|||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.route.params.subscribe(params => {
|
||||
const id = params['id'];
|
||||
this.deviceId = id;
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Router } from "@angular/router";
|
|||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { DeviceService } from "../../service/device.service";
|
||||
import { ToastrService } from "ngx-toastr";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-device-control",
|
||||
|
@ -32,10 +33,12 @@ export class DeviceControlComponent {
|
|||
private router: Router,
|
||||
private deviceService: DeviceService,
|
||||
private monitoringApiService: BuildingService,
|
||||
private toastr: ToastrService
|
||||
private toastr: ToastrService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Device",
|
||||
links: [
|
||||
|
|
|
@ -9,6 +9,7 @@ import { ToastrService } from "ngx-toastr";
|
|||
import * as FileSaver from "file-saver";
|
||||
import * as XLSX from "xlsx";
|
||||
import { TableexcelService } from "src/app/_services/tableexcel.service";
|
||||
import { LoginService } from "../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-device",
|
||||
|
@ -47,10 +48,12 @@ export class DeviceComponent implements OnInit {
|
|||
private monitoringApiService: BuildingService,
|
||||
private deviceService: DeviceService,
|
||||
private toastr: ToastrService,
|
||||
private tableexcelService: TableexcelService
|
||||
private tableexcelService: TableexcelService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Device",
|
||||
links: [
|
||||
|
|
|
@ -3,6 +3,7 @@ import { FormArray, FormBuilder, FormGroup, NgForm, Validators } from '@angular/
|
|||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BlockUI, NgBlockUI } from 'ng-block-ui';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-edit-list',
|
||||
|
@ -36,9 +37,11 @@ export class AddEditListComponent {
|
|||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.route.data.subscribe((data) => {
|
||||
this.mode = data.mode;
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ import { Router } from "@angular/router";
|
|||
import { TableApiService } from "src/app/_services/table-api.service";
|
||||
import { BuildingService } from "../service/monitoring-api.service";
|
||||
import Swal from "sweetalert2";
|
||||
import { LoginService } from "../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-list-monitoring",
|
||||
|
@ -19,10 +20,12 @@ export class ListMonitoringComponent {
|
|||
constructor(
|
||||
private tableApiservice: TableApiService,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Cost Management",
|
||||
links: [
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, Input, OnInit } from "@angular/core";
|
|||
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-add-edit-master",
|
||||
|
@ -21,10 +22,12 @@ export class AddEditMasterComponent implements OnInit {
|
|||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private fb: FormBuilder,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.createForm();
|
||||
this.dataListMaster();
|
||||
if (this.mode === "add") {
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
|
|||
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { BuildingService } from "../../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-add-edit-master-building",
|
||||
|
@ -21,10 +22,12 @@ export class AddEditMasterBuildingComponent {
|
|||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private fb: FormBuilder,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.createForm();
|
||||
this.listDataStatus();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
|||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { AddEditMasterBuildingComponent } from './add-edit-master-building/add-edit-master-building.component';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-building',
|
||||
|
@ -22,10 +23,12 @@ export class MasterBuildingComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Building",
|
||||
links: [
|
||||
|
|
|
@ -6,6 +6,7 @@ import { TableApiService } from "src/app/_services/table-api.service";
|
|||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { AddEditMasterComponent } from "../add-edit-master/add-edit-master.component";
|
||||
import { ToastrService } from "ngx-toastr";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-master-category",
|
||||
|
@ -27,10 +28,12 @@ export class MasterCategoryComponent implements OnInit {
|
|||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService,
|
||||
private toastr: ToastrService
|
||||
private toastr: ToastrService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Category",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
|
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-duration-use',
|
||||
|
@ -22,10 +23,12 @@ export class MasterDurationUseComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Duration Use",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
|
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-floor',
|
||||
|
@ -22,10 +23,12 @@ export class MasterFloorComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Floor",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
|
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-role',
|
||||
|
@ -22,10 +23,12 @@ export class MasterRoleComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Role",
|
||||
links: [
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, Input } from "@angular/core";
|
|||
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
|
||||
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { BuildingService } from "../../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-add-edit-master-room",
|
||||
|
@ -24,10 +25,12 @@ export class AddEditMasterRoomComponent {
|
|||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private fb: FormBuilder,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.createForm();
|
||||
this.listDataStatus();
|
||||
this.listDataBuilding();
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from "src/app/_services/table-api.service";
|
|||
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
|
||||
import { Router } from "@angular/router";
|
||||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-master-room",
|
||||
|
@ -19,10 +20,12 @@ export class MasterRoomComponent {
|
|||
|
||||
constructor(
|
||||
private modalService: NgbModal,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Room",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
|||
import { TableApiService } from 'src/app/_services/table-api.service';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { AddEditMasterComponent } from '../add-edit-master/add-edit-master.component';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-status',
|
||||
|
@ -22,10 +23,12 @@ export class MasterStatusComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Status",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
|
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-type',
|
||||
|
@ -22,10 +23,12 @@ export class MasterTypeComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Type",
|
||||
links: [
|
||||
|
|
|
@ -4,6 +4,7 @@ import { TableApiService } from 'src/app/_services/table-api.service';
|
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Router } from '@angular/router';
|
||||
import { BuildingService } from '../../service/monitoring-api.service';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-master-voltage',
|
||||
|
@ -22,10 +23,12 @@ export class MasterVoltageComponent {
|
|||
private tableApiservice: TableApiService,
|
||||
private modalService: NgbModal,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Master Voltage",
|
||||
links: [
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component } from "@angular/core";
|
|||
import { TableMonitoringService } from "../monitoring.service";
|
||||
import { Router } from "@angular/router";
|
||||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-building",
|
||||
|
@ -21,10 +22,12 @@ export class BuildingComponent {
|
|||
constructor(
|
||||
private monitoringService: TableMonitoringService,
|
||||
private monitoringApiService: BuildingService,
|
||||
private router: Router
|
||||
private router: Router,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.breadcrumb = {
|
||||
mainlabel: "Dashboard",
|
||||
links: [
|
||||
|
|
|
@ -3,6 +3,7 @@ import { BuildingService } from '../../service/monitoring-api.service';
|
|||
import { DeviceService } from '../../service/device.service';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { LoginService } from '../../service/login.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-control-device-seemore',
|
||||
|
@ -32,9 +33,11 @@ export class ControlDeviceSeemoreComponent {
|
|||
private monitoringApiService: BuildingService,
|
||||
private route: ActivatedRoute,
|
||||
private toastr: ToastrService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.route.params.subscribe((params) => {
|
||||
const buildingId = params["id"];
|
||||
this.paramsId = buildingId ? buildingId: 0;
|
||||
|
|
|
@ -3,6 +3,7 @@ import { ActivatedRoute, Router } from "@angular/router";
|
|||
import { ChartOptions, ChartType, ChartDataset } from "chart.js";
|
||||
import { EnergyMonitoringService } from "../../service/energy-monitoring.service";
|
||||
import { CurrencyPipe } from "@angular/common";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-detail",
|
||||
|
@ -126,6 +127,7 @@ export class DetailComponent {
|
|||
private energyMonitoringService: EnergyMonitoringService,
|
||||
private currencyPipe: CurrencyPipe,
|
||||
private router: Router,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
get formattedSummaryCost(): string {
|
||||
|
@ -138,6 +140,7 @@ export class DetailComponent {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.route.data.subscribe((data) => {
|
||||
this.mode = data.mode;
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import { Component, OnInit } from "@angular/core";
|
|||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { TableMonitoringService } from "../monitoring.service";
|
||||
import { BuildingService } from "../../service/monitoring-api.service";
|
||||
import { LoginService } from "../../service/login.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-room",
|
||||
|
@ -20,9 +21,11 @@ export class RoomComponent implements OnInit {
|
|||
private monitoringService: TableMonitoringService,
|
||||
private router: Router,
|
||||
private monitoringApiService: BuildingService,
|
||||
private authService: LoginService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.route.data.subscribe((data) => {
|
||||
this.mode = data.mode;
|
||||
console.log(this.mode);
|
||||
|
|
|
@ -1,21 +1,40 @@
|
|||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient, HttpHeaders } from "@angular/common/http";
|
||||
import { Observable } from "rxjs";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { Router } from "@angular/router";
|
||||
import { AuthService } from "src/app/_services/auth.service";
|
||||
|
||||
const BASE_URL = 'https://kapi.absys.ninja/hemat';
|
||||
const BASE_URL = "https://kapi.absys.ninja/hemat";
|
||||
interface CustomJwtPayload {
|
||||
exp: number;
|
||||
scope: string;
|
||||
iat: number;
|
||||
preferred_username: string;
|
||||
name: string;
|
||||
email: string;
|
||||
family_name: string;
|
||||
given_name: string;
|
||||
sub: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: "root",
|
||||
})
|
||||
export class LoginService {
|
||||
constructor(private http: HttpClient) {}
|
||||
private readonly tokenKey = "currentUser";
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private router: Router,
|
||||
public logoutService: AuthService
|
||||
) {}
|
||||
|
||||
updatePassword(data: any): Observable<any> {
|
||||
const endpoint = `/users`;
|
||||
const url = `${BASE_URL}${endpoint}/reset-password`;
|
||||
const headers = new HttpHeaders({
|
||||
'Content-Type': 'application/json',
|
||||
'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT'
|
||||
"Content-Type": "application/json",
|
||||
"x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT",
|
||||
});
|
||||
return this.http.put<any>(url, data, { headers });
|
||||
}
|
||||
|
@ -51,4 +70,33 @@ export class LoginService {
|
|||
return this.http.post(`${url}`, body, { headers });
|
||||
}
|
||||
|
||||
isTokenExpired(): boolean {
|
||||
const tokenData = localStorage.getItem(this.tokenKey);
|
||||
if (tokenData) {
|
||||
const tokenInfo = JSON.parse(tokenData);
|
||||
const decodedToken = jwtDecode<CustomJwtPayload>(tokenInfo.refresh_token);
|
||||
const expiryDate = decodedToken.exp * 1000;
|
||||
const now = new Date().getTime();
|
||||
return now > expiryDate;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
checkTokenAndRedirect(): void {
|
||||
if (this.isTokenExpired()) {
|
||||
// Token sudah kedaluwarsa, arahkan ke halaman login
|
||||
// console.log("Token expired, redirecting to login page...");
|
||||
this.logoutService.doLogout().then(
|
||||
(res) => {
|
||||
this.router.navigate(["/login"]);
|
||||
},
|
||||
(err) => {
|
||||
console.log(err);
|
||||
}
|
||||
);
|
||||
this.router.navigate(["/login"]);
|
||||
} else {
|
||||
console.log("Token is valid, continuing...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms";
|
|||
import { LoginService } from "../../service/login.service";
|
||||
import { ToastrService } from "ngx-toastr";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { AuthService } from "src/app/_services/auth.service";
|
||||
import { Router } from "@angular/router";
|
||||
interface CustomJwtPayload {
|
||||
exp: number;
|
||||
scope: string;
|
||||
|
@ -35,12 +37,16 @@ export class ProfilInformationComponent {
|
|||
constructor(
|
||||
private formBuilder: FormBuilder,
|
||||
private authService: LoginService,
|
||||
private toastr: ToastrService
|
||||
private toastr: ToastrService,
|
||||
public logoutService: AuthService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.storedData = JSON.parse(localStorage.getItem("account_info"));
|
||||
this.currentUser = JSON.parse(localStorage.getItem("currentUser"));
|
||||
this.authService.checkTokenAndRedirect();
|
||||
|
||||
this.profilInfo = this.formBuilder.group({
|
||||
firstName: ["", Validators.required],
|
||||
lastName: ["", Validators.required],
|
||||
|
|
|
@ -40,6 +40,7 @@ export class UpdatePasswordComponent {
|
|||
|
||||
ngOnInit(): void {
|
||||
this.storedData = JSON.parse(localStorage.getItem("account_info"));
|
||||
this.authService.checkTokenAndRedirect();
|
||||
this.profilInfo = this.formBuilder.group({
|
||||
userid: this.storedData.sub,
|
||||
currentPass: [""],
|
||||
|
|
|
@ -138,7 +138,7 @@
|
|||
<p
|
||||
class="card-subtitle line-on-side text-muted text-center font-small-3 mx-2 my-1"
|
||||
>
|
||||
<span>(v@2024.07.9.01)</span>
|
||||
<span>(v@2024.07.9.02)</span>
|
||||
</p>
|
||||
<!-- <div class="card-body">
|
||||
<a
|
||||
|
|
Loading…
Reference in New Issue