-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix error response when activating account * fix activate account endpoint tests * add generating client urls from appsettings (class and options) * refactored sending emails to use client urls * add complete registration endpoint, command, command handler and domain logic * add complete registration endpoint tests * additional refactoring
- Loading branch information
1 parent
ef153ce
commit 04165c4
Showing
19 changed files
with
318 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/Modules/UserAccess/TeamUp.UserAccess.Application/CompleteRegistrationCommandHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using TeamUp.Common.Application; | ||
using TeamUp.UserAccess.Application.Abstractions; | ||
using TeamUp.UserAccess.Contracts; | ||
using TeamUp.UserAccess.Contracts.CompleteRegistration; | ||
using TeamUp.UserAccess.Domain; | ||
|
||
namespace TeamUp.UserAccess.Application; | ||
|
||
internal sealed class CompleteRegistrationCommandHandler : ICommandHandler<CompleteRegistrationCommand> | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
private readonly IPasswordService _passwordService; | ||
private readonly IUnitOfWork<UserAccessModuleId> _unitOfWork; | ||
|
||
public CompleteRegistrationCommandHandler(IUserRepository userRepository, IPasswordService passwordService, IUnitOfWork<UserAccessModuleId> unitOfWork) | ||
{ | ||
_userRepository = userRepository; | ||
_passwordService = passwordService; | ||
_unitOfWork = unitOfWork; | ||
} | ||
|
||
public async Task<Result> Handle(CompleteRegistrationCommand command, CancellationToken ct) | ||
{ | ||
var user = await _userRepository.GetUserByIdAsync(command.UserId, ct); | ||
return await user | ||
.EnsureNotNull(UserErrors.UserNotFound) | ||
.Then(user => user.CompleteGeneratedRegistration(_passwordService.HashPassword(command.Password))) | ||
.TapAsync(() => _unitOfWork.SaveChangesAsync(ct)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...serAccess/TeamUp.UserAccess.Contracts/CompleteRegistration/CompleteRegistrationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using FluentValidation; | ||
|
||
using TeamUp.Common.Contracts; | ||
|
||
namespace TeamUp.UserAccess.Contracts.CompleteRegistration; | ||
|
||
public sealed record CompleteRegistrationCommand : ICommand | ||
{ | ||
public required UserId UserId { get; init; } | ||
public required string Password { get; init; } | ||
|
||
public sealed class Validator : AbstractValidator<CompleteRegistrationCommand> | ||
{ | ||
public Validator() | ||
{ | ||
RuleFor(x => x.UserId).NotEmpty(); | ||
RuleFor(x => x.Password).NotEmpty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Modules/UserAccess/TeamUp.UserAccess.Domain/IClientUrlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using TeamUp.UserAccess.Contracts; | ||
|
||
namespace TeamUp.UserAccess.Domain; | ||
|
||
public interface IClientUrlGenerator | ||
{ | ||
public string GetActivationUrl(UserId userId); | ||
public string GetCompleteAccountRegistrationUrl(UserId userId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/Modules/UserAccess/TeamUp.UserAccess.Endpoints/Endpoint.CompleteRegistration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using MediatR; | ||
|
||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
|
||
using TeamUp.Common.Endpoints; | ||
using TeamUp.UserAccess.Contracts; | ||
using TeamUp.UserAccess.Contracts.CompleteRegistration; | ||
|
||
namespace TeamUp.UserAccess.Endpoints; | ||
|
||
public sealed class CompleteRegistrationEndpoint : IEndpoint | ||
{ | ||
public void MapEndpoint(RouteGroupBuilder group) | ||
{ | ||
group.MapPost("/{userId:guid}/generated/complete", ActivateAccountAsync) | ||
.Produces(StatusCodes.Status200OK) | ||
.ProducesProblem(StatusCodes.Status400BadRequest) | ||
.ProducesProblem(StatusCodes.Status404NotFound) | ||
.WithName(nameof(CompleteRegistrationEndpoint)) | ||
.MapToApiVersion(1); | ||
} | ||
|
||
private async Task<IResult> ActivateAccountAsync( | ||
[FromRoute] Guid userId, | ||
[FromHeader(Name = UserConstants.HTTP_HEADER_PASSWORD)] string password, | ||
[FromServices] ISender sender, | ||
CancellationToken ct) | ||
{ | ||
var command = new CompleteRegistrationCommand | ||
{ | ||
UserId = UserId.FromGuid(userId), | ||
Password = password | ||
}; | ||
|
||
var result = await sender.Send(command, ct); | ||
return result.ToResponse(TypedResults.Ok); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Modules/UserAccess/TeamUp.UserAccess.Infrastructure/Services/ClientUrlGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using Microsoft.Extensions.Options; | ||
|
||
using TeamUp.Common.Infrastructure.Options; | ||
using TeamUp.UserAccess.Contracts; | ||
using TeamUp.UserAccess.Domain; | ||
|
||
namespace TeamUp.UserAccess.Infrastructure.Services; | ||
|
||
internal sealed class ClientUrlGenerator : IClientUrlGenerator | ||
{ | ||
private readonly ClientOptions _options; | ||
|
||
public ClientUrlGenerator(IOptions<ClientOptions> options) | ||
{ | ||
_options = options.Value; | ||
} | ||
|
||
public string GetActivationUrl(UserId userId) => | ||
string.Format(_options.ActivateAccountUrl, _options.Url, userId.Value); | ||
|
||
public string GetCompleteAccountRegistrationUrl(UserId userId) => | ||
string.Format(_options.CompleteAccountRegistrationUrl, _options.Url, userId.Value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.