diff --git a/controller/token.go b/controller/token.go index e44170cc..78fc26e8 100644 --- a/controller/token.go +++ b/controller/token.go @@ -174,7 +174,7 @@ func UpdateToken(c *gin.Context) { if len(token.Name) > 30 { c.JSON(http.StatusOK, gin.H{ "success": false, - "message": "Key名称过长", + "message": "Key名称过长,不能超过30位", }) return } diff --git a/controller/user.go b/controller/user.go index edbfc371..aaf42ae2 100644 --- a/controller/user.go +++ b/controller/user.go @@ -553,6 +553,7 @@ func CreateUser(c *gin.Context) { type ManageRequest struct { Username string `json:"username"` + Action string `json:"action"` NewGroup string `json:"newGroup"` } @@ -591,8 +592,68 @@ func ManageUser(c *gin.Context) { return } - // 更新用户分组 - user.Group = req.NewGroup + 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 + case "changeGroup": + user.Group = req.NewGroup + } if err := user.Update(false); err != nil { c.JSON(http.StatusOK, gin.H{ @@ -617,6 +678,7 @@ func ManageUser(c *gin.Context) { } + func EmailBind(c *gin.Context) { email := c.Query("email") code := c.Query("code") diff --git a/model/redemption.go b/model/redemption.go index c2201b09..ba75f08d 100644 --- a/model/redemption.go +++ b/model/redemption.go @@ -86,7 +86,7 @@ func Redeem(key string, userId int) (quota int, upgradedToVIP bool, err error) { } // 检查是否需要升级为 VIP - if user.Group != "vip" && user.Quota >= 5*500000 { + if user.Group != "vip" && user.Group != "svip" && user.Quota >= 5*500000 { // 升级用户到 VIP err = DB.Model(&User{}).Where("id = ?", userId).Update("group", "vip").Error if err != nil { diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index dc146345..114fbef9 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -466,7 +466,7 @@ const ChannelsTable = () => { manageChannel(channel.id, 'delete', idx); }} > - 删除渠道 {channel.name} + 确认删除 {channel.name} diff --git a/web/src/components/Header.js b/web/src/components/Header.js index d2607583..dd410626 100644 --- a/web/src/components/Header.js +++ b/web/src/components/Header.js @@ -6,6 +6,8 @@ import { Button, Container, Dropdown, Icon, Menu, Segment } from 'semantic-ui-re import { API, getLogo, getSystemName, isAdmin, isMobile, showSuccess } from '../helpers'; import '../index.css'; + + // Header Buttons let headerButtons = [ { @@ -83,6 +85,8 @@ const Header = () => { const [showSidebar, setShowSidebar] = useState(false); const systemName = getSystemName(); const logo = getLogo(); + const [activeItem, setActiveItem] = useState(null); + async function logout() { setShowSidebar(false); @@ -100,6 +104,7 @@ const Header = () => { const renderButtons = (isMobile) => { return headerButtons.map((button) => { if (button.admin && !isAdmin()) return <>>; + const isActive = activeItem === button.name; if (isMobile) { return (