From 825374c334be8956561ea67b2dca78964ab17b13 Mon Sep 17 00:00:00 2001 From: wood Date: Tue, 7 Nov 2023 01:43:09 +0800 Subject: [PATCH] =?UTF-8?q?[x]=20=E5=BD=93=E7=94=A8=E6=88=B7=E5=85=85?= =?UTF-8?q?=E5=80=BC=E8=BE=BE=E5=88=B05=E5=88=80=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=8F=90=E5=8D=87=E4=B8=BAvip=E5=88=86?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E5=85=B7=E4=BD=93=E9=87=91=E9=A2=9D=E5=8F=AF?= =?UTF-8?q?=E5=9C=A8`web\src\pages\TopUp\index.js`=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=9B=20[x]=20=E4=BF=AE=E6=94=B9=E9=A2=9C=E8=89=B2=20[x]=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E9=A1=B5=E9=9D=A2=E6=96=B0=E5=A2=9E=E5=BF=AB?= =?UTF-8?q?=E9=80=9F=E7=AD=9B=E9=80=89=E6=97=A5=E6=9C=9F=E3=80=81=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=B8=A0=E9=81=93ID=E6=9F=A5=E8=AF=A2=E3=80=81?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0=E6=B6=88=E8=80=97=E9=A2=9D?= =?UTF-8?q?=E5=BA=A6=E3=80=81=E5=88=A0=E9=99=A4=E6=97=A5=E5=BF=97=E8=AF=A6?= =?UTF-8?q?=E6=83=85=EF=BC=88=E5=9B=A0=E4=B8=BA=E6=B2=A1=E6=9C=89=E5=A4=AA?= =?UTF-8?q?=E5=A4=A7=E6=84=8F=E4=B9=89=EF=BC=89=EF=BC=9B=20[x]=20=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=BF=AB=E9=80=9F=E8=AE=BE=E7=BD=AE=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=84=EF=BC=8C=E5=9C=A8`web\src\components\UsersTable.js`?= =?UTF-8?q?=E5=A4=84=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3=E5=80=BC=EF=BC=9B?= =?UTF-8?q?=20[x]=20=E4=BB=A4=E7=89=8C=E7=95=8C=E9=9D=A2=EF=BC=8C=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=97=A0=E7=94=A8=E7=9A=84=E5=A4=9A=E7=A7=8D=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E3=80=81=E8=81=8A=E5=A4=A9=E7=AD=89=E6=8C=89=E9=92=AE?= =?UTF-8?q?=EF=BC=9B=20[x]=20=E5=88=A0=E9=99=A4=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E4=BB=A4=E7=89=8C=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++ controller/user.go | 192 ++++++++++++++------- web/src/components/ChannelsTable.js | 50 +++--- web/src/components/Header.js | 29 +++- web/src/components/LoginForm.js | 14 +- web/src/components/LogsTable.js | 115 ++++++++++-- web/src/components/OtherSetting.js | 48 ------ web/src/components/PasswordResetConfirm.js | 2 +- web/src/components/PasswordResetForm.js | 2 +- web/src/components/RedemptionsTable.js | 119 +++++++------ web/src/components/RegisterForm.js | 6 +- web/src/components/TokensTable.js | 56 +++--- web/src/components/UsersTable.js | 67 +++++-- web/src/index.css | 64 ++++++- web/src/pages/Redemption/EditRedemption.js | 2 +- web/src/pages/TopUp/index.js | 50 ++++-- 16 files changed, 559 insertions(+), 271 deletions(-) diff --git a/README.md b/README.md index 41335599..3cc1524a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +## 自定义部分 + +[x] 当用户充值达到5刀时,自动提升为vip分组,具体金额可在`web\src\pages\TopUp\index.js`调整; +[x] 修改颜色 +[x] 日志页面新增快速筛选日期、修复渠道ID查询、自动更新消耗额度、删除日志详情(因为没有太大意义); +[x] 用户管理界面,支持快速设置用户组,在`web\src\components\UsersTable.js`处修改相关值; +[x] 令牌界面,删除无用的多种复制、聊天等按钮; +[x] 删除 系统访问令牌; +[ ] 在个人设置页面显示分组; +[ ] 渠道管理处,已启用渠道和禁用渠道, 启用/禁用 按钮改为不同颜色; + +[x] 等 + +---

中文 | English | 日本語

