Added profile ProfileColors and Profile images
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Google.Apis.Oauth2.v2.Data;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Application.Common.Models;
|
||||
using Hutopy.Application.Users.Models;
|
||||
@@ -64,10 +66,8 @@ public class IdentityService(
|
||||
|
||||
var applicationResult = identityResult.ToApplicationResult();
|
||||
|
||||
var result = new Result<string>(applicationResult.Succeeded, applicationResult.Errors);
|
||||
var result = new Result<string>(applicationUser.Id, applicationResult.Succeeded, applicationResult.Errors);
|
||||
|
||||
result.Value = applicationUser.Id;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -83,51 +83,53 @@ public class IdentityService(
|
||||
|
||||
var response = await userManager.CreateAsync(applicationUser, password);
|
||||
|
||||
var result = new Result<string>(response.Succeeded, response.ToApplicationResult().Errors);
|
||||
result.Value = applicationUser.Id;
|
||||
var result = new Result<string>(applicationUser.Id, response.Succeeded, response.ToApplicationResult().Errors);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result<string>> UpdateCurrentUserAsync(string id, string firstName, string lastName, string occupation,
|
||||
string phoneNumber, string birthDate, string country, string city, string address, string about, string description,
|
||||
SocialNetworksModel socialNetworks)
|
||||
public async Task<Result<string>> UpdateCurrentUserAsync(UserModel userModel)
|
||||
{
|
||||
var applicationUser = await userManager.FindByIdAsync(id);
|
||||
var applicationUser = await userManager.FindByIdAsync(userModel.Id);
|
||||
|
||||
if (applicationUser is null) return Result<string>.Failure(new[] { "User not found." });
|
||||
if (applicationUser is null) return Result<string>.Failure("", new[] { "User not found." });
|
||||
|
||||
applicationUser.FirstName = firstName;
|
||||
applicationUser.LastName = lastName;
|
||||
applicationUser.Occupation = occupation;
|
||||
applicationUser.PhoneNumber = phoneNumber;
|
||||
applicationUser.BirthDate = birthDate;
|
||||
applicationUser.Country = country;
|
||||
applicationUser.City = city;
|
||||
applicationUser.Address = address;
|
||||
applicationUser.About = about;
|
||||
applicationUser.Description = description;
|
||||
applicationUser.SocialNetworks = new SocialNetworks()
|
||||
applicationUser.FirstName = userModel.FirstName;
|
||||
applicationUser.LastName = userModel.LastName;
|
||||
applicationUser.Occupation = userModel.Occupation;
|
||||
applicationUser.PhoneNumber = userModel.Phone;
|
||||
applicationUser.BirthDate = userModel.BirthDate;
|
||||
applicationUser.Country = userModel.Country;
|
||||
applicationUser.City = userModel.City;
|
||||
applicationUser.Address = userModel.Address;
|
||||
applicationUser.About = userModel.About;
|
||||
applicationUser.Description = userModel.Description;
|
||||
applicationUser.SocialNetworks = new SocialNetworks
|
||||
{
|
||||
FacebookUrl = socialNetworks.FacebookUrl,
|
||||
InstagramUrl = socialNetworks.InstagramUrl,
|
||||
XUrl = socialNetworks.XUrl,
|
||||
LinkedInUrl = socialNetworks.LinkedInUrl,
|
||||
TikTokUrl = socialNetworks.TikTokUrl,
|
||||
YoutubeUrl = socialNetworks.YoutubeUrl,
|
||||
RedditUrl = socialNetworks.RedditUrl,
|
||||
YourWebsiteUrl = socialNetworks.YourWebsiteUrl
|
||||
FacebookUrl = userModel.SocialNetworks.FacebookUrl,
|
||||
InstagramUrl = userModel.SocialNetworks.InstagramUrl,
|
||||
XUrl = userModel.SocialNetworks.XUrl,
|
||||
LinkedInUrl = userModel.SocialNetworks.LinkedInUrl,
|
||||
TikTokUrl = userModel.SocialNetworks.TikTokUrl,
|
||||
YoutubeUrl = userModel.SocialNetworks.YoutubeUrl,
|
||||
RedditUrl = userModel.SocialNetworks.RedditUrl,
|
||||
YourWebsiteUrl = userModel.SocialNetworks.YourWebsiteUrl
|
||||
};
|
||||
applicationUser.ProfileColors = new ProfileColors
|
||||
{
|
||||
BannerTop = userModel.ProfileColors.BannerTop,
|
||||
BannerBottom = userModel.ProfileColors.BannerBottom,
|
||||
Accent = userModel.ProfileColors.Accent,
|
||||
Menu = userModel.ProfileColors.Menu
|
||||
};
|
||||
|
||||
var response = await userManager.UpdateAsync(applicationUser);
|
||||
|
||||
var applicationResult = response.ToApplicationResult();
|
||||
|
||||
var result = new Result<string>(applicationResult.Succeeded,
|
||||
var result = new Result<string>(userModel.Id, applicationResult.Succeeded,
|
||||
applicationResult.Errors);
|
||||
|
||||
result.Value = id;
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -140,12 +142,12 @@ 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,
|
||||
Phone = response.PhoneNumber,
|
||||
Phone = response.PhoneNumber ?? string.Empty,
|
||||
BirthDate = response.BirthDate,
|
||||
Country = response.Country,
|
||||
City = response.City,
|
||||
@@ -162,6 +164,57 @@ public class IdentityService(
|
||||
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
|
||||
}
|
||||
};
|
||||
|
||||
return userModel;
|
||||
}
|
||||
|
||||
public async Task<UserModel?> FindUserByEmailAsync(string email)
|
||||
{
|
||||
var response = await userManager.FindByEmailAsync(email);
|
||||
|
||||
if (response == null) return null;
|
||||
|
||||
var userModel = new UserModel
|
||||
{
|
||||
Id = response.Id,
|
||||
UserName = response.UserName ?? string.Empty,
|
||||
FirstName = response.FirstName,
|
||||
LastName = response.LastName,
|
||||
Email = response.Email ?? string.Empty,
|
||||
Occupation = response.Occupation,
|
||||
Phone = 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
|
||||
}
|
||||
};
|
||||
|
||||
@@ -179,22 +232,49 @@ public class IdentityService(
|
||||
return await FindUserByIdAsync(currentUserId);
|
||||
}
|
||||
|
||||
public async Task<UserModel?> FindUserByEmailAsync(string email)
|
||||
public async Task<Result> UpdateCurrentUserBannerPictureUrlAsync(string url)
|
||||
{
|
||||
var response = await userManager.FindByEmailAsync(email);
|
||||
var userModel = await GetCurrentUserAsync();
|
||||
if (userModel is null) return Result.Failure(new[] { "User not found." });
|
||||
|
||||
if (response == null) return null;
|
||||
var applicationUser = await userManager.FindByIdAsync(userModel.Id);
|
||||
if (applicationUser is null) return Result.Failure(new[] { "ApplicationUser not found." });
|
||||
|
||||
var userModel = new UserModel
|
||||
{
|
||||
Id = response.Id,
|
||||
UserName = response.UserName,
|
||||
FirstName = response.FirstName,
|
||||
LastName = response.LastName,
|
||||
Email = response.Email
|
||||
};
|
||||
applicationUser.StoredDataUrls.BannerPictureUrl = url;
|
||||
|
||||
var response = await userManager.UpdateAsync(applicationUser);
|
||||
|
||||
return userModel;
|
||||
return response.ToApplicationResult();
|
||||
}
|
||||
|
||||
public async Task<Result> UpdateCurrentUserProfilePictureUrlAsync(string url)
|
||||
{
|
||||
var userModel = await GetCurrentUserAsync();
|
||||
if (userModel is null) return Result.Failure(new[] { "User not found." });
|
||||
|
||||
var applicationUser = await userManager.FindByIdAsync(userModel.Id);
|
||||
if (applicationUser is null) return Result.Failure(new[] { "ApplicationUser not found." });
|
||||
|
||||
applicationUser.StoredDataUrls.ProfilePictureUrl = url;
|
||||
|
||||
var response = await userManager.UpdateAsync(applicationUser);
|
||||
|
||||
return response.ToApplicationResult();
|
||||
}
|
||||
|
||||
public async Task<Result> UpdateCurrentUserWebsiteIconUrlAsync(string url)
|
||||
{
|
||||
var userModel = await GetCurrentUserAsync();
|
||||
if (userModel is null) return Result.Failure(new[] { "User not found." });
|
||||
|
||||
var applicationUser = await userManager.FindByIdAsync(userModel.Id);
|
||||
if (applicationUser is null) return Result.Failure(new[] { "ApplicationUser not found." });
|
||||
|
||||
applicationUser.StoredDataUrls.WebsiteIconUrl = url;
|
||||
|
||||
var response = await userManager.UpdateAsync(applicationUser);
|
||||
|
||||
return response.ToApplicationResult();
|
||||
}
|
||||
|
||||
public async Task<bool> IsInRoleAsync(string userId, string role)
|
||||
@@ -293,7 +373,7 @@ public class IdentityService(
|
||||
email: user.Email,
|
||||
firstname: user.FirstName,
|
||||
lastname: user.LastName,
|
||||
portraitUrl: user.PortraitUrl);
|
||||
portraitUrl: user.ProfilePictureUrl);
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user