81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"context"
|
|
|
|
"blazing/common/data/share"
|
|
"blazing/cool"
|
|
|
|
"blazing/modules/base/service"
|
|
|
|
blazing_service "blazing/modules/blazing/service"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
type BaseSysUserController struct {
|
|
*cool.Controller
|
|
}
|
|
|
|
func init() {
|
|
var base_sys_user_controller = &BaseSysUserController{
|
|
&cool.Controller{
|
|
Prefix: "/admin/base/sys/user",
|
|
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page", "Move"},
|
|
Service: service.NewBaseSysUserService(),
|
|
},
|
|
}
|
|
// 注册路由
|
|
cool.RegisterController(base_sys_user_controller)
|
|
}
|
|
|
|
type UserMoveReq struct {
|
|
g.Meta `path:"/move" method:"GET"`
|
|
Authorization string `json:"Authorization" in:"header"`
|
|
}
|
|
type SessionReq struct {
|
|
g.Meta `path:"/getSession" method:"GET"`
|
|
Authorization string `json:"Authorization" in:"header"`
|
|
}
|
|
|
|
func (c *BaseSysUserController) Move(ctx context.Context, req *UserMoveReq) (res *cool.BaseRes, err error) {
|
|
err = service.NewBaseSysUserService().Move(ctx)
|
|
res = cool.Ok(nil)
|
|
return
|
|
}
|
|
|
|
func (c *BaseSysUserController) GetSession(ctx context.Context, req *SessionReq) (res *SessionRes, err error) {
|
|
|
|
t := cool.GetAdmin(ctx)
|
|
if t == nil || t.UserId == 0 {
|
|
|
|
return &SessionRes{}, nil
|
|
}
|
|
retsid, sid, err := blazing_service.NewLoginServiceService().GetSessionId(t.UserId)
|
|
if err != nil {
|
|
return &SessionRes{}, nil
|
|
|
|
}
|
|
res = &SessionRes{}
|
|
|
|
t1 := service.NewBaseSysUserService().GetPerson(t.UserId)
|
|
|
|
res.Session = retsid
|
|
|
|
if !blazing_service.NewUserService(uint32(t1.ID)).IsReg() {
|
|
res.UserID = int(t1.ID)
|
|
|
|
}
|
|
|
|
if err := share.ShareManager.SaveSession(sid, uint32(t.UserId)); err != nil {
|
|
return &SessionRes{}, nil
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type SessionRes struct {
|
|
UserID int `json:"userid"`
|
|
Session string `json:"session"`
|
|
}
|