fix 修改个人信息立即更新登录状态信息
This commit is contained in:
parent
07acd2edfc
commit
c75e87ee11
@ -10,6 +10,7 @@ package system
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
commonApi "github.com/tiger1103/gfast/v3/api/v1/common"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||
)
|
||||
|
||||
@ -45,6 +46,9 @@ type PersonalEditReq struct {
|
||||
}
|
||||
|
||||
type PersonalEditRes struct {
|
||||
commonApi.EmptyRes
|
||||
UserInfo *model.LoginUserRes `json:"userInfo"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type PersonalResetPwdReq struct {
|
||||
|
@ -9,8 +9,12 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
"github.com/tiger1103/gfast/v3/library/libUtils"
|
||||
)
|
||||
|
||||
var Personal = new(personalController)
|
||||
@ -24,7 +28,19 @@ func (c *personalController) GetPersonal(ctx context.Context, req *system.Person
|
||||
}
|
||||
|
||||
func (c *personalController) EditPersonal(ctx context.Context, req *system.PersonalEditReq) (res *system.PersonalEditRes, err error) {
|
||||
res, err = service.Personal().EditPersonal(ctx, req)
|
||||
ip := libUtils.GetClientIp(ctx)
|
||||
userAgent := libUtils.GetUserAgent(ctx)
|
||||
res = new(system.PersonalEditRes)
|
||||
res.UserInfo, err = service.Personal().EditPersonal(ctx, req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
key := gconv.String(res.UserInfo.Id) + "-" + gmd5.MustEncryptString(res.UserInfo.UserName) + gmd5.MustEncryptString(res.UserInfo.UserPassword)
|
||||
if g.Cfg().MustGet(ctx, "gfToken.multiLogin").Bool() {
|
||||
key = gconv.String(res.UserInfo.Id) + "-" + gmd5.MustEncryptString(res.UserInfo.UserName) + gmd5.MustEncryptString(res.UserInfo.UserPassword+ip+userAgent)
|
||||
}
|
||||
res.UserInfo.UserPassword = ""
|
||||
res.Token, err = service.GfToken().GenerateToken(ctx, key, res.UserInfo)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/entity"
|
||||
service "github.com/tiger1103/gfast/v3/internal/app/system/service"
|
||||
@ -54,8 +55,7 @@ func (s *sPersonal) GetPersonalInfo(ctx context.Context, req *system.PersonalInf
|
||||
return
|
||||
}
|
||||
|
||||
func (s *sPersonal) EditPersonal(ctx context.Context, req *system.PersonalEditReq) (res *system.PersonalEditRes, err error) {
|
||||
|
||||
func (s *sPersonal) EditPersonal(ctx context.Context, req *system.PersonalEditReq) (user *model.LoginUserRes, err error) {
|
||||
userId := service.Context().GetUserId(ctx)
|
||||
err = service.SysUser().UserNameOrMobileExists(ctx, "", req.Mobile, int64(userId))
|
||||
if err != nil {
|
||||
@ -73,6 +73,7 @@ func (s *sPersonal) EditPersonal(ctx context.Context, req *system.PersonalEditRe
|
||||
Avatar: req.Avatar,
|
||||
})
|
||||
liberr.ErrIsNil(ctx, err, "修改用户信息失败")
|
||||
user, err = service.SysUser().GetUserById(ctx, userId)
|
||||
liberr.ErrIsNil(ctx, err)
|
||||
})
|
||||
return err
|
||||
|
@ -86,6 +86,16 @@ func (s *sSysUser) GetUserByUsername(ctx context.Context, userName string) (user
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserById 通过用户名获取用户信息
|
||||
func (s *sSysUser) GetUserById(ctx context.Context, id uint64) (user *model.LoginUserRes, err error) {
|
||||
err = g.Try(ctx, func(ctx context.Context) {
|
||||
user = &model.LoginUserRes{}
|
||||
err = dao.SysUser.Ctx(ctx).Fields(user).WherePri(id).Scan(user)
|
||||
liberr.ErrIsNil(ctx, err, "获取用户信息失败")
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// LoginLog 记录登录日志
|
||||
func (s *sSysUser) LoginLog(ctx context.Context, params *model.LoginLogParams) {
|
||||
ua := user_agent.New(params.UserAgent)
|
||||
@ -756,3 +766,47 @@ func (s *sSysUser) HasAccessByDataWhere(ctx context.Context, where g.Map, uid in
|
||||
})
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// AccessRule 判断用户是否有某一菜单规则权限
|
||||
func (s *sSysUser) AccessRule(ctx context.Context, userId uint64, rule string) bool {
|
||||
//获取无需验证权限的用户id
|
||||
tagSuperAdmin := false
|
||||
s.NotCheckAuthAdminIds(ctx).Iterator(func(v interface{}) bool {
|
||||
if gconv.Uint64(v) == userId {
|
||||
tagSuperAdmin = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
if tagSuperAdmin {
|
||||
return true
|
||||
}
|
||||
menuList, err := service.SysAuthRule().GetMenuList(ctx)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
return false
|
||||
}
|
||||
var menu *model.SysAuthRuleInfoRes
|
||||
for _, m := range menuList {
|
||||
ms := gstr.SubStr(m.Name, 0, gstr.Pos(m.Name, "?"))
|
||||
if m.Name == rule || ms == rule {
|
||||
menu = m
|
||||
break
|
||||
}
|
||||
}
|
||||
// 不存在的规则直接false
|
||||
if menu == nil {
|
||||
return false
|
||||
}
|
||||
enforcer, err := commonService.CasbinEnforcer(ctx)
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
return false
|
||||
}
|
||||
hasAccess, err := enforcer.Enforce(fmt.Sprintf("%s%d", service.SysUser().GetCasBinUserPrefix(), userId), gconv.String(menu.Id), "All")
|
||||
if err != nil {
|
||||
g.Log().Error(ctx, err)
|
||||
return false
|
||||
}
|
||||
return hasAccess
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model"
|
||||
|
||||
"github.com/tiger1103/gfast/v3/api/v1/system"
|
||||
)
|
||||
@ -14,7 +15,7 @@ import (
|
||||
type (
|
||||
IPersonal interface {
|
||||
GetPersonalInfo(ctx context.Context, req *system.PersonalInfoReq) (res *system.PersonalInfoRes, err error)
|
||||
EditPersonal(ctx context.Context, req *system.PersonalEditReq) (res *system.PersonalEditRes, err error)
|
||||
EditPersonal(ctx context.Context, req *system.PersonalEditReq) (user *model.LoginUserRes, err error)
|
||||
ResetPwdPersonal(ctx context.Context, req *system.PersonalResetPwdReq) (res *system.PersonalResetPwdRes, err error)
|
||||
}
|
||||
)
|
||||
|
@ -22,6 +22,7 @@ type (
|
||||
NotCheckAuthAdminIds(ctx context.Context) *gset.Set
|
||||
GetAdminUserByUsernamePassword(ctx context.Context, req *system.UserLoginReq) (user *model.LoginUserRes, err error)
|
||||
GetUserByUsername(ctx context.Context, userName string) (user *model.LoginUserRes, err error)
|
||||
GetUserById(ctx context.Context, id uint64) (user *model.LoginUserRes, err error)
|
||||
LoginLog(ctx context.Context, params *model.LoginLogParams)
|
||||
UpdateLoginInfo(ctx context.Context, id uint64, ip string) (err error)
|
||||
GetAdminRules(ctx context.Context, userId uint64) (menuList []*model.UserMenus, permissions []string, err error)
|
||||
@ -46,7 +47,8 @@ type (
|
||||
Delete(ctx context.Context, ids []int) (err error)
|
||||
GetUsers(ctx context.Context, ids []int) (users []*model.SysUserSimpleRes, err error)
|
||||
GetDataWhere(ctx context.Context, userInfo *model.ContextUser, entityData interface{}) (where g.Map, err error)
|
||||
HasAccessByDataWhere(ctx context.Context, where g.Map,uid interface{}) bool
|
||||
HasAccessByDataWhere(ctx context.Context, where g.Map, uid interface{}) bool
|
||||
AccessRule(ctx context.Context, userId uint64, rule string) bool
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user