add api doc

master
joefalmko 1 month ago
parent 76e8dab193
commit 4e9ae56c97

@ -1,13 +1,186 @@
## 获取公钥
/admin/users/publickey
参数字段|参数属性|类型|选项|
### 验证码
无需校验参数
##### 获取验证码
> <font color=#FF4500>*GET*/captcha </font>
> 返回示例:
```json
{
"code": 200,
"data": {
"id": "ECAZBGqD6ORferpWPx9y",
"img_url": "/captcha/ECAZBGqD6ORferpWPx9y.png",// 验证码图片地址
"refresh": "/captcha/ECAZBGqD6ORferpWPx9y.png?reload=1",
"verify": "/captcha/ECAZBGqD6ORferpWPx9y/这里替换为正确的验证码进行验证"
},
"msg": "验证码信息"
}
```
#### 验证验证码
> <font color=#FF4500>*GET*/captcha/:captcha_id/:captcha_value </font>
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "验证码校验通过"
}
```
## 用户相关
### 无需鉴权
#### 获取公钥
> <font color=#FF4500>*POST*/admin/users/publickey </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
> 返回示例:
```
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAw/GsJEfppPkaZXGt7uKr
q2UOsCEzrtPYz/DDUCjJzWnr725FoNqT77B33QbET995hay8j8Bcwwj7APkUYKyt
RoNUOJkaWgAqpNp9/TKhulFex8ycEaI1lG0kzqPQtcNjIQyqOQ1qSyXb8BxFFN5+
zvuWdpb4lI8YxZGg9+n77qtmr2an7d4ADIsRVAejJuoDWB56RovVuiLihG71Wfam
V1HhGf0ykWfyamd1HxN74hdBICbpChWPCmD/S2MwBMViM+TfCu5D15DxP5ZkADLU
vV81YIKBLg6KZUV7N7oZzzJqiEmpeis4QO4ABf/KRQ9KVRe4dcJFi4E0uVCBKGm8
1QIDAQAB
-----END PUBLIC KEY-----
```
> 加密参考 */test/login_test.html*
> 用户发送密码必须通过加密,否则会产生错误
```javascript
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);
```
#### 用户注册
> <font color=#FF4500>*POST*/admin/users/register </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
pass|form-data|string|必填
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "Success"
}
```
#### 用户登录
> <font color=#FF4500>*POST*/admin/users/login </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
pass|form-data|string|必填
> 返回示例:
```json
{
"code": 200,
"data": {
"userId":5
"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo1LCJ1c2VyX25hbWUiOiJqb2VmYWxta28iLCJwaG9uZSI6IiIsImV4cCI6MTczMDA1OTQxMSwibmJmIjoxNzMwMDMwNjAxfQ.tqxCyPGQYPpTUJBoqZ47sfCAdxEN2thKRBPHilWHl18",
"updated_at":"2024-10-27 20:03:31",
"msg": "Success"
}
}
```
### 需要鉴权
Header中必须包含 "Authorization": "Bearer {token}"
#### 获取用户信息
> <font color=#FF4500>*POST*/admin/users/info </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
> 返回示例:
```json
{
"code": 200,
"data": {
"id": 1,
"user_name": "joefalmko",
},
"msg": "Success"
}
```
#### 更新用户名
> <font color=#FF4500>*POST*/admin/users/username </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
id|form-data|int|必填
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "Success"
}
```
#### 更新密码
> <font color=#FF4500>*POST*/admin/users/password </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
id|form-data|int|必填
oldpass|form-data|string|必填
newpass|form-data|string|必填
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "Success"
}
```
#### 注销用户
> <font color=#FF4500>*POST*/admin/users/delete </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
user_name|form-data|string|必填
id|form-data|int|必填
pass|form-data|string|必填
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "Success"
}
```
#### 登出用户
> <font color=#FF4500>*POST*/admin/users/logout </font>
参数字段|参数属性|类型|选项
---|---|---|---|---
id|form-data|int|必填
> 返回示例:
```json
{
"code": 200,
"data": "",
"msg": "Success"
}
```
#### token刷新 请将旧token放置在header头参数直接提交更新
> <font color=#FF4500>*post*/admin/users/refreshtoken</font>
参数字段|参数属性|类型|选项|默认值
---|---|---|---|---
Authorization|Headers|string|必填|Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjQ3LCJ1c2VyX25hbWUiOiJnb3NrZWxldG9uMS40IiwicGhvbmUiOiIiLCJleHAiOjE2MDQwNTIxNzMsIm5iZiI6MTYwNDA0ODU2M30.YNhN9_QasHc5XILQiilZvhxpPDnmC_j82y4JfYPnI7A
> 返回示例:
```json
{
"code": 200,
"data": {
"PublicKey": "LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFrZUx2RWNpS3o5UytUQ3E1VnE5MQpTU2RaNm55d3VzbHNPRzAzZnY1VXMxVzJTR0ZDVnpTY3N6aWlLYlIrQk9FR3JsSVRQN29Yb2w3enhQUm55eTczCkZjTkRDOHQwQlhxcGR0U3pkL3V1N1JndXpDYW5BYXVaRXh4RERLUmZEV0MrR0p4TUlBaUV0VHJwT1d6dWp1azgKbDdDMWprTlRhQUpBMmx6ODA2ZWNHZ1NIcFg4MHhCZUpwV3lERnF2N3J3eS9EWjhaekQvRTNXa2ZLREUvRzFFTApPNWRBWUg0QXoxcVQ3SHFEY0hpVVlrNGFDWUswb1pJSC9hSXlKRjhnMDVIbER6NUN2eXNXZVZCTWljT0VRaXQxCnJMaDRaWVhqSVAyVEZmYU5hTlpuVVdhR1BCc05VRThjRU92MlA1d3ZHazFGL29yQ0NyNlFQRytBVE00SU1EME4KR3dJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0tCg=="
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjQ3LCJ1c2VyX25hbWUiOiJnb3NrZWxldG9uMS40IiwicGhvbmUiOiIiLCJleHAiOjE2MDQwNTYxMDcsIm5iZiI6MTYwNDA0ODU2M30.JPE6G-9YE9UTdxHiWuvdVlD-akiIkvp6Ezf9y4_ud9M"
},
"msg": "Success"
}

@ -50,7 +50,7 @@ func (u *Users) Login(c *gin.Context) {
if userToken, err := userTokenFactory.GenerateToken( userModel.Id,userName, variable.ConfigYml.GetInt64("Token.JwtTokenCreatedExpireAt")); err == nil {
if userTokenFactory.RecordLoginToken(userModel.Id,userToken) { // 记录用户登录记录不必要但会将token存入Redis懒得改了
data := gin.H{
// "userId": userModel.Id,
"userId": userModel.Id,
// "user_name": userName,
// "realName": userModel.RealName,
// "phone": phone,

Loading…
Cancel
Save