更新密码找回uniapp

This commit is contained in:
hero920103 committed 2026-11-16 17:22:50 +08:00
1 parent 7f9a66da0f
commit 3fdda89833
1304 files changed
+3503 -26132

No files matched your search

-34
View File
@@ -21,10 +21,6 @@ import (
beego "github.com/beego/beego/v2/server/web"
)
// syncTenantUserToAuth 把租户用户同步到统一认证中心(双写)。
// updatePassword:身份已存在时是否允许同步密码(仅改密场景传 true;
// 新增/编辑/绑定场景传 false,避免把身份层密码覆盖回旧值)。
// 同步失败只记日志,不影响平台端主流程(认证中心为新增能力)。
func syncTenantUserToAuth(row *models.SystemTenantUser, updatePassword bool) {
if row == nil {
return
@@ -57,7 +53,6 @@ func syncTenantUserToAuth(row *models.SystemTenantUser, updatePassword bool) {
}
}
// removeTenantUserFromAuth 删除认证中心中的企业绑定(保留身份)
func removeTenantUserFromAuth(row *models.SystemTenantUser) {
if row == nil {
return
@@ -77,7 +72,6 @@ func removeTenantUserFromAuth(row *models.SystemTenantUser) {
}
}
// PlatformTenantUserController 平台租户用户绑定管理
type PlatformTenantUserController struct {
beego.Controller
}
@@ -96,9 +90,6 @@ type tenantUserPayload struct {
Remark *string `json:"remark"`
}
// GetTenantOrganizations GET /platform/tenantUser/orgs?tid=1
// 平台端代租户加用户时,部门下拉必须取「该租户」的组织架构;
// 平台自己的组织与租户无关,直接查会一直是空列表。
func (c *PlatformTenantUserController) GetTenantOrganizations() {
if _, err := requirePlatform(&c.Controller); err != nil {
code := identity.Status(err)
@@ -135,8 +126,6 @@ func (c *PlatformTenantUserController) GetTenantOrganizations() {
_ = c.ServeJSON()
}
// GetTenantUserList 获取绑定列表(支持按 tid / uid 过滤,keyword 对姓名/手机/邮箱/账号模糊匹配)
// GET /platform/tenantUser/list?tid=1&uid=2&keyword=xxx
func (c *PlatformTenantUserController) GetTenantUserList() {
tid, _ := c.GetUint64("tid")
uid, _ := c.GetUint64("uid")
@@ -196,8 +185,6 @@ func (c *PlatformTenantUserController) GetTenantUserList() {
_ = c.ServeJSON()
}
// GetTenantUsersByTid 兼容旧路由,根据租户 ID 获取租户用户列表
// GET /platform/getTenantUsers/:tid
func (c *PlatformTenantUserController) GetTenantUsersByTid() {
tidStr := c.Ctx.Input.Param(":tid")
tid, _ := strconv.ParseUint(tidStr, 10, 64)
@@ -224,8 +211,6 @@ func (c *PlatformTenantUserController) GetTenantUsersByTid() {
_ = c.ServeJSON()
}
// GetTenantUserDetail 获取绑定详情
// GET /platform/tenantUser/detail/:id
func (c *PlatformTenantUserController) GetTenantUserDetail() {
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
@@ -246,8 +231,6 @@ func (c *PlatformTenantUserController) GetTenantUserDetail() {
_ = c.ServeJSON()
}
// CreateTenantUser 创建租户用户绑定(写入 yz_system_tenant_user;uid 为空时自动生成)
// POST /platform/tenantUser/create
func (c *PlatformTenantUserController) CreateTenantUser() {
p, ok := c.parsePayload()
if !ok {
@@ -292,7 +275,6 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
p.Uid = uid
}
// 用户数配额校验:租户用户数达到上限时不允许新增(增购用户数后放开)
if check, err := services.CheckTenantUserQuota(p.Tid, p.Uid); err != nil {
c.Data["json"] = map[string]interface{}{"code": 500, "msg": "用户数校验失败: " + err.Error()}
_ = c.ServeJSON()
@@ -328,7 +310,6 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
}
if isDefault == 1 {
_ = services.SetDefaultTenant(p.Uid, p.Tid)
// 租户的第一个账号即租户管理员:自动绑定全局「租户管理员」角色(拥有 backend 全权限)。
if adminRoleID, err := models.GetTenantAdminRole(); err == nil && adminRoleID > 0 {
_, _ = models.Orm.QueryTable(new(models.SystemTenantUser)).
Filter("id", id).
@@ -336,8 +317,6 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
}
}
// 双写:同步到统一认证中心(读回最新记录,确保 group_id/org_id 已落库);
// 新建身份时密码已随身份创建写入;已存在身份不覆盖密码
var created models.SystemTenantUser
if e := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", id).One(&created); e == nil {
syncTenantUserToAuth(&created, false)
@@ -347,8 +326,6 @@ func (c *PlatformTenantUserController) CreateTenantUser() {
_ = c.ServeJSON()
}
// EditTenantUser 编辑绑定
// POST /platform/tenantUser/edit/:id
func (c *PlatformTenantUserController) EditTenantUser() {
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
@@ -420,7 +397,6 @@ func (c *PlatformTenantUserController) EditTenantUser() {
_ = services.SetDefaultTenant(p.Uid, p.Tid)
}
// 双写:同步到统一认证中心(仅本次显式修改了密码时才同步密码字段)
var updated models.SystemTenantUser
if err := models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", id).One(&updated); err == nil {
syncTenantUserToAuth(&updated, p.Password != nil)
@@ -430,8 +406,6 @@ func (c *PlatformTenantUserController) EditTenantUser() {
_ = c.ServeJSON()
}
// DeleteTenantUser 删除绑定
// DELETE /platform/tenantUser/delete/:id
func (c *PlatformTenantUserController) DeleteTenantUser() {
id, err := strconv.ParseUint(c.Ctx.Input.Param(":id"), 10, 64)
if err != nil || id == 0 {
@@ -440,7 +414,6 @@ func (c *PlatformTenantUserController) DeleteTenantUser() {
return
}
// 删除前先读出记录,供认证中心侧定位(删除后就读不到了)
var row models.SystemTenantUser
_ = models.Orm.QueryTable(new(models.SystemTenantUser)).Filter("id", id).One(&row)
@@ -450,7 +423,6 @@ func (c *PlatformTenantUserController) DeleteTenantUser() {
return
}
// 双写:删除认证中心中的企业绑定
removeTenantUserFromAuth(&row)
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success"}
@@ -468,11 +440,6 @@ func (c *PlatformTenantUserController) parsePayload() (tenantUserPayload, bool)
return p, true
}
// ensureTenantUIDForNewUser 新增租户用户时确定 uid。
//
// 统一走 uid:优先取认证中心 identity_id —— 业务表(文件/客户/合同/日程…)
// 已在 uid 全量迁移中统一成 identity_id,老表 uid 与它一致,业务侧就无需任何换算。
// 认证中心不可用时退回随机 uid(generateTenantUID),保证新增流程不中断。
func ensureTenantUIDForNewUser(tid uint64, account, name, phone, email, passwordHash string) (uint64, error) {
if tid == 0 {
return 0, errors.New("tid 不能为空")
@@ -495,7 +462,6 @@ func ensureTenantUIDForNewUser(tid uint64, account, name, phone, email, password
return generateTenantUID(tid)
}
// strOrEmpty 取指针字符串的值,nil 时返回空串
func strOrEmpty(p *string) string {
if p == nil {
return ""