保誠-保戶業務員媒合平台
jack
2023-09-05 3ecee0fa557b7bb9e83b67e289b316f04efa9ce5
PAMapp/shared/services/login.service.ts
@@ -2,6 +2,8 @@
import { AxiosResponse } from 'axios';
import _ from "lodash";
import CryptoJS from "crypto-js";
import forge from "node-forge";
// import CryptoJS from "asmcrypto-js";
import { ConsultantLoginInfo } from "../models/ConsultantLoginInfo";
import { LoginRequest } from "../models/loginRequest.model";
@@ -15,7 +17,8 @@
    async sendOtp(loginInfo: LoginRequest, verifyCode: string): Promise<OtpInfo> {
      try {
        const response = await http.post(`/otp/sendOtp/${verifyCode}`, loginInfo);
        if (response !== null) {
        // 弱掃Test1: 改為 if (response)
        if (response) {
          return response.data;
        } else {
          throw new Error('http.post returned null-like value.');
@@ -86,22 +89,24 @@
  /** 顧問登入 **/
  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> {
    return http.post('/logout');
  }
}
export default new LoginService();