introspect 返回一个表示用户是否设置过密码的字段
This commit is contained in:
@@ -307,6 +307,7 @@ func Revoke(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
type IntrospectResp struct {
|
type IntrospectResp struct {
|
||||||
m.User
|
m.User
|
||||||
|
HasPassword bool `json:"has_password"` // 是否设置了密码
|
||||||
}
|
}
|
||||||
|
|
||||||
func Introspect(c *fiber.Ctx) error {
|
func Introspect(c *fiber.Ctx) error {
|
||||||
@@ -319,12 +320,19 @@ func Introspect(c *fiber.Ctx) error {
|
|||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
profile, err := q.User.
|
profile, err := q.User.
|
||||||
Where(q.User.ID.Eq(authCtx.Payload.Id)).
|
Where(q.User.ID.Eq(authCtx.Payload.Id)).
|
||||||
Omit(q.User.Password, q.User.DeletedAt).
|
Omit(q.User.DeletedAt).
|
||||||
Take()
|
Take()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查用户是否设置了密码
|
||||||
|
hasPassword := false
|
||||||
|
if profile.Password != nil && *profile.Password != "" {
|
||||||
|
hasPassword = true
|
||||||
|
profile.Password = nil // 不返回密码
|
||||||
|
}
|
||||||
|
|
||||||
// 掩码敏感信息
|
// 掩码敏感信息
|
||||||
if profile.Phone != "" {
|
if profile.Phone != "" {
|
||||||
profile.Phone = maskPhone(profile.Phone)
|
profile.Phone = maskPhone(profile.Phone)
|
||||||
@@ -332,7 +340,7 @@ func Introspect(c *fiber.Ctx) error {
|
|||||||
if profile.IDNo != nil && *profile.IDNo != "" {
|
if profile.IDNo != nil && *profile.IDNo != "" {
|
||||||
profile.IDNo = u.P(maskIdNo(*profile.IDNo))
|
profile.IDNo = u.P(maskIdNo(*profile.IDNo))
|
||||||
}
|
}
|
||||||
return c.JSON(IntrospectResp{*profile})
|
return c.JSON(IntrospectResp{*profile, hasPassword})
|
||||||
}
|
}
|
||||||
|
|
||||||
func maskPhone(phone string) string {
|
func maskPhone(phone string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user