feat: Sistema de autenticación frontend (Login + Register + Dashboard) #3
22
Backend/PruebaGentle.Core/DTOs/RegisterDto.cs
Normal file
22
Backend/PruebaGentle.Core/DTOs/RegisterDto.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PruebaGentle.Core.DTOs;
|
||||
|
||||
public class RegisterDto
|
||||
{
|
||||
[Required]
|
||||
[StringLength(50, MinimumLength = 3)]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(100, MinimumLength = 6)]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[EmailAddress]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
[StringLength(100)]
|
||||
public string NombreCompleto { get; set; } = string.Empty;
|
||||
}
|
||||
8
Backend/PruebaGentle.Core/DTOs/RegisterResponseDto.cs
Normal file
8
Backend/PruebaGentle.Core/DTOs/RegisterResponseDto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace PruebaGentle.Core.DTOs;
|
||||
|
||||
public class RegisterResponseDto
|
||||
{
|
||||
public string Token { get; set; } = string.Empty;
|
||||
public DateTime ExpiresAt { get; set; }
|
||||
public int UserId { get; set; }
|
||||
}
|
||||
26
Backend/Sql/sp_User_Register.sql
Normal file
26
Backend/Sql/sp_User_Register.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
CREATE OR ALTER PROCEDURE sp_User_Register
|
||||
@Username NVARCHAR(50),
|
||||
@PasswordHash NVARCHAR(255),
|
||||
@Email NVARCHAR(100),
|
||||
@NombreCompleto NVARCHAR(100)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
-- Check if username already exists
|
||||
IF EXISTS (SELECT 1 FROM Users WHERE Username = @Username)
|
||||
BEGIN
|
||||
THROW 50001, 'El nombre de usuario ya existe.', 1;
|
||||
END
|
||||
|
||||
-- Check if email already exists
|
||||
IF EXISTS (SELECT 1 FROM Users WHERE Email = @Email)
|
||||
BEGIN
|
||||
THROW 50002, 'El email ya existe.', 1;
|
||||
END
|
||||
|
||||
-- Insert new user
|
||||
INSERT INTO Users (Username, PasswordHash, Email, NombreCompleto)
|
||||
OUTPUT INSERTED.Id, INSERTED.Username, INSERTED.Email, INSERTED.NombreCompleto, INSERTED.FechaCreacion
|
||||
VALUES (@Username, @PasswordHash, @Email, @NombreCompleto);
|
||||
END
|
||||
Reference in New Issue
Block a user