Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"core-js": "^3.29.1",
"dayjs": "^1.11.7",
"element-ui": "^2.15.13",
"jsencrypt": "^3.3.2",
"vue": "^2.6.14",
"vue-i18n": "^8.28.2",
"vue-router": "^3.6.5",
Expand Down
4 changes: 4 additions & 0 deletions src/config/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ const GROUP_API_URL = "/group";
export const GROUP_ADD_URL = `${GROUP_API_URL}/add`;
export const GROUP_LIST_URL = `${GROUP_API_URL}/list`;
export const GROUP_SEARCH_URL = `${GROUP_API_URL}/search`;

// 通用API
const COMMON_API_URL = "/common";
export const COMMON_PUBLIC_KEY_URL = `${COMMON_API_URL}/public-key`
21 changes: 16 additions & 5 deletions src/services/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ import {
RELATION_ADD_URL,
GROUP_ADD_URL,
GROUP_SEARCH_URL,
COMMON_PUBLIC_KEY_URL,
} from "@/config/api";
import { OPENAI_API_KEY, OPENAI_MAKING_REQUEST } from "@/config/openai";
import encrypt from "@/utils/crypto";

export default {
loginUser: (username, password) => {
return post(USER_LOGIN_URL, {
username,
password,
loginUser: async (username, password) => {
let publicKey;
await get(COMMON_PUBLIC_KEY_URL)
.then((res) => {
publicKey = res.data.data["public-key"];
})
.catch((err) => {
console.log("Error: " + err);
});

return post(USER_LOGIN_URL, null, {
username: encrypt(publicKey, username),
password: encrypt(publicKey, password),
});
},
registerUser: (username, password) => {
return post(USER_REGISTER_URL, {
return post(USER_REGISTER_URL, null, {
username,
password,
});
Expand Down
11 changes: 11 additions & 0 deletions src/utils/crypto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import JSEncrypt from "jsencrypt";
function encrypt(publicKey, text) {
// 创建加密实例
var crypt = new JSEncrypt();

// 设置公钥
crypt.setPublicKey(publicKey);
return crypt.encrypt(text);
}

export default encrypt;