diff --git a/phronCare.API/Controllers/AccountController.cs b/phronCare.API/Controllers/AccountController.cs index 853d6b7..af9e9cd 100644 --- a/phronCare.API/Controllers/AccountController.cs +++ b/phronCare.API/Controllers/AccountController.cs @@ -142,7 +142,13 @@ namespace phronCare.API.Controllers user.NormalizedEmail = model.Email.ToUpper(); user.TwoFactorEnabled = model.TwoFactorEnabled; user.LockoutEnabled = model.LockoutEnabled; - + // Campos personalizados + user.FirstName = model.FirstName; + user.LastName = model.LastName; + user.PhoneNumber = model.PhoneNumber; + user.CompanyName = model.CompanyName; + user.Department = model.Department; + user.BirthDate = model.BirthDate; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) diff --git a/phronCare.API/Models/Account/UserUpdate.cs b/phronCare.API/Models/Account/UserUpdate.cs index c991b1a..ef71b30 100644 --- a/phronCare.API/Models/Account/UserUpdate.cs +++ b/phronCare.API/Models/Account/UserUpdate.cs @@ -7,6 +7,14 @@ public string Email { get; set; } = string.Empty; public bool TwoFactorEnabled { get; set; } public bool LockoutEnabled { get; set; } + + // Nuevos campos + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? PhoneNumber { get; set; } + public string? CompanyName { get; set; } + public string? Department { get; set; } + public DateTime? BirthDate { get; set; } } public class User { @@ -24,5 +32,12 @@ public DateTimeOffset? LockoutEnd { get; set; } public bool LockoutEnabled { get; set; } public int AccessFailedCount { get; set; } + + // Nuevos campos + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? Company { get; set; } + public string? Department { get; set; } + public DateTime? BirthDate { get; set; } } } diff --git a/phronCare.UIBlazor/Pages/Accounts/Registration.razor b/phronCare.UIBlazor/Pages/Accounts/Registration.razor index 6b9dc5c..9415e68 100644 --- a/phronCare.UIBlazor/Pages/Accounts/Registration.razor +++ b/phronCare.UIBlazor/Pages/Accounts/Registration.razor @@ -1,71 +1,104 @@ @page "/registration" -@using System.Text.Json; -@using System.Collections.Generic -@using System.ComponentModel.DataAnnotations; +@using System.Text.Json +@using System.ComponentModel.DataAnnotations @inject HttpClient httpClient @inject IToastService toastService @inject NavigationManager navigation -

Registro de Usuario

- - - - - -
- -
- -
+
+
+

Registro de Usuario

