Selaa lähdekoodia

服务端退出登录

yxh 3 vuotta sitten
vanhempi
säilyke
6c30e4084c

+ 8 - 0
api/v1/system/sys_login.go

@@ -27,3 +27,11 @@ type UserLoginRes struct {
 	MenuList    []*model.UserMenus  `json:"menuList"`
 	Permissions []string            `json:"permissions"`
 }
+
+type UserLoginOutReq struct {
+	g.Meta        `path:"/loginOut" tags:"登录" method:"delete" summary:"退出登录"`
+	Authorization string `p:"Authorization" in:"header" dc:"Bearer {{token}}"`
+}
+
+type UserLoginOutRes struct {
+}

+ 1 - 1
go.mod

@@ -12,7 +12,7 @@ require (
 	github.com/mssola/user_agent v0.5.3
 	github.com/shirou/gopsutil v3.21.11+incompatible
 	github.com/tiger1103/gfast-cache v0.0.7
-	github.com/tiger1103/gfast-token v0.0.9
+	github.com/tiger1103/gfast-token v0.1.0
 	github.com/tklauser/go-sysconf v0.3.10 // indirect
 	github.com/yusufpapurcu/wmi v1.2.2 // indirect
 	go.opentelemetry.io/otel/sdk v1.6.1 // indirect

+ 2 - 2
go.sum

@@ -116,8 +116,8 @@ github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMT
 github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
 github.com/tiger1103/gfast-cache v0.0.7 h1:YRuSFxFdvNlIsHAndS7XjYRLd4tmXGWhvHt9rK0LVT0=
 github.com/tiger1103/gfast-cache v0.0.7/go.mod h1:s6cRWyr87wz6IJNGKRV6Ahq9hcuVz8h2PAtGrO66JO8=
-github.com/tiger1103/gfast-token v0.0.9 h1:+cKNu4zAMZpqaeILy3QIjuEO0HQMXtMSqVGPmhKAP90=
-github.com/tiger1103/gfast-token v0.0.9/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY=
+github.com/tiger1103/gfast-token v0.1.0 h1:C41f0lZ5nLizHtgfRNvE3nf7hVQ+IO0dCCgg3a9/Oa4=
+github.com/tiger1103/gfast-token v0.1.0/go.mod h1:RnVRqmWD3h4qfTU1vJNXNhQjh2L5ht1vxLnjwShwGuY=
 github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw=
 github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk=
 github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o=

+ 2 - 0
internal/app/common/service/token.go

@@ -20,6 +20,8 @@ type IGfToken interface {
 	Middleware(group *ghttp.RouterGroup) error
 	ParseToken(r *ghttp.Request) (*gftoken.CustomClaims, error)
 	IsLogin(r *ghttp.Request) (b bool, failed *gftoken.AuthFailed)
+	GetRequestToken(r *ghttp.Request) (token string)
+	RemoveToken(ctx context.Context, token string) (err error)
 }
 
 type gfTokenImpl struct {

+ 6 - 0
internal/app/system/controller/sys_login.go

@@ -94,3 +94,9 @@ func (c *loginController) Login(ctx context.Context, req *system.UserLoginReq) (
 	}
 	return
 }
+
+// LoginOut 退出登录
+func (c *loginController) LoginOut(ctx context.Context, req *system.UserLoginOutReq) (res *system.UserLoginOutRes, err error) {
+	err = service.GfToken().RemoveToken(ctx, service.GfToken().GetRequestToken(g.RequestFromCtx(ctx)))
+	return
+}