保誠-保戶業務員媒合平台
Tomas
2023-09-01 bce34327a0aa3d6ea8365423df9962c13f256ab4
PAMapp/shared/services/login.service.ts
@@ -1,6 +1,9 @@
import { http } from "./httpClient";
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";
@@ -14,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.');
@@ -48,9 +52,21 @@
  }
  /** 顧客註冊 **/
  async register(registerInfo: RegisterInfo):Promise<LoginSuccessToken>{
    return http.post('/otp/register', registerInfo).then(res => res.data);
  async register(registerInfo: RegisterInfo): Promise<LoginSuccessToken> {
    try {
      const response = await http.post('/otp/register', registerInfo);
      if (response !== null) {
        return response.data;
      } else {
        throw new Error('http.post returned null-like value.');
      }
    } catch (error) {
      console.error('An error occurred while registering:', error);
      // 可以在此處處理錯誤或回傳預設值
      throw error;
    }
  }
  /** 取得驗證碼圖片 **/
  async getImgOfVerification():Promise<string>{
@@ -72,7 +88,24 @@
  /** 顧問登入 **/
  logInToConsultant(consultantDto:ConsultantLoginInfo, verificationCode: string):Promise<AxiosResponse<LoginSuccessToken>>{
    return http.post(`/eService/authenticate/${verificationCode}`,consultantDto);
  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);
    return http.post(`/eService/authenticate/${verificationCode}`, { ...consultantDto, password: encryptedPassword});
  }
  async logout(): Promise<void> {
    return http.post('/logout');
  }
}