-
- -
- -
+
+ + + + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + + @foreach (var role in roles) + { + + } + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+
-
- -
- -
+ - -
- -
- -
-
- -
- -
- - @foreach (var role in roles) - { - - } - -
-
-
- - - - +
@code { - private User user = new User(); - private string confirmPassword=string.Empty; + private User user = new(); + private string confirmPassword = string.Empty; - - public List roles = new List(); // Reemplaza con tu lista de roles reales + public List roles = new(); private const int USERNAME_VALID_LENGTH = 8; + protected override async Task OnInitializedAsync() { roles = await GetAllRoles(); @@ -78,25 +111,26 @@ } private async Task RegistrarUsuario() - { + { if (user.UserName.Length < USERNAME_VALID_LENGTH) { - toastService.ShowError($"longitud de nombre minima: {USERNAME_VALID_LENGTH} caracteres. ¡Inténtalo de nuevo!"); + toastService.ShowError($"El nombre de usuario debe tener al menos {USERNAME_VALID_LENGTH} caracteres."); } else if (user.Password != confirmPassword) { - toastService.ShowError("Las contraseñas no coinciden. ¡Inténtalo de nuevo!"); + toastService.ShowError("Las contraseñas no coinciden."); } else if (string.IsNullOrEmpty(user.Role)) { - toastService.ShowWarning("Debes seleccionar un rol."); + toastService.ShowWarning("Debe seleccionar un rol."); } else { await CreateUser(); } } - public async Task CreateUser() + + private async Task CreateUser() { var requestContent = new StringContent(JsonSerializer.Serialize(user), System.Text.Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("/api/Authentication/register/", requestContent); @@ -111,18 +145,26 @@ toastService.ShowError(errorResponse); } } - public void Cancel() + + private void Cancel() { navigation.NavigateTo("/users"); } public class User { - [Required(ErrorMessage = "El Username es un dato obligatorio")] public string UserName { get; set; } = string.Empty; - [EmailAddress, Required(ErrorMessage = "El correo electronico es un dato obligatorio")] public string EmailAddress { get; set; } = string.Empty; - [Required(ErrorMessage = "La contraseña es un dato obligatorio")] public string Password { get; set; } = string.Empty; - [Required(ErrorMessage = "El rol es un dato obligatorio")] public string Role { get; set; } = string.Empty; + [Required] public string UserName { get; set; } = string.Empty; + [EmailAddress, Required] public string EmailAddress { get; set; } = string.Empty; + [Required] public string Password { get; set; } = string.Empty; + [Required] public string Role { get; set; } = string.Empty; + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? PhoneNumber { get; set; } + public string? Company { get; set; } + public string? Department { get; set; } + public DateTime? BirthDate { get; set; } } + public class Role { public string Id { get; set; } = string.Empty; diff --git a/phronCare.UIBlazor/Pages/Accounts/RoleForm.razor b/phronCare.UIBlazor/Pages/Accounts/RoleForm.razor index b7cc176..712366a 100644 --- a/phronCare.UIBlazor/Pages/Accounts/RoleForm.razor +++ b/phronCare.UIBlazor/Pages/Accounts/RoleForm.razor @@ -1,5 +1,5 @@ -@page "/roleform/edit/{id}" -@page "/roleform/create" +@page "/role/{id}" +@page "/role/create" @using System.Net.Http.Headers; @using System.Text.Json; @@ -9,8 +9,14 @@ @inject IToastService toastService @inject AuthenticationStateProvider authenticationStateProvider -

Editar Rol

- +@if (role.Id is null) +{ +

Crear Nuevo Rol

+} +else +{ +

Editar Rol

+} @if (role is not null) { @@ -42,10 +48,8 @@ [Parameter] public string id { get; set; } = string.Empty; private Role? role; - protected override async Task OnInitializedAsync() { - if ( id is not null) { role = await GetRole(id); @@ -55,6 +59,7 @@ role = new Role(); } } + public async Task GetRole(string roleId) { var customAuthStateProvider = (CustomAuthorizationProvider)authenticationStateProvider; @@ -75,7 +80,6 @@ }; Role role = JsonSerializer.Deserialize(jsonResponse, options) ?? new Role(); return role; - } } catch @@ -88,7 +92,7 @@ } private async Task UpsertRole() { - if(role is null) + if(role.Id is null) { await CreateRole(); } @@ -99,23 +103,8 @@ } public async Task UpdateRole() { - // var requestContent = new StringContent(JsonSerializer.Serialize(role), System.Text.Encoding.UTF8, "application/json"); - // var response = await _httpClient.PutAsync("/api/Account/UpdateRole/"+role.Id, requestContent); - - // if (response.IsSuccessStatusCode) - // { - // toastService.ShowSuccess("El registro fue actualizado correctamente!"); - // Navigation.NavigateTo("/roles"); // Redirige a la página de roles después de la actualización - // } - // else - // { - // // Manejar errores de actualización - // var errorResponse = await response.Content.ReadAsStringAsync(); - // toastService.ShowError(errorResponse); - // } if (role == null) { - // Maneja el caso en que role es null toastService.ShowError("Role no está definido."); return; } @@ -135,10 +124,10 @@ toastService.ShowError(errorResponse); } } + public async Task CreateRole() { var newConcurrencyStamp = Guid.NewGuid().ToString(); - var requestContent = new StringContent(JsonSerializer.Serialize(role), System.Text.Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("/api/Account/CreateRole/", requestContent); var errorResponse = await response.Content.ReadAsStringAsync(); diff --git a/phronCare.UIBlazor/Pages/Accounts/Roles.razor b/phronCare.UIBlazor/Pages/Accounts/Roles.razor index 9028f63..31e9828 100644 --- a/phronCare.UIBlazor/Pages/Accounts/Roles.razor +++ b/phronCare.UIBlazor/Pages/Accounts/Roles.razor @@ -10,7 +10,7 @@ @inject AuthenticationStateProvider authenticationStateProvider

Lista de Roles

-Crear Nuevo Rol +Crear Nuevo Rol
@if (roles != null && roles.Count > 0) { @@ -100,7 +100,7 @@ else } public void EditRole(string roleId) { - navigation.NavigateTo($"/roleform/edit/{roleId}"); + navigation.NavigateTo($"/role/{roleId}"); } private void ConfirmDelete(string roleId) { diff --git a/phronCare.UIBlazor/Pages/Accounts/UserForm.razor b/phronCare.UIBlazor/Pages/Accounts/UserForm.razor index 9378a86..474cfc4 100644 --- a/phronCare.UIBlazor/Pages/Accounts/UserForm.razor +++ b/phronCare.UIBlazor/Pages/Accounts/UserForm.razor @@ -1,54 +1,80 @@ @page "/userform/edit/{Id}" -@using System.Net.Http.Headers; -@using System.Text.Json; +@using System.Net.Http.Headers +@using System.Text.Json @using Microsoft.AspNetCore.Components.Forms @inject HttpClient _httpClient @inject NavigationManager Navigation -@inject IToastService toastService @inject AuthenticationStateProvider authenticationStateProvider +@inject IToastService toastService -

Editar Usuario

-@if (user is not null) -{ - -
- -
- +
+
+

Editar Usuario

+
+ + @if (user is not null) + { + +
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+ + +
+
+
+
+ + +
+
+
-
-
- -
- + + -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- - -
- -} + + } +
@code { [Parameter] @@ -57,12 +83,12 @@ protected override async Task OnInitializedAsync() { - if (id is not null) { user = await GetUser(id); } } + public async Task GetUser(string userId) { var customAuthStateProvider = (CustomAuthorizationProvider)authenticationStateProvider; @@ -77,28 +103,31 @@ if (response.IsSuccessStatusCode) { var jsonResponse = await response.Content.ReadAsStringAsync(); - var options = new JsonSerializerOptions - { - PropertyNameCaseInsensitive = true - }; + var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; var deserializedUser = JsonSerializer.Deserialize(jsonResponse, options); User user = deserializedUser ?? new User(); - // user = JsonSerializer.Deserialize(jsonResponse, options); - UserUpdate require = new UserUpdate(); - require.Id = user.Id; - require.UserName = user.UserName; - require.Email = user.Email; - require.LockoutEnabled = user.LockoutEnabled; - require.TwoFactorEnabled = user.TwoFactorEnabled; - return require; + return new UserUpdate + { + Id = user.Id, + UserName = user.UserName, + Email = user.Email, + LockoutEnabled = user.LockoutEnabled, + TwoFactorEnabled = user.TwoFactorEnabled, + FirstName = user.FirstName, + LastName = user.LastName, + PhoneNumber = user.PhoneNumber, + CompanyName = user.CompanyName, + Department = user.Department, + BirthDate = user.BirthDate + }; } } catch { return null; } - }; + } return null; } @@ -125,10 +154,12 @@ toastService.ShowError(ex.Message); } } + public void Cancel() { Navigation.NavigateTo("/users"); } + public class User { public string Id { get; set; } = string.Empty; @@ -145,14 +176,27 @@ public DateTimeOffset? LockoutEnd { get; set; } public bool LockoutEnabled { get; set; } public int AccessFailedCount { get; set; } + + // Campos personalizados + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? CompanyName { get; set; } + public string? Department { get; set; } + public DateTime? BirthDate { get; set; } } + public class UserUpdate { public string Id { get; set; } = string.Empty; public string UserName { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; + public string? FirstName { get; set; } + public string? LastName { get; set; } + public string? PhoneNumber { get; set; } + public string? CompanyName { get; set; } + public string? Department { get; set; } + public DateTime? BirthDate { get; set; } public bool TwoFactorEnabled { get; set; } public bool LockoutEnabled { get; set; } } - -} +} \ No newline at end of file diff --git a/phronCare.UIBlazor/Pages/Accounts/Users.razor b/phronCare.UIBlazor/Pages/Accounts/Users.razor index 48cceac..bac61cc 100644 --- a/phronCare.UIBlazor/Pages/Accounts/Users.razor +++ b/phronCare.UIBlazor/Pages/Accounts/Users.razor @@ -10,41 +10,53 @@ @inject AuthenticationStateProvider authenticationStateProvider

Lista de Usuarios

-Registrar usuario -
+Registrar usuario + @if (users != null && users.Count > 0) { - - +
+ - - - - - - - - + + + + + + + + + + + @foreach (var user in users) { - + - - - - + + + + + + + } @@ -53,8 +65,7 @@ } else { -
-

Cargando informacion...

+

Cargando información o no hay usuarios disponibles...

} @code { @@ -69,7 +80,7 @@ else try { var response = await _httpClient.GetAsync("/api/Account/GetAllUsers"); - Console.WriteLine(token.token); + //Console.WriteLine(token.token); if (response.IsSuccessStatusCode) { var jsonResponse = await response.Content.ReadAsStringAsync(); @@ -206,5 +217,15 @@ else public DateTimeOffset? LockoutEnd { get; set; } public bool LockoutEnabled { get; set; } public int AccessFailedCount { get; set; } + + // Nuevos campos + public string FirstName { get; set; } = string.Empty; + public string LastName { get; set; } = string.Empty; + public string FullName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public string Department { get; set; } = string.Empty; + public string CompanyName { get; set; } = string.Empty; + public DateTime? BirthDate { get; set; } } + } \ No newline at end of file
IdUsernameEmailConfirmed2FAAccess FailedLockoutActionsNombre completoUsuarioEmailTeléfonoEmpresaDepartamentoVerificado2FA#IntentosLockoutAcciones
@user.Id@user.FullName @user.UserName @user.Email@user.EmailConfirmed@user.TwoFactorEnabled@user.AccessFailedCount@user.LockoutEnabled@user.PhoneNumber@user.CompanyName@user.Department@(user.EmailConfirmed ? "✅" : "❌")@(user.TwoFactorEnabled ? "✅" : "❌")@user.AccessFailedCount@(user.LockoutEnabled ? "✅" : "❌") - + @if (user.UserName.ToLower() != "superdmin") { - + } - +