| | |
| | | import { http } from "./httpClient"; |
| | | import { AxiosResponse } from 'axios'; |
| | | import _ from "lodash"; |
| | | import AES from 'crypto-js/aes'; |
| | | 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"; |
| | |
| | | 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.'); |
| | |
| | | |
| | | /** 顧問登入 **/ |
| | | logInToConsultant(consultantDto:ConsultantLoginInfo, verificationCode: string):Promise<AxiosResponse<LoginSuccessToken>>{ |
| | | const encryptPassword = AES.encrypt(consultantDto.password, 'PAM KEY').toString(); |
| | | return http.post(`/eService/authenticate/${verificationCode}`, { ...consultantDto, password: encryptPassword }); |
| | | |
| | | 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'); |
| | | } |
| | | } |
| | | |