JIJO recupere el codigo dsps que de claude nukee mi repo LETS GOOO

This commit is contained in:
fede committed 2026-05-11 23:08:14 -03:00
1 parent a35539590a
commit 6c1bc50089
24 files changed
+1260

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
package auth
import (
"net/http"
"strings"
"repuestera_back/config"
"repuestera_back/dto"
"repuestera_back/models"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/bcrypt"
)
func Register(c *gin.Context) {
var req dto.RegisterRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
email := strings.ToLower(strings.TrimSpace(req.Email))
var existing models.Usuario
if err := config.DB.Where("LOWER(email) = ?", email).First(&existing).Error; err == nil {
c.JSON(http.StatusConflict, gin.H{"error": "El email ya esta registrado"})
return
}
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(req.Password), bcrypt.DefaultCost)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error al procesar la contrasena"})
return
}
user := models.Usuario{
Email: email,
Password: string(hashedPassword),
Name: req.Name,
}
if err := config.DB.Create(&user).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusCreated, dto.RegisterResponse{
ID: user.ID,
Email: user.Email,
Name: user.Name,
})
}