From f065760fa7df1f88747395ab4b55349ce8b2faf0 Mon Sep 17 00:00:00 2001 From: Tomas <tomasysh@gmail.com> Date: 星期一, 25 十二月 2023 13:35:43 +0800 Subject: [PATCH] Update#178944: 移除 lodash 套件 --- PAMapp/shared/services/login.service.ts | 37 +++++++++++++++++++------------------ 1 files changed, 19 insertions(+), 18 deletions(-) diff --git a/PAMapp/shared/services/login.service.ts b/PAMapp/shared/services/login.service.ts index 4b06bed..98ac692 100644 --- a/PAMapp/shared/services/login.service.ts +++ b/PAMapp/shared/services/login.service.ts @@ -1,7 +1,7 @@ -import { http } from "./httpClient"; import { AxiosResponse } from 'axios'; -import _ from "lodash"; -import CryptoJS from "crypto-js"; +import forge from "node-forge"; +import { http } from "./httpClient"; +// import CryptoJS from "asmcrypto-js"; import { ConsultantLoginInfo } from "../models/ConsultantLoginInfo"; import { LoginRequest } from "../models/loginRequest.model"; @@ -15,7 +15,8 @@ async sendOtp(loginInfo: LoginRequest, verifyCode: string): Promise<OtpInfo> { try { const response = await http.post(`/otp/sendOtp/${verifyCode}`, loginInfo); - if (response !== null) { + // 撘望�est1: �� if (response) + if (response) { return response.data; } else { throw new Error('http.post returned null-like value.'); @@ -70,8 +71,8 @@ return http.get('/login/validate/get_img_code',{ responseType : 'arraybuffer' }) .then( response => { const toBase64 = window.btoa( - _.reduce( new Uint8Array(response.data),(data,byte) => - data + String.fromCharCode(byte),'') + Array.from(new Uint8Array(response.data)).reduce((data, byte) => + data + String.fromCharCode(byte), '') ); const imgSrc = `data:image/jpeg;base64,${toBase64}`; return imgSrc; @@ -86,19 +87,19 @@ /** 憿批�� **/ logInToConsultant(consultantDto:ConsultantLoginInfo, verificationCode: string):Promise<AxiosResponse<LoginSuccessToken>>{ - const key = "PAMKEY1234567890"; - const iv = "0123456789abcdef"; + const iv = "0123456789abcdef"; + const key = "PAMKEY1234567890"; + const cipher = forge.cipher.createCipher('AES-GCM', key); + cipher.start({ + iv:iv + }); + cipher.update(forge.util.createBuffer(forge.util.encodeUtf8(consultantDto.password))); + cipher.finish(); + const encry = cipher.output; + var tag = cipher.mode.tag; + const encryptedPassword = window.btoa(encry.data+tag.data); - const keyBytes = CryptoJS.enc.Utf8.parse(key); - const ivBytes = CryptoJS.enc.Utf8.parse(iv); - - const encrypted = CryptoJS.AES.encrypt(consultantDto.password, keyBytes, { - iv: ivBytes, - mode: CryptoJS.mode.CBC, - padding: CryptoJS.pad.Pkcs7, - }); - - return http.post(`/eService/authenticate/${verificationCode}`, { ...consultantDto, password: encrypted.toString() }); + return http.post(`/eService/authenticate/${verificationCode}`, { ...consultantDto, password: encryptedPassword}); } async logout(): Promise<void> { -- Gitblit v1.9.3