更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -12,9 +12,6 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendRoleController 租户端(backend)角色管理(yz_system_admin_role, cid=2)
|
||||
// 角色按租户隔离:所有读写均以当前登录租户(JWT 中的 tenant_id)为边界,
|
||||
// 租户仅能查看/管理自己名下的角色,无法越权访问其他租户数据。
|
||||
type BackendRoleController struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -25,7 +22,6 @@ type backendRolePayload struct {
|
||||
Rights interface{} `json:"rights"`
|
||||
}
|
||||
|
||||
// parseSubmittedIDs 将前端提交的 rights 解析为菜单 ID 列表(兼容 JSON 数组 / 逗号分隔字符串)。
|
||||
func parseSubmittedIDs(v interface{}) []uint64 {
|
||||
ids := make([]uint64, 0)
|
||||
switch t := v.(type) {
|
||||
@@ -61,7 +57,6 @@ func parseSubmittedIDs(v interface{}) []uint64 {
|
||||
return ids
|
||||
}
|
||||
|
||||
// loadAssignableTenantMenuIDs 返回租户端可分配菜单的 ID 集合:cid=2 且已启用且已显示。
|
||||
func loadAssignableTenantMenuIDs() map[uint64]bool {
|
||||
ids := make(map[uint64]bool)
|
||||
var menus []models.SystemMenu
|
||||
@@ -76,9 +71,6 @@ func loadAssignableTenantMenuIDs() map[uint64]bool {
|
||||
return ids
|
||||
}
|
||||
|
||||
// sanitizeTenantRights 在服务端收敛租户角色权限:
|
||||
// 仅保留租户端(cid=2)已启用且已显示的菜单 ID,剔除平台菜单、停用菜单、隐藏菜单。
|
||||
// rights 为 nil 或空串表示全权限(与 filterMenusByRights 保持一致)。
|
||||
func sanitizeTenantRights(v interface{}) *string {
|
||||
if v == nil {
|
||||
return nil
|
||||
@@ -111,15 +103,10 @@ func sanitizeTenantRights(v interface{}) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
// tenantRoleReadOnly 判定角色对租户端是否只读。
|
||||
// is_locked 是平台下发的显式开关;tenant_id==0 的全局角色不属于任何租户,天然只读。
|
||||
// 两者取并集,避免平台建全局角色时漏设 is_locked 就把写权限漏给租户。
|
||||
func tenantRoleReadOnly(role models.AdminRole) bool {
|
||||
return role.IsLocked == 1 || role.TenantID == 0
|
||||
}
|
||||
|
||||
// currentTenantID 从 Bearer Token 解析当前登录租户 ID。
|
||||
// 返回 (tid, true) 表示成功;失败时已写入 401/403 响应并返回 (0, false)。
|
||||
func (c *BackendRoleController) currentTenantID() (uint64, bool) {
|
||||
claims, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend, identity.EndApp)
|
||||
if err != nil {
|
||||
@@ -136,10 +123,6 @@ func (c *BackendRoleController) currentTenantID() (uint64, bool) {
|
||||
return uint64(claims.TenantId), true
|
||||
}
|
||||
|
||||
// GetAllRoles 获取当前租户可见的角色列表
|
||||
// GET /backend/allRoles
|
||||
// 返回「全局角色(cid=2, tenant_id=0,所有租户共用)」+「本租户自建角色」;
|
||||
// 全局角色由平台端统一维护,租户端只读。
|
||||
func (c *BackendRoleController) GetAllRoles() {
|
||||
tid, ok := c.currentTenantID()
|
||||
if !ok {
|
||||
@@ -160,8 +143,6 @@ func (c *BackendRoleController) GetAllRoles() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// GetRoleByID 获取当前租户的角色详情
|
||||
// GET /backend/roles/:id
|
||||
func (c *BackendRoleController) GetRoleByID() {
|
||||
tid, ok := c.currentTenantID()
|
||||
if !ok {
|
||||
@@ -188,8 +169,6 @@ func (c *BackendRoleController) GetRoleByID() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// CreateRole 创建当前租户的角色
|
||||
// POST /backend/roles
|
||||
func (c *BackendRoleController) CreateRole() {
|
||||
tid, ok := c.currentTenantID()
|
||||
if !ok {
|
||||
@@ -208,7 +187,6 @@ func (c *BackendRoleController) CreateRole() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
// 不能与本租户可见的角色重名(含平台默认的全局角色),避免混淆
|
||||
dup, derr := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("cid", 2).
|
||||
Filter("tenant_id__in", []uint64{0, tid}).
|
||||
@@ -230,7 +208,6 @@ func (c *BackendRoleController) CreateRole() {
|
||||
status = *p.Status
|
||||
}
|
||||
rights := sanitizeTenantRights(p.Rights)
|
||||
// 租户端创建的角色一律标记为“自定义角色”,与系统/平台预置角色区分,并按租户隔离
|
||||
role := &models.AdminRole{
|
||||
TenantID: tid,
|
||||
Cid: 2,
|
||||
@@ -249,8 +226,6 @@ func (c *BackendRoleController) CreateRole() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// UpdateRole 更新当前租户的角色
|
||||
// PUT /backend/roles/:id
|
||||
func (c *BackendRoleController) UpdateRole() {
|
||||
tid, ok := c.currentTenantID()
|
||||
if !ok {
|
||||
@@ -288,7 +263,6 @@ func (c *BackendRoleController) UpdateRole() {
|
||||
return
|
||||
}
|
||||
|
||||
// 平台下发或全局共享的角色由平台端统一维护,租户端只读
|
||||
var target models.AdminRole
|
||||
if e := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("id", id).
|
||||
@@ -299,7 +273,6 @@ func (c *BackendRoleController) UpdateRole() {
|
||||
return
|
||||
}
|
||||
|
||||
// 改名时不能与可见角色重名(含平台默认的全局角色,排除自身)
|
||||
if newName, ok := update["name"]; ok {
|
||||
dup, derr := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("cid", 2).
|
||||
@@ -319,9 +292,6 @@ func (c *BackendRoleController) UpdateRole() {
|
||||
}
|
||||
}
|
||||
|
||||
// 仅允许更新本租户名下的角色,防止越权改到其他租户。
|
||||
// 先查存在性再更新:MySQL 的 affected rows 只算「真正变化」的行,
|
||||
// 提交与库里完全一致的值会返回 0,直接用它判 404 会把「保存成功但没改动」误报成「角色不存在」。
|
||||
exist, err := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("id", id).
|
||||
Filter("cid", 2).
|
||||
@@ -351,8 +321,6 @@ func (c *BackendRoleController) UpdateRole() {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
// DeleteRole 删除当前租户的角色
|
||||
// DELETE /backend/roles/:id
|
||||
func (c *BackendRoleController) DeleteRole() {
|
||||
tid, ok := c.currentTenantID()
|
||||
if !ok {
|
||||
@@ -365,7 +333,6 @@ func (c *BackendRoleController) DeleteRole() {
|
||||
_ = c.ServeJSON()
|
||||
return
|
||||
}
|
||||
// 平台下发或全局共享的角色由平台端统一维护,租户端不能删除
|
||||
var target models.AdminRole
|
||||
if e := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("id", id).
|
||||
@@ -376,7 +343,6 @@ func (c *BackendRoleController) DeleteRole() {
|
||||
return
|
||||
}
|
||||
|
||||
// 仅允许删除本租户名下的角色
|
||||
cnt, err := models.Orm.QueryTable(new(models.AdminRole)).
|
||||
Filter("id", id).
|
||||
Filter("cid", 2).
|
||||
|
||||
Reference in new issue
Block a user