From 3558952634305f844b60d45f92add251878fb08e Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Thu, 4 Jul 2024 20:47:07 -0400 Subject: [PATCH] merged --- .../Common/Interfaces/IIdentityService.cs | 2 +- .../Commands/UpdateCurrentUserCommand.cs | 2 +- .../Queries/GetMinimalUser/GetMinimalUser.cs | 10 +++-- .../Queries/GetMinimalUser/MinimalUserDto.cs | 6 +++ .../Identity/IdentityResultExtensions.cs | 3 +- .../Identity/IdentityService.cs | 42 ++++++++++++++++--- src/Infrastructure/Identity/RoleService.cs | 4 +- src/Infrastructure/Utils/GenerateJwtToken.cs | 10 +++-- src/Web/Controllers/GoogleController.cs | 2 +- 9 files changed, 62 insertions(+), 19 deletions(-) diff --git a/src/Application/Common/Interfaces/IIdentityService.cs b/src/Application/Common/Interfaces/IIdentityService.cs index edcbb9c..74e9240 100644 --- a/src/Application/Common/Interfaces/IIdentityService.cs +++ b/src/Application/Common/Interfaces/IIdentityService.cs @@ -12,7 +12,7 @@ public interface IIdentityService Task UpdateCurrentUserBannerPictureUrlAsync(string url); Task UpdateCurrentUserProfilePictureUrlAsync(string url); Task UpdateCurrentUserWebsiteIconUrlAsync(string url); - Task> UpdateCurrentUserAsync(UserModel userModel, string? portraitUrl); + Task> UpdateCurrentUserAsync(UserModel userModel); Task> GetCurrentUserRolesAsync(); Task FindUserByIdAsync(string id); Task FindUserByEmailAsync(string email); diff --git a/src/Application/Users/Commands/UpdateCurrentUserCommand.cs b/src/Application/Users/Commands/UpdateCurrentUserCommand.cs index d47985a..8c9766f 100644 --- a/src/Application/Users/Commands/UpdateCurrentUserCommand.cs +++ b/src/Application/Users/Commands/UpdateCurrentUserCommand.cs @@ -44,7 +44,7 @@ public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIde var userModel = mapper.Map(request); userModel.Id = identityUser.Id; - var result = await identityService.UpdateCurrentUserAsync(userModel, request.PortraitUrl); + var result = await identityService.UpdateCurrentUserAsync(userModel); await context.SaveChangesAsync(cancellationToken); diff --git a/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs b/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs index e7e5940..124e9cf 100644 --- a/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs +++ b/src/Application/Users/Queries/GetMinimalUser/GetMinimalUser.cs @@ -28,15 +28,17 @@ public class GetMinimalUserQueryHandler( { identityUser = await identityService.GetUserByUserNameAsync(request.UserName); } - - + var user = new MinimalUserDto { FirstName = identityUser?.FirstName ?? string.Empty, LastName = identityUser?.LastName ?? string.Empty, - UserName = identityUser?.UserName ?? string.Empty + UserName = identityUser?.UserName ?? string.Empty, + SocialNetworks = identityUser?.SocialNetworks ?? new(), + ProfileColors = identityUser?.ProfileColors ?? new(), + StoredDataUrls = identityUser?.StoredDataUrls ?? new(), }; return user; } -} \ No newline at end of file +} diff --git a/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs b/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs index 97fa6a1..7648fa7 100644 --- a/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs +++ b/src/Application/Users/Queries/GetMinimalUser/MinimalUserDto.cs @@ -1,3 +1,5 @@ +using Hutopy.Application.Users.Models; + namespace Hutopy.Application.Users.Queries.GetMinimalUser; public class MinimalUserDto @@ -5,4 +7,8 @@ public class MinimalUserDto public required string FirstName { get; init; } public required string LastName { get; init; } public required string UserName { get; init; } = String.Empty; + + public SocialNetworksModel SocialNetworks { get; init; } = new(); + public ProfileColorsModel ProfileColors { get; init; } = new(); + public StoredDataUrlsModel StoredDataUrls { get; init; } = new(); } diff --git a/src/Infrastructure/Identity/IdentityResultExtensions.cs b/src/Infrastructure/Identity/IdentityResultExtensions.cs index 630c372..0902e4f 100644 --- a/src/Infrastructure/Identity/IdentityResultExtensions.cs +++ b/src/Infrastructure/Identity/IdentityResultExtensions.cs @@ -1,4 +1,5 @@ -using Hutopy.Application.Common.Models; +using System.Linq; +using Hutopy.Application.Common.Models; using Microsoft.AspNetCore.Identity; namespace Hutopy.Infrastructure.Identity; diff --git a/src/Infrastructure/Identity/IdentityService.cs b/src/Infrastructure/Identity/IdentityService.cs index fe0fc3d..2bc6ff4 100644 --- a/src/Infrastructure/Identity/IdentityService.cs +++ b/src/Infrastructure/Identity/IdentityService.cs @@ -41,10 +41,42 @@ public class IdentityService( var userModel = new UserModel() { Id = response.Id, - UserName = response.UserName, + UserName = response.UserName ?? string.Empty, FirstName = response.FirstName, LastName = response.LastName, - Email = response.Email, + Email = response.Email ?? string.Empty, + Occupation = response.Occupation, + PhoneNumber = response.PhoneNumber ?? string.Empty, + BirthDate = response.BirthDate, + Country = response.Country, + City = response.City, + Address = response.Address, + About = response.About, + Description = response.Description, + SocialNetworks = new SocialNetworksModel + { + FacebookUrl = response.SocialNetworks.FacebookUrl, + InstagramUrl = response.SocialNetworks.InstagramUrl, + XUrl = response.SocialNetworks.XUrl, + LinkedInUrl = response.SocialNetworks.LinkedInUrl, + TikTokUrl = response.SocialNetworks.TikTokUrl, + YoutubeUrl = response.SocialNetworks.YoutubeUrl, + RedditUrl = response.SocialNetworks.RedditUrl, + YourWebsiteUrl = response.SocialNetworks.YourWebsiteUrl, + }, + ProfileColors = new ProfileColorsModel + { + BannerTop = response.ProfileColors.BannerTop, + BannerBottom = response.ProfileColors.BannerBottom, + Accent = response.ProfileColors.Accent, + Menu = response.ProfileColors.Menu + }, + StoredDataUrls = new StoredDataUrlsModel + { + ProfilePictureUrl = response.StoredDataUrls.ProfilePictureUrl, + BannerPictureUrl = response.StoredDataUrls.BannerPictureUrl, + WebsiteIconUrl = response.StoredDataUrls.WebsiteIconUrl, + } }; return userModel; @@ -88,7 +120,7 @@ public class IdentityService( return result; } - public async Task> UpdateCurrentUserAsync(UserModel userModel, string? portraitUrl) + public async Task> UpdateCurrentUserAsync(UserModel userModel) { var applicationUser = await userManager.FindByIdAsync(userModel.Id); @@ -104,7 +136,6 @@ public class IdentityService( applicationUser.Address = userModel.Address; applicationUser.About = userModel.About; applicationUser.Description = userModel.Description; - applicationUser.PortraitUrl = portraitUrl; applicationUser.SocialNetworks = new SocialNetworks { FacebookUrl = userModel.SocialNetworks.FacebookUrl, @@ -155,7 +186,6 @@ public class IdentityService( Address = response.Address, About = response.About, Description = response.Description, - PortraitUrl = response.PortraitUrl, SocialNetworks = new SocialNetworksModel { FacebookUrl = response.SocialNetworks.FacebookUrl, @@ -387,7 +417,7 @@ public class IdentityService( email: user.Email, firstname: user.FirstName, lastname: user.LastName, - portraitUrl: user.PortraitUrl); + profilePictureUrl: user.StoredDataUrls.ProfilePictureUrl); return token; } diff --git a/src/Infrastructure/Identity/RoleService.cs b/src/Infrastructure/Identity/RoleService.cs index 71f0ed0..59fc22b 100644 --- a/src/Infrastructure/Identity/RoleService.cs +++ b/src/Infrastructure/Identity/RoleService.cs @@ -1,4 +1,6 @@ -using Hutopy.Application.Common.Interfaces; +using System; +using System.Threading.Tasks; +using Hutopy.Application.Common.Interfaces; using Hutopy.Application.Common.Models; using Microsoft.AspNetCore.Identity; diff --git a/src/Infrastructure/Utils/GenerateJwtToken.cs b/src/Infrastructure/Utils/GenerateJwtToken.cs index a4d74de..013da69 100644 --- a/src/Infrastructure/Utils/GenerateJwtToken.cs +++ b/src/Infrastructure/Utils/GenerateJwtToken.cs @@ -1,4 +1,6 @@ -using System.IdentityModel.Tokens.Jwt; +using System; +using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using System.Text; using Microsoft.IdentityModel.Tokens; @@ -15,7 +17,7 @@ public static class JwtTokenHelper string? email, string? firstname, string? lastname, - string? portraitUrl) + string? profilePictureUrl) { var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); @@ -31,9 +33,9 @@ public static class JwtTokenHelper new Claim(ClaimTypes.Surname, lastname), }); - if (portraitUrl is not null) + if (profilePictureUrl is not null) { - claims.Add(new Claim("portrait-url", portraitUrl)); + claims.Add(new Claim("portrait-url", profilePictureUrl)); } var token = new JwtSecurityToken( diff --git a/src/Web/Controllers/GoogleController.cs b/src/Web/Controllers/GoogleController.cs index dfaa91e..38e04e7 100644 --- a/src/Web/Controllers/GoogleController.cs +++ b/src/Web/Controllers/GoogleController.cs @@ -71,7 +71,7 @@ public class GoogleController(IIdentityService identityService, IHttpClientFacto user.Email, user.FirstName, user.LastName, - user.PortraitUrl); + user.StoredDataUrls.ProfilePictureUrl); return Ok(new { accessToken = token, email }); }