This commit is contained in:
hero920103 committed 2026-11-11 17:30:06 +08:00
1 parent 8fc52c574f
commit fb04d66e61
7 files changed
+284 -9

No files matched your search

+61
View File
@@ -130,6 +130,67 @@ func (c *AppAuthController) GetCurrentUser() {
})
}
// UpdateCurrentUserProfile 修改当前用户资料(姓名 / 邮箱)。
// 手机号由微信验证并作为登录账号,不开放修改;同步统一身份与当前企业绑定表,
// 避免下次登录或切换企业后又读到旧的姓名。
func (c *AppAuthController) UpdateCurrentUserProfile() {
claims, err := identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndBackend, identity.EndApp)
if err != nil {
code := identity.Status(err)
c.serveJSON(map[string]interface{}{"code": code, "msg": err.Error()})
return
}
var req struct {
Name string `json:"name"`
Email string `json:"email"`
}
body := c.Ctx.Input.RequestBody
if len(body) == 0 {
body, _ = io.ReadAll(c.Ctx.Request.Body)
}
if err := json.Unmarshal(body, &req); err != nil {
c.serveJSON(map[string]interface{}{"code": 400, "msg": "参数错误"})
return
}
name := strings.TrimSpace(req.Name)
email := strings.TrimSpace(req.Email)
if name == "" {
c.serveJSON(map[string]interface{}{"code": 400, "msg": "请填写姓名"})
return
}
if len([]rune(name)) > 30 {
c.serveJSON(map[string]interface{}{"code": 400, "msg": "姓名不能超过 30 个字符"})
return
}
if email != "" && (!strings.Contains(email, "@") || len(email) > 128) {
c.serveJSON(map[string]interface{}{"code": 400, "msg": "邮箱格式不正确"})
return
}
uid := services.ResolveTenantUID(uint64(claims.TenantId), uint64(claims.UserID))
num, err := models.Orm.QueryTable(new(models.SystemTenantUser)).
Filter("uid", uid).
Filter("tid", claims.TenantId).
Update(map[string]interface{}{"name": name, "email": email})
if err != nil || num == 0 {
c.serveJSON(map[string]interface{}{"code": 400, "msg": "未找到当前企业下的用户资料"})
return
}
_, _ = models.Orm.QueryTable(new(models.AuthIdentity)).
Filter("id", uint64(claims.UserID)).
Update(map[string]interface{}{"nickname": name, "email": email})
_, _ = models.Orm.QueryTable(new(models.AuthTenantUser)).
Filter("identity_id", uint64(claims.UserID)).
Filter("tid", claims.TenantId).
Update(map[string]interface{}{"name": name, "email": email})
c.serveJSON(map[string]interface{}{
"code": 200,
"msg": "资料已更新",
"data": map[string]interface{}{"name": name, "email": email},
})
}
// SendLoginCode 发送App端登录验证码
func (c *AppAuthController) SendLoginCode() {
var req struct {