1. 修复密码被重复加密的问题

2. gin改为debug模式
This commit is contained in:
2025-09-08 17:07:32 +08:00
parent ca3cf02396
commit 0b16d7d886
3 changed files with 4 additions and 11 deletions

View File

@@ -63,7 +63,7 @@ type API struct {
// 初始化Gin引擎和相关配置
func NewAPI(cfg *config.Config, userRepo repository.UserRepo, operationHistoryRepo repository.OperationHistoryRepo, deviceControlRepo repository.DeviceControlRepo, deviceRepo repository.DeviceRepo, websocketService *service.WebSocketService) *API {
// 设置Gin为发布模式
gin.SetMode(gin.ReleaseMode)
gin.SetMode(gin.DebugMode)
// 创建Gin引擎实例
engine := gin.New()

View File

@@ -65,16 +65,8 @@ func (c *Controller) Register(ctx *gin.Context) {
return
}
// 对密码进行哈希处理
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
if err != nil {
c.logger.Error("密码哈希处理失败: " + err.Error())
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "用户注册失败")
return
}
// 创建用户
user, err := c.userRepo.CreateUser(req.Username, string(hashedPassword))
user, err := c.userRepo.CreateUser(req.Username, req.Password)
if err != nil {
c.logger.Error("创建用户失败: " + err.Error())
controller.SendErrorResponse(ctx, controller.InternalServerErrorCode, "用户注册失败")

View File

@@ -24,5 +24,6 @@ type Storage interface {
// 根据配置返回相应的存储实现
func NewStorage(connectionString string, maxOpenConns, maxIdleConns, connMaxLifetime int) Storage {
// 当前默认返回PostgreSQL存储实现
return NewPostgresStorage(connectionString, maxOpenConns, maxIdleConns, connMaxLifetime)
s := NewPostgresStorage(connectionString, maxOpenConns, maxIdleConns, connMaxLifetime)
return s
}