migrate controllers
Some checks failed
build quyun / Build (push) Failing after 1m30s

This commit is contained in:
2025-12-19 23:33:02 +08:00
parent 557a641f41
commit 49072ddd79
37 changed files with 1944 additions and 69 deletions

View File

@@ -0,0 +1,40 @@
package admin
import (
"quyun/v2/providers/jwt"
"github.com/gofiber/fiber/v3"
)
// @provider
type auth struct {
jwt *jwt.JWT
}
type AuthBody struct {
Username string `json:"username" validate:"required"`
Password string `json:"password" validate:"required"`
}
type TokenResponse struct {
Token string `json:"token"`
}
// Login
//
// @Router /admin/auth [post]
// @Bind body body
func (ctl *auth) Login(ctx fiber.Ctx, body *AuthBody) (*TokenResponse, error) {
if body.Username == "pl.yang" && body.Password == "Xixi@0202" {
claim := ctl.jwt.CreateClaims(jwt.BaseClaims{
UserID: -20140202,
})
token, err := ctl.jwt.CreateToken(claim)
if err != nil {
return nil, err
}
return &TokenResponse{Token: token}, nil
}
return nil, fiber.ErrUnauthorized
}