-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for database context allowing post authentication to upsert user
1 parent
704b078
commit ef0babe
Showing
10 changed files
with
92 additions
and
103 deletions.
There are no files selected for viewing
33 changes: 16 additions & 17 deletions
33
src/SFA.DAS.EmployerFinance.Web/App_Start/FilterConfig.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 |
---|---|---|
@@ -1,19 +1,18 @@ | ||
using System.Web.Mvc; | ||
using SFA.DAS.Authorization.Mvc.Extensions; | ||
using SFA.DAS.EmployerFinance.Web.Filters; | ||
using System.Web.Mvc; | ||
using SFA.DAS.Authorization.Mvc.Extensions; | ||
using SFA.DAS.EmployerFinance.Web.Filters; | ||
using SFA.DAS.UnitOfWork.Mvc.Extensions; | ||
|
||
namespace SFA.DAS.EmployerFinance.Web | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.AddUnitOfWorkFilter(); | ||
filters.AddAuthorizationFilter(); | ||
filters.AddUnauthorizedAccessExceptionFilter(); | ||
filters.Add(new AnalyticsFilter()); | ||
filters.Add(new UpsertUserFilter()); | ||
} | ||
} | ||
} | ||
namespace SFA.DAS.EmployerFinance.Web | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.AddUnitOfWorkFilter(); | ||
filters.AddAuthorizationFilter(); | ||
filters.AddUnauthorizedAccessExceptionFilter(); | ||
filters.Add(new AnalyticsFilter()); | ||
} | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
src/SFA.DAS.EmployerFinance.Web/Filters/UpsertUserFilter.cs
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
src/SFA.DAS.EmployerFinance.Web/Orchestrators/AuthenticationOrchestrator.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,31 @@ | ||
using MediatR; | ||
using SFA.DAS.EmployerFinance.Commands.UpsertRegisteredUser; | ||
using SFA.DAS.NLog.Logger; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerFinance.Web.Orchestrators | ||
{ | ||
public class AuthenticationOrchestrator | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public AuthenticationOrchestrator(IMediator mediator) | ||
{ | ||
if (mediator == null) | ||
throw new ArgumentNullException(nameof(mediator)); | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task SaveIdentityAttributes(string userRef, string email, string firstName, string lastName) | ||
{ | ||
await _mediator.SendAsync(new UpsertRegisteredUserCommand | ||
{ | ||
EmailAddress = email, | ||
UserRef = userRef, | ||
LastName = lastName, | ||
FirstName = firstName | ||
}); | ||
} | ||
} | ||
} |
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
16 changes: 11 additions & 5 deletions
16
...A.DAS.EmployerFinance/Commands/UpsertRegisteredUser/UpsertRegisteredUserCommandHandler.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 |
---|---|---|
@@ -1,39 +1,45 @@ | ||
using MediatR; | ||
using SFA.DAS.EmployerFinance.Data; | ||
using SFA.DAS.EmployerFinance.Models.UserProfile; | ||
using SFA.DAS.NLog.Logger; | ||
using SFA.DAS.Validation; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerFinance.Commands.UpsertRegisteredUser | ||
{ | ||
public class UpsertRegisteredUserCommandHandler : RequestHandler<UpsertRegisteredUserCommand> | ||
public class UpsertRegisteredUserCommandHandler : AsyncRequestHandler<UpsertRegisteredUserCommand> | ||
{ | ||
private readonly IValidator<UpsertRegisteredUserCommand> _validator; | ||
private readonly IUserAccountRepository _userRepository; | ||
private readonly ILog _logger; | ||
private readonly IUserRepository _userRepository; | ||
|
||
public UpsertRegisteredUserCommandHandler( | ||
IValidator<UpsertRegisteredUserCommand> validator, | ||
IUserAccountRepository userRepository) | ||
ILog logger, | ||
IUserRepository userRepository) | ||
{ | ||
_validator = validator; | ||
_logger = logger; | ||
_userRepository = userRepository; | ||
} | ||
|
||
protected override void HandleCore(UpsertRegisteredUserCommand message) | ||
protected override async Task HandleCore(UpsertRegisteredUserCommand message) | ||
{ | ||
var validationResult = _validator.Validate(message); | ||
|
||
if (!validationResult.IsValid()) throw new InvalidRequestException(validationResult.ValidationDictionary); | ||
|
||
_userRepository.Upsert(new User | ||
await _userRepository.Upsert(new User | ||
{ | ||
Ref = new Guid(message.UserRef), | ||
Email = message.EmailAddress, | ||
FirstName = message.FirstName, | ||
LastName = message.LastName, | ||
CorrelationId = message.CorrelationId | ||
}); | ||
|
||
_logger.Info($"Upserted user with email={message.EmailAddress}, userRef={message.UserRef}, lastName={message.LastName}, firstName={message.FirstName}"); | ||
} | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
...yerFinance/Data/IUserAccountRepository.cs → ...S.EmployerFinance/Data/IUserRepository.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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
using SFA.DAS.EmployerFinance.Models.UserProfile; | ||
using System.Threading.Tasks; | ||
|
||
namespace SFA.DAS.EmployerFinance.Data | ||
{ | ||
public interface IUserAccountRepository | ||
public interface IUserRepository | ||
{ | ||
void Upsert(User user); | ||
Task Upsert(User user); | ||
} | ||
} |
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