refactor(identity): isolate ASP.NET Identity in Infrastructure
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Failing after 4m5s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s
Heimdall Gitea / Detect CI scope (pull_request) Successful in 6s
Heimdall Gitea / Build and tests (pull_request) Failing after 4m5s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / CI policy (pull_request) Failing after 1s
This commit is contained in:
1 parent
2bf3dbc95b
commit
622add46ad
109 files changed
+4076
-1197
No files matched your search
@@ -3,17 +3,17 @@ using Heimdall.Application.Common.Persistence;
|
||||
using Heimdall.Application.DTOs;
|
||||
using Heimdall.Domain.Entities;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Heimdall.Application.Services;
|
||||
|
||||
namespace Heimdall.Application.Users.Commands.UpdateUser;
|
||||
|
||||
public class UpdateUserHandler : IRequestHandler<UpdateUserCommand, ServiceResult<UserResponse>>
|
||||
{
|
||||
private readonly UserManager<AppUser> _userManager;
|
||||
private readonly IIdentityAccountService _userManager;
|
||||
private readonly IUserRepository _repository;
|
||||
|
||||
public UpdateUserHandler(UserManager<AppUser> userManager, IUserRepository repository)
|
||||
public UpdateUserHandler(IIdentityAccountService userManager, IUserRepository repository)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_repository = repository;
|
||||
@@ -21,7 +21,7 @@ public class UpdateUserHandler : IRequestHandler<UpdateUserCommand, ServiceResul
|
||||
|
||||
public async Task<ServiceResult<UserResponse>> Handle(UpdateUserCommand command, CancellationToken ct)
|
||||
{
|
||||
var user = await _userManager.FindByIdAsync(command.Id.ToString()).ConfigureAwait(false);
|
||||
var user = await _userManager.FindByIdAsync(command.Id, ct).ConfigureAwait(false);
|
||||
if (user is null)
|
||||
return ServiceResult<UserResponse>.NotFound("User not found");
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateUserHandler : IRequestHandler<UpdateUserCommand, ServiceResul
|
||||
|
||||
if (!string.Equals(oldEmail, newEmail, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var existingUser = await _userManager.FindByEmailAsync(newEmail).ConfigureAwait(false);
|
||||
var existingUser = await _userManager.FindByEmailAsync(newEmail, ct).ConfigureAwait(false);
|
||||
if (existingUser is not null && existingUser.Id != user.Id)
|
||||
return ServiceResult<UserResponse>.Failure("Cette adresse email est déjà utilisée", 409);
|
||||
|
||||
@@ -55,15 +55,15 @@ public class UpdateUserHandler : IRequestHandler<UpdateUserCommand, ServiceResul
|
||||
user.Theme = command.Theme ?? user.Theme;
|
||||
user.Language = language ?? user.Language;
|
||||
|
||||
var result = await _userManager.UpdateAsync(user).ConfigureAwait(false);
|
||||
var result = await _userManager.UpdateAsync(user, ct).ConfigureAwait(false);
|
||||
if (!result.Succeeded)
|
||||
return ServiceResult<UserResponse>.Failure(
|
||||
string.Join(", ", result.Errors.Select(e => e.Description)));
|
||||
string.Join(", ", result.ErrorCodes));
|
||||
|
||||
if (emailChanged)
|
||||
{
|
||||
var stamp = await _userManager.UpdateSecurityStampAsync(user).ConfigureAwait(false);
|
||||
if (!stamp.Succeeded)
|
||||
var stamp = await _userManager.UpdateSecurityStampAsync(user, ct).ConfigureAwait(false);
|
||||
if (!stamp)
|
||||
return ServiceResult<UserResponse>.Failure("Email updated but existing sessions could not be revoked", 500);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user