feat: add admin login

This commit is contained in:
yanghao05
2025-04-16 20:16:41 +08:00
parent e95fc65f5f
commit 4a9836db68
7 changed files with 88 additions and 14 deletions

View File

@@ -0,0 +1,35 @@
package admin
import (
"quyun/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"`
}
// Login
// @Router /v1/admin/auth [post]
// @Bind body body
func (ctl *auth) Login(ctx fiber.Ctx, body *AuthBody) (string, error) {
if body.Username == "admin" && body.Password == "xixi@0202" {
claim := ctl.jwt.CreateClaims(jwt.BaseClaims{
UserID: 1,
})
token, err := ctl.jwt.CreateToken(claim)
if err != nil {
return "", err
}
return token, nil
}
return "", fiber.ErrUnauthorized
}