feat(postit): allow username updates in profile flow
This commit is contained in:
parent
137665bfe0
commit
05e35d0677
5 changed files with 39 additions and 10 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using Yavsc.Abstract.Identity;
|
||||
using PostIt.ViewModels;
|
||||
|
||||
namespace PostIt.Tests;
|
||||
|
|
@ -66,11 +67,23 @@ public class HomePageProviderFlowTests
|
|||
Assert.NotNull(vm.RefreshCommand);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProfileUpdateRequest_allows_username_updates()
|
||||
{
|
||||
var request = new ProfileUpdateRequest
|
||||
{
|
||||
UserName = "alice.new"
|
||||
};
|
||||
|
||||
Assert.Equal("alice.new", request.UserName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UserProfilePage_can_save_profile_values()
|
||||
{
|
||||
var vm = new UserProfilePageViewModel
|
||||
{
|
||||
UserName = "alice.new",
|
||||
FullName = "Alice Example",
|
||||
Address = "14 rue de l’Érable",
|
||||
DedicatedGoogleCalendar = "calendar-123",
|
||||
|
|
|
|||
|
|
@ -109,10 +109,11 @@ public partial class UserProfilePageViewModel : ViewModelBase
|
|||
{
|
||||
var payload = new ProfileUpdateRequest
|
||||
{
|
||||
FullName = FullName,
|
||||
Address = Address,
|
||||
GoogleCalendarId = DedicatedGoogleCalendar == "Non configuré" ? string.Empty : DedicatedGoogleCalendar,
|
||||
BankInfoSummary = BankInfoSummary == "Aucune information bancaire" ? string.Empty : BankInfoSummary
|
||||
UserName = string.IsNullOrWhiteSpace(UserName) ? string.Empty : UserName.Trim(),
|
||||
FullName = string.IsNullOrWhiteSpace(FullName) ? string.Empty : FullName.Trim(),
|
||||
Address = string.IsNullOrWhiteSpace(Address) ? string.Empty : Address.Trim(),
|
||||
GoogleCalendarId = DedicatedGoogleCalendar == "Non configuré" ? string.Empty : DedicatedGoogleCalendar.Trim(),
|
||||
BankInfoSummary = BankInfoSummary == "Aucune information bancaire" ? string.Empty : BankInfoSummary.Trim()
|
||||
};
|
||||
|
||||
var endpoint = new Uri(new Uri(_api.Settings.ApiUrl.TrimEnd('/') + "/", UriKind.Absolute), "account/me").ToString();
|
||||
|
|
|
|||
|
|
@ -18,12 +18,13 @@
|
|||
IsIndeterminate="True"
|
||||
Height="8"/>
|
||||
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*" RowSpacing="8">
|
||||
<TextBox Watermark="Nom complet" Text="{Binding FullName}"/>
|
||||
<TextBox Grid.Row="1" Watermark="Adresse" Text="{Binding Address}" AcceptsReturn="True" TextWrapping="Wrap"/>
|
||||
<TextBox Grid.Row="2" Watermark="Calendrier Google" Text="{Binding DedicatedGoogleCalendar}"/>
|
||||
<TextBox Grid.Row="3" Watermark="Détails bancaires" Text="{Binding BankInfoSummary}" AcceptsReturn="True" TextWrapping="Wrap"/>
|
||||
<Button Grid.Row="4" Content="Enregistrer" Command="{Binding SaveProfileCommand}" IsEnabled="{Binding !IsBusy}"/>
|
||||
<Grid RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto" ColumnDefinitions="*" RowSpacing="8">
|
||||
<TextBox Watermark="Nom d’utilisateur" Text="{Binding UserName}"/>
|
||||
<TextBox Grid.Row="1" Watermark="Nom complet" Text="{Binding FullName}"/>
|
||||
<TextBox Grid.Row="2" Watermark="Adresse" Text="{Binding Address}" AcceptsReturn="True" TextWrapping="Wrap"/>
|
||||
<TextBox Grid.Row="3" Watermark="Calendrier Google" Text="{Binding DedicatedGoogleCalendar}"/>
|
||||
<TextBox Grid.Row="4" Watermark="Détails bancaires" Text="{Binding BankInfoSummary}" AcceptsReturn="True" TextWrapping="Wrap"/>
|
||||
<Button Grid.Row="5" Content="Enregistrer" Command="{Binding SaveProfileCommand}" IsEnabled="{Binding !IsBusy}"/>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Text="{Binding UserName, StringFormat='Nom d’utilisateur : {0}'}"/>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ namespace Yavsc.Abstract.Identity;
|
|||
|
||||
public class ProfileUpdateRequest
|
||||
{
|
||||
public string? UserName { get; set; }
|
||||
public string? FullName { get; set; }
|
||||
public string? Address { get; set; }
|
||||
public string? GoogleCalendarId { get; set; }
|
||||
|
|
|
|||
|
|
@ -103,6 +103,19 @@ namespace Yavsc.WebApi.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.UserName))
|
||||
{
|
||||
var trimmedUserName = request.UserName.Trim();
|
||||
if (!string.Equals(user.UserName, trimmedUserName, StringComparison.Ordinal))
|
||||
{
|
||||
var usernameUpdate = await _userManager.SetUserNameAsync(user, trimmedUserName);
|
||||
if (!usernameUpdate.Succeeded)
|
||||
{
|
||||
return BadRequest(new { error = "Unable to update username.", details = usernameUpdate.Errors.Select(e => e.Description) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.FullName))
|
||||
{
|
||||
user.FullName = request.FullName.Trim();
|
||||
|
|
|
|||
Loading…
Reference in a new issue