邹方成 1ab39d2f5a
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 25s
refactor: 重构项目结构并重命名模块
feat(admin): 新增工会管理功能
feat(activity): 添加活动管理相关服务
feat(user): 实现用户道具卡和积分管理
feat(guild): 新增工会成员管理功能

fix: 修复数据库连接配置
fix: 修正jwtoken导入路径
fix: 解决端口冲突问题

style: 统一代码格式和注释风格
style: 更新项目常量命名

docs: 添加项目框架和开发规范文档
docs: 更新接口文档注释

chore: 移除无用代码和文件
chore: 更新Makefile和配置文件
chore: 清理日志文件

test: 添加道具卡测试脚本
2025-11-14 21:10:00 +08:00

66 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package admin
import (
"fmt"
"net/http"
"bindbox-game/internal/code"
"bindbox-game/internal/pkg/core"
"bindbox-game/internal/pkg/utils"
"bindbox-game/internal/pkg/validation"
adminsvc "bindbox-game/internal/service/admin"
)
type loginRequest struct {
Username string `json:"username" binding:"required"` // 用户名
Password string `json:"password" binding:"required"` // 密码 (MD5加密后的密码)
}
type loginResponse struct {
Token string `json:"token"` // 登录成功后颁发的 Token
IsSuper int32 `json:"is_super"` // 是否是超级管理员(1:是 0:否)
}
// Login 管理员登录
// @Summary 管理员登录
// @Description 管理员登录
// @Tags 管理端.登录
// @Accept json
// @Produce json
// @Param RequestBody body loginRequest true "请求参数"
// @Success 200 {object} loginResponse
// @Failure 400 {object} code.Failure
// @Router /api/admin/login [post]
func (h *handler) Login() core.HandlerFunc {
return func(ctx core.Context) {
req := new(loginRequest)
res := new(loginResponse)
if err := ctx.ShouldBindJSON(req); err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
validation.Error(err)),
)
return
}
result, err := h.svc.Login(ctx.RequestContext(), adminsvc.LoginInput{
Username: req.Username,
Password: req.Password,
IP: utils.GetIP(ctx.Request()),
})
if err != nil {
ctx.AbortWithError(core.Error(
http.StatusBadRequest,
code.AdminLoginError,
fmt.Sprintf("%s%s", code.Text(code.AdminLoginError), err.Error())),
)
return
}
res.Token = result.Token
res.IsSuper = result.IsSuper
ctx.Payload(res)
}
}