init from gitlab

This commit is contained in:
texm
2023-04-25 14:33:14 +08:00
parent 6a85a41ff0
commit c8202a5c82
281 changed files with 19861 additions and 1 deletions

View File

@@ -0,0 +1,47 @@
package auth
import (
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
"gitlab.com/texm/shokku/internal/env"
"gitlab.com/texm/shokku/internal/server/auth"
"net/http"
)
func HandleLogout(e *env.Env, c echo.Context) error {
e.Auth.ClearTokenCookies(c)
return c.NoContent(http.StatusOK)
}
func HandleRefreshAuth(e *env.Env, c echo.Context) error {
user, err := e.Auth.GetUserFromContext(c)
if err != nil {
log.Error().Msg("failed to parse user from context")
return echo.ErrInternalServerError
}
claims := auth.UserClaims{
Name: user.Name,
}
token, err := e.Auth.NewToken(claims)
if err != nil {
log.Error().Err(err).Msg("failed to create jwt")
return echo.ErrInternalServerError
}
e.Auth.SetTokenCookies(c, token)
return c.NoContent(http.StatusOK)
}
func HandleGetDetails(e *env.Env, c echo.Context) error {
user, err := e.Auth.GetUserFromContext(c)
if err != nil {
log.Error().Msg("failed to parse user from context")
return echo.ErrInternalServerError
}
return c.JSON(http.StatusOK, echo.Map{
"username": user.Name,
})
}