zelda/backend/apiserver/auth/jwt/handler.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-11-19 16:57:27 +08:00
package jwt
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/ycyxuehan/zelda/apiserver/auth/api"
)
//登录
func (m *manager) HandlerLogin(identifyFunc api.IdentifyFunc) gin.HandlerFunc {
return func(c *gin.Context) {
authRequest := api.AuthentitionRequest{}
err := c.Bind(&authRequest)
if err != nil {
c.JSON(http.StatusOK, &api.AuthentitionResponse{Error: err})
return
}
resp := m.Login(identifyFunc, &authRequest)
c.JSON(http.StatusOK, resp)
}
}
//登出
func (m *manager) HandlerLogout() gin.HandlerFunc {
return func(c *gin.Context) {
authRequest := api.AuthentitionRequest{}
err := c.Bind(&authRequest)
if err != nil {
c.JSON(http.StatusOK, &api.AuthentitionResponse{Error: err})
return
}
resp := m.Logout(&authRequest)
c.JSON(http.StatusOK, resp)
}
}
//刷新token
func (m *manager) HandlerRefreshToken() gin.HandlerFunc {
return func(c *gin.Context) {
authRequest := api.AuthentitionRequest{}
err := c.Bind(&authRequest)
if err != nil {
c.JSON(http.StatusOK, &api.AuthentitionResponse{Error: err})
return
}
resp := m.Refresh(&authRequest)
c.JSON(http.StatusOK, resp)
}
}