Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

login_admin.go 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package admin
  2. import (
  3. "context"
  4. "fmt"
  5. "git.x2erp.com/qdy/go-base/config"
  6. "git.x2erp.com/qdy/go-base/ctx"
  7. "git.x2erp.com/qdy/go-base/logger"
  8. "git.x2erp.com/qdy/go-base/model/request/configreq"
  9. "git.x2erp.com/qdy/go-base/model/response"
  10. "git.x2erp.com/qdy/go-base/util"
  11. )
  12. // LoginAdmin 管理员登录(验证配置文件凭据)
  13. func LoginAdmin(req *configreq.UserLoginRequest, ctx context.Context, reqCtx *ctx.RequestContext) *response.QueryResult[bool] {
  14. logger.Debug("LoginAdmin-开始管理员登录")
  15. // 参数验证
  16. if req.UserID == "" || req.Password == "" {
  17. logger.ErrorC(reqCtx, "管理员用户名和密码不能为空")
  18. return util.CreateErrorResult[bool]("管理员用户名和密码不能为空", reqCtx)
  19. }
  20. // 获取配置文件中的管理员凭据
  21. cfg := config.GetConfig()
  22. serviceConfig := cfg.GetServiceConfig()
  23. configUsername := serviceConfig.Username
  24. configPassword := serviceConfig.Password
  25. // 验证用户名密码是否匹配配置文件
  26. if req.UserID != configUsername || req.Password != configPassword {
  27. logger.ErrorC(reqCtx, fmt.Sprintf("管理员用户名或密码错误, 配置用户名: %s", configUsername))
  28. return util.CreateErrorResult[bool]("管理员用户名或密码错误", reqCtx)
  29. }
  30. logger.Debug(fmt.Sprintf("管理员登录成功: %s", configUsername))
  31. return util.CreateSuccessResultData(true, reqCtx)
  32. }