merged
This commit is contained in:
@@ -12,7 +12,7 @@ public interface IIdentityService
|
||||
Task<Result> UpdateCurrentUserBannerPictureUrlAsync(string url);
|
||||
Task<Result> UpdateCurrentUserProfilePictureUrlAsync(string url);
|
||||
Task<Result> UpdateCurrentUserWebsiteIconUrlAsync(string url);
|
||||
Task<Result<string>> UpdateCurrentUserAsync(UserModel userModel, string? portraitUrl);
|
||||
Task<Result<string>> UpdateCurrentUserAsync(UserModel userModel);
|
||||
Task<IList<string>> GetCurrentUserRolesAsync();
|
||||
Task<UserModel?> FindUserByIdAsync(string id);
|
||||
Task<UserModel?> FindUserByEmailAsync(string email);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class UpdateCurrentUserCommandHandler(IApplicationDbContext context, IIde
|
||||
var userModel = mapper.Map<UserModel>(request);
|
||||
userModel.Id = identityUser.Id;
|
||||
|
||||
var result = await identityService.UpdateCurrentUserAsync(userModel, request.PortraitUrl);
|
||||
var result = await identityService.UpdateCurrentUserAsync(userModel);
|
||||
|
||||
await context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<Result<string>> UpdateCurrentUserAsync(UserModel userModel, string? portraitUrl)
|
||||
public async Task<Result<string>> 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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user