diff --git a/controller/user.go b/controller/user.go index 8fd10b82..59e50017 100644 --- a/controller/user.go +++ b/controller/user.go @@ -7,7 +7,6 @@ import ( "one-api/common" "one-api/model" "strconv" - "github.com/gin-contrib/sessions" "github.com/gin-gonic/gin" ) @@ -554,10 +553,128 @@ func CreateUser(c *gin.Context) { type ManageRequest struct { Username string `json:"username"` - Action string `json:"action"` + NewGroup string `json:"newGroup"` } // ManageUser Only admin user can do this +// func ManageUser(c *gin.Context) { +// var req ManageRequest +// err := json.NewDecoder(c.Request.Body).Decode(&req) + +// if err != nil { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "无效的参数", +// }) +// return +// } +// user := model.User{ +// Username: req.Username, +// } +// // Fill attributes +// model.DB.Where(&user).First(&user) +// if user.Id == 0 { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "用户不存在", +// }) +// return +// } +// myRole := c.GetInt("role") +// if myRole <= user.Role && myRole != common.RoleRootUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "无权更新同权限等级或更高权限等级的用户信息", +// }) +// return +// } +// switch req.Action { +// case "disable": +// user.Status = common.UserStatusDisabled +// if user.Role == common.RoleRootUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "无法禁用超级管理员用户", +// }) +// return +// } +// case "enable": +// user.Status = common.UserStatusEnabled +// case "delete": +// if user.Role == common.RoleRootUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "无法删除超级管理员用户", +// }) +// return +// } +// if err := user.Delete(); err != nil { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": err.Error(), +// }) +// return +// } +// case "promote": +// if myRole != common.RoleRootUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "普通管理员用户无法提升其他用户为管理员", +// }) +// return +// } +// if user.Role >= common.RoleAdminUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "该用户已经是管理员", +// }) +// return +// } +// user.Role = common.RoleAdminUser +// case "demote": +// if user.Role == common.RoleRootUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "无法降级超级管理员用户", +// }) +// return +// } +// if user.Role == common.RoleCommonUser { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": "该用户已经是普通用户", +// }) +// return +// } +// user.Role = common.RoleCommonUser +// } + +// if err := user.Update(false); err != nil { +// c.JSON(http.StatusOK, gin.H{ +// "success": false, +// "message": err.Error(), +// }) +// return +// } + +// user.Group = req.NewGroup + + +// clearUser := model.User{ +// Group: user.Group, +// Role: user.Role, +// Status: user.Status, +// } +// c.JSON(http.StatusOK, gin.H{ +// "success": true, +// "message": "", +// "data": clearUser, +// }) +// return + + + +// } func ManageUser(c *gin.Context) { var req ManageRequest err := json.NewDecoder(c.Request.Body).Decode(&req) @@ -569,10 +686,11 @@ func ManageUser(c *gin.Context) { }) return } + user := model.User{ Username: req.Username, } - // Fill attributes + model.DB.Where(&user).First(&user) if user.Id == 0 { c.JSON(http.StatusOK, gin.H{ @@ -581,6 +699,7 @@ func ManageUser(c *gin.Context) { }) return } + myRole := c.GetInt("role") if myRole <= user.Role && myRole != common.RoleRootUser { c.JSON(http.StatusOK, gin.H{ @@ -589,66 +708,9 @@ func ManageUser(c *gin.Context) { }) return } - switch req.Action { - case "disable": - user.Status = common.UserStatusDisabled - if user.Role == common.RoleRootUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "无法禁用超级管理员用户", - }) - return - } - case "enable": - user.Status = common.UserStatusEnabled - case "delete": - if user.Role == common.RoleRootUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "无法删除超级管理员用户", - }) - return - } - if err := user.Delete(); err != nil { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": err.Error(), - }) - return - } - case "promote": - if myRole != common.RoleRootUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "普通管理员用户无法提升其他用户为管理员", - }) - return - } - if user.Role >= common.RoleAdminUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "该用户已经是管理员", - }) - return - } - user.Role = common.RoleAdminUser - case "demote": - if user.Role == common.RoleRootUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "无法降级超级管理员用户", - }) - return - } - if user.Role == common.RoleCommonUser { - c.JSON(http.StatusOK, gin.H{ - "success": false, - "message": "该用户已经是普通用户", - }) - return - } - user.Role = common.RoleCommonUser - } + + // 更新用户分组 + user.Group = req.NewGroup if err := user.Update(false); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -657,10 +719,13 @@ func ManageUser(c *gin.Context) { }) return } + clearUser := model.User{ + Group: user.Group, Role: user.Role, Status: user.Status, } + c.JSON(http.StatusOK, gin.H{ "success": true, "message": "", @@ -669,6 +734,7 @@ func ManageUser(c *gin.Context) { return } + func EmailBind(c *gin.Context) { email := c.Query("email") code := c.Query("code") diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index c072f26d..4ba5c901 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -30,21 +30,22 @@ function renderType(type) { function renderBalance(type, balance) { switch (type) { case 1: // OpenAI - return ${balance.toFixed(2)}; + return ${balance.toFixed(2)}; case 4: // CloseAI - return ¥{balance.toFixed(2)}; + return ¥{balance.toFixed(2)}; case 8: // 自定义 - return ${balance.toFixed(2)}; + return ${balance.toFixed(2)}; case 5: // OpenAI-SB - return ¥{(balance / 10000).toFixed(2)}; + return ¥{(balance / 10000).toFixed(2)}; case 10: // AI Proxy - return {renderNumber(balance)}; + return {renderNumber(balance)}; case 12: // API2GPT - return ¥{balance.toFixed(2)}; + return ¥{balance.toFixed(2)}; case 13: // AIGC2D - return {renderNumber(balance)}; + return {renderNumber(balance)}; default: - return 不支持; + return 不支持; + } } @@ -150,11 +151,11 @@ const ChannelsTable = () => { const renderStatus = (status) => { switch (status) { case 1: - return ; + return ; case 2: return ( + trigger={} content='本渠道被手动禁用' @@ -164,7 +165,7 @@ const ChannelsTable = () => { case 3: return ( + trigger={} content='本渠道被程序自动禁用' @@ -173,10 +174,11 @@ const ChannelsTable = () => { ); default: return ( -