package admin import ( "context" "fmt" "git.x2erp.com/qdy/go-base/config" "git.x2erp.com/qdy/go-base/ctx" "git.x2erp.com/qdy/go-base/logger" "git.x2erp.com/qdy/go-base/model/request/configreq" "git.x2erp.com/qdy/go-base/model/response" "git.x2erp.com/qdy/go-base/util" ) // LoginAdmin 管理员登录(验证配置文件凭据) func LoginAdmin(req *configreq.UserLoginRequest, ctx context.Context, reqCtx *ctx.RequestContext) *response.QueryResult[bool] { logger.Debug("LoginAdmin-开始管理员登录") // 参数验证 if req.UserID == "" || req.Password == "" { logger.ErrorC(reqCtx, "管理员用户名和密码不能为空") return util.CreateErrorResult[bool]("管理员用户名和密码不能为空", reqCtx) } // 获取配置文件中的管理员凭据 cfg := config.GetConfig() serviceConfig := cfg.GetServiceConfig() configUsername := serviceConfig.Username configPassword := serviceConfig.Password // 验证用户名密码是否匹配配置文件 if req.UserID != configUsername || req.Password != configPassword { logger.ErrorC(reqCtx, fmt.Sprintf("管理员用户名或密码错误, 配置用户名: %s", configUsername)) return util.CreateErrorResult[bool]("管理员用户名或密码错误", reqCtx) } logger.Debug(fmt.Sprintf("管理员登录成功: %s", configUsername)) return util.CreateSuccessResultData(true, reqCtx) }