feat: 重构认证控制器,统一类型命名为auth
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// @provider
|
// @provider
|
||||||
type authController struct {
|
type auth struct {
|
||||||
app *app.Config
|
app *app.Config
|
||||||
jwt *jwt.JWT
|
jwt *jwt.JWT
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ type authController struct {
|
|||||||
//
|
//
|
||||||
// @Router /super/v1/auth/login [post]
|
// @Router /super/v1/auth/login [post]
|
||||||
// @Bind form body
|
// @Bind form body
|
||||||
func (ctl *authController) login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
func (ctl *auth) login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
||||||
m, err := services.User.FindByUsername(ctx, form.Username)
|
m, err := services.User.FindByUsername(ctx, form.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errorx.Wrap(err).WithMsg("用户名或密码错误")
|
return nil, errorx.Wrap(err).WithMsg("用户名或密码错误")
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ func Provide(opts ...opt.Option) error {
|
|||||||
if err := container.Container.Provide(func(
|
if err := container.Container.Provide(func(
|
||||||
app *app.Config,
|
app *app.Config,
|
||||||
jwt *jwt.JWT,
|
jwt *jwt.JWT,
|
||||||
) (*authController, error) {
|
) (*auth, error) {
|
||||||
obj := &authController{
|
obj := &auth{
|
||||||
app: app,
|
app: app,
|
||||||
jwt: jwt,
|
jwt: jwt,
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,14 @@ func Provide(opts ...opt.Option) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := container.Container.Provide(func(
|
if err := container.Container.Provide(func(
|
||||||
authController *authController,
|
auth *auth,
|
||||||
tenant *tenant,
|
tenant *tenant,
|
||||||
user *user,
|
user *user,
|
||||||
) (contracts.HttpRoute, error) {
|
) (contracts.HttpRoute, error) {
|
||||||
obj := &Routes{
|
obj := &Routes{
|
||||||
authController: authController,
|
auth: auth,
|
||||||
tenant: tenant,
|
tenant: tenant,
|
||||||
user: user,
|
user: user,
|
||||||
}
|
}
|
||||||
if err := obj.Prepare(); err != nil {
|
if err := obj.Prepare(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ import (
|
|||||||
type Routes struct {
|
type Routes struct {
|
||||||
log *log.Entry `inject:"false"`
|
log *log.Entry `inject:"false"`
|
||||||
// Controller instances
|
// Controller instances
|
||||||
authController *authController
|
auth *auth
|
||||||
tenant *tenant
|
tenant *tenant
|
||||||
user *user
|
user *user
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare initializes the routes provider with logging configuration.
|
// Prepare initializes the routes provider with logging configuration.
|
||||||
@@ -40,10 +40,10 @@ func (r *Routes) Name() string {
|
|||||||
// Register registers all HTTP routes with the provided fiber router.
|
// Register registers all HTTP routes with the provided fiber router.
|
||||||
// Each route is registered with its corresponding controller action and parameter bindings.
|
// Each route is registered with its corresponding controller action and parameter bindings.
|
||||||
func (r *Routes) Register(router fiber.Router) {
|
func (r *Routes) Register(router fiber.Router) {
|
||||||
// Register routes for controller: authController
|
// Register routes for controller: auth
|
||||||
r.log.Debugf("Registering route: Post /super/v1/auth/login -> authController.login")
|
r.log.Debugf("Registering route: Post /super/v1/auth/login -> auth.login")
|
||||||
router.Post("/super/v1/auth/login", DataFunc1(
|
router.Post("/super/v1/auth/login", DataFunc1(
|
||||||
r.authController.login,
|
r.auth.login,
|
||||||
Body[dto.LoginForm]("form"),
|
Body[dto.LoginForm]("form"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: tenant
|
// Register routes for controller: tenant
|
||||||
|
|||||||
Reference in New Issue
Block a user