parent
157a7f99d2
commit
76e8dab193
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Launch Package",
|
||||||
|
"type": "go",
|
||||||
|
"request": "launch",
|
||||||
|
"mode": "auto",
|
||||||
|
"program": "~/WorkSpace/GinSkeleto",
|
||||||
|
"env": {},
|
||||||
|
"args": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
## 获取公钥
|
||||||
|
/admin/users/publickey
|
||||||
|
参数字段|参数属性|类型|选项|
|
||||||
|
user_name|form-data|string|必填
|
||||||
|
> 返回示例:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"code": 200,
|
||||||
|
"data": {
|
||||||
|
"PublicKey": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFrZUx2RWNpS3o5UytUQ3E1VnE5MQpTU2RaNm55d3VzbHNPRzAzZnY1VXMxVzJTR0ZDVnpTY3N6aWlLYlIrQk9FR3JsSVRQN29Yb2w3enhQUm55eTczCkZjTkRDOHQwQlhxcGR0U3pkL3V1N1JndXpDYW5BYXVaRXh4RERLUmZEV0MrR0p4TUlBaUV0VHJwT1d6dWp1azgKbDdDMWprTlRhQUpBMmx6ODA2ZWNHZ1NIcFg4MHhCZUpwV3lERnF2N3J3eS9EWjhaekQvRTNXa2ZLREUvRzFFTApPNWRBWUg0QXoxcVQ3SHFEY0hpVVlrNGFDWUswb1pJSC9hSXlKRjhnMDVIbER6NUN2eXNXZVZCTWljT0VRaXQxCnJMaDRaWVhqSVAyVEZmYU5hTlpuVVdhR1BCc05VRThjRU92MlA1d3ZHazFGL29yQ0NyNlFQRytBVE00SU1EME4KR3dJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg=="
|
||||||
|
},
|
||||||
|
"msg": "Success"
|
||||||
|
}
|
||||||
|
```
|
@ -0,0 +1,73 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Login</title>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsencrypt/3.2.1/jsencrypt.min.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form id="loginForm">
|
||||||
|
<input type="text" id="username" placeholder="Username" required>
|
||||||
|
<input type="password" id="password" placeholder="Password" required>
|
||||||
|
<button type="submit">Login</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
document.getElementById('loginForm').addEventListener('submit', async function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const username = document.getElementById('username').value;
|
||||||
|
const password = document.getElementById('password').value;
|
||||||
|
|
||||||
|
// Fetch the public key from the server
|
||||||
|
const response = await fetch('http://localhost:14514/admin/users/publickey?user_name=joefalmko',{
|
||||||
|
method: 'POST',
|
||||||
|
});
|
||||||
|
const publicKey = await response.text();
|
||||||
|
console.log("public key:\n",publicKey);
|
||||||
|
|
||||||
|
// Encrypt the password using the public key
|
||||||
|
const encrypt = new JSEncrypt();
|
||||||
|
encrypt.setPublicKey(publicKey);
|
||||||
|
const encryptedPassword = encrypt.encrypt(password);
|
||||||
|
console.log("encrypted password: ",encryptedPassword);
|
||||||
|
|
||||||
|
// Send the login request
|
||||||
|
const loginResponse = await fetch('http://localhost:14514/admin/users/login', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ user_name:username, pass: encryptedPassword })
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await loginResponse.json();
|
||||||
|
console.log(result);
|
||||||
|
// if (result.success == "true") {
|
||||||
|
// localStorage.setItem('token', result.token);
|
||||||
|
// alert('Login successful!');
|
||||||
|
// alert("token: " + result.token);
|
||||||
|
// console.log(fetchWithAuth('auth/index'));
|
||||||
|
// } else {
|
||||||
|
// alert('Login failed!');
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
// function fetchWithAuth(url, options = {}) {
|
||||||
|
// const token = localStorage.getItem('token'); // 从本地存储获取token
|
||||||
|
// if (token) {
|
||||||
|
// options.headers = {
|
||||||
|
// ...options.headers,
|
||||||
|
// 'Authorization': `Bearer ${token}`
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
// return fetch(url, options).then(response => {
|
||||||
|
// if (response.status === 401) {
|
||||||
|
// window.location.href = '/'; // 重定向到登录页面
|
||||||
|
// throw new Error('Unauthorized');
|
||||||
|
// }
|
||||||
|
// return response;
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
Loading…
Reference in new issue