更新
This commit is contained in:
1 parent
8fc52c574f
commit
fb04d66e61
7 files changed
+284
-9
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -54,6 +54,8 @@ func Register() {
|
||||
|
||||
// 当前用户信息
|
||||
beego.Router("/api/currentUser", &controllers.AppAuthController{}, "get:GetCurrentUser")
|
||||
// 修改当前用户资料(姓名 / 邮箱;手机号由微信验证,不开放修改)
|
||||
beego.Router("/api/currentUser/profile", &controllers.AppAuthController{}, "post:UpdateCurrentUserProfile")
|
||||
|
||||
// 极验与登录验证配置
|
||||
beego.Router("/api/login/getGeetest3Infos", &controllers.AppAuthController{}, "get:GetGeetest3Infos")
|
||||
|
||||
Reference in new issue
Block a user