Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions LearningHub.Nhs.UserApi.Repository.Interface/LH/IUserRepository.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace LearningHub.Nhs.UserApi.Repository.Interface.LH
{
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Common;
using elfhHub.Nhs.Models.Dto;
using LearningHub.Nhs.Models.Entities;

/// <summary>
Expand All @@ -20,38 +18,5 @@ public interface IUserRepository : IGenericLHRepository<User>
/// The <see cref="Task"/>.
/// </returns>
Task<User> GetByIdAsync(int id);

/// <summary>
/// The get user id by username async.
/// </summary>
/// <param name="username">
/// The username.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<int> GetUserIdByUsernameAsync(string username);

/// <summary>
/// The get by open athens id.
/// </summary>
/// <param name="openAthensId">
/// The open athens id.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId);

/// <summary>
/// The get user detail for the authentication.
/// </summary>
/// <param name = "username">
/// username.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
Task<UserAuthenticateDto> GetUserDetailForAuthentication(string username);
}
}
6 changes: 0 additions & 6 deletions LearningHub.Nhs.UserApi.Repository/LH/LearningHubDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace LearningHub.Nhs.UserApi.Repository.LH
{
using elfhHub.Nhs.Models.Dto;
using LearningHub.Nhs.Models.Entities;
using LearningHub.Nhs.Models.Entities.External;
using LearningHub.Nhs.Models.Entities.Messaging;
Expand Down Expand Up @@ -51,11 +50,6 @@ public LearningHubDbContext(LearningHubDbContextOptions options)
/// </summary>
public virtual DbSet<EmailTemplate> EmailTemplate { get; set; }

/// <summary>
/// Gets or sets the UserAuthentiate Dto.
/// </summary>
public virtual DbSet<UserAuthenticateDto> UserAuthenticateDto { get; set; }

/// <summary>
/// The on model creating.
/// </summary>
Expand Down
40 changes: 0 additions & 40 deletions LearningHub.Nhs.UserApi.Repository/LH/UserRepository.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
namespace LearningHub.Nhs.UserApi.Repository.LH
{
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using elfhHub.Nhs.Models.Common;
using elfhHub.Nhs.Models.Dto;
using LearningHub.Nhs.Models.Entities;
using LearningHub.Nhs.UserApi.Repository;
using LearningHub.Nhs.UserApi.Repository.Interface.LH;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

/// <summary>
Expand All @@ -31,40 +26,5 @@ public async Task<User> GetByIdAsync(int id)
{
return await this.DbContext.User.FirstOrDefaultWithNoLockAsync(n => n.Id == id);
}

/// <inheritdoc/>
public async Task<int> GetUserIdByUsernameAsync(string username)
{
return await this.DbContext.User.AsNoTracking().Where(n => n.UserName == username).Select(n => n.Id).FirstOrDefaultWithNoLockAsync();
}

/// <inheritdoc/>
public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
{
var param = new SqlParameter("@OpenAthensId", openAthensId);

return await this.DbContext.Set<UserBasic>()
.FromSqlRaw("EXEC elfh.proc_GetUserByOpenAthensId @OpenAthensId", param)
.AsNoTracking()
.FirstOrDefaultAsync();
}

/// <summary>
/// The get user detail for the authentication.
/// </summary>
/// <param name = "username">
/// username.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
public async Task<UserAuthenticateDto> GetUserDetailForAuthentication(string username)
{
var param0 = new SqlParameter("@userName", SqlDbType.VarChar) { Value = username };

var userAuthenticateDto = await this.DbContext.UserAuthenticateDto.FromSqlRaw("elfh.proc_UserDetailForAuthenticationByUserName @userName", param0).AsNoTracking().ToListAsync();

return userAuthenticateDto.FirstOrDefault();
}
}
}
37 changes: 20 additions & 17 deletions LearningHub.Nhs.UserApi.Services/ElfhUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,14 @@ public async Task<UserBasic> GetByOpenAthensIdAsync(string openAthensId)
return null;
}

var user = await this.lhUserRepository.GetByOpenAthensIdAsync(openAthensId);
var user = await this.elfhUserRepository.GetByOpenAthensIdAsync(openAthensId);

// if (user != null)
// {
// await this.SyncLHUserAsync(user.Id, user.UserName);
// }
return user;
if (user != null)
{
await this.SyncLHUserAsync(user.Id, user.UserName);
}

return user?.ToBasicUser();
}

/// <inheritdoc/>
Expand All @@ -180,13 +181,13 @@ public async Task<User> GetByUsernameAsync(string userName, UserIncludeCollectio
/// <returns>The <see cref="Task"/>.</returns>
public async Task<int> GetUserIdByUsernameAsync(string userName)
{
return await this.lhUserRepository.GetUserIdByUsernameAsync(userName);
return await this.elfhUserRepository.GetUserIdByUsernameAsync(userName);
}

/// <inheritdoc/>
public async Task<UserAuthenticateDto> GetUserDetailForAuthenticateAsync(string userName)
{
return await this.lhUserRepository.GetUserDetailForAuthentication(userName);
return await this.elfhUserRepository.GetUserDetailForAuthentication(userName);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -228,14 +229,14 @@ public async Task<string> GetUserRoleAsync(int id)
/// <inheritdoc/>
public async Task RecordSuccessfulSigninAsync(int id, CancellationToken token = default)
{
var user = await this.lhUserRepository.GetByIdAsync(id);
var user = await this.elfhUserRepository.GetByIdAsync(id);

if (user.PasswordLifeCounter != 0 || user.SecurityLifeCounter != 0)
{
user.PasswordLifeCounter = 0;
user.SecurityLifeCounter = 0;

await this.lhUserRepository.UpdateAsync(id, user);
await this.elfhUserRepository.UpdateAsync(id, user);

await this.InvalidateElfhUserCacheAsync(user.Id, user.UserName, token);
}
Expand All @@ -244,11 +245,11 @@ public async Task RecordSuccessfulSigninAsync(int id, CancellationToken token =
/// <inheritdoc/>
public async Task RecordUnsuccessfulSigninAsync(int id, CancellationToken token = default)
{
var user = await this.lhUserRepository.GetByIdAsync(id);
var user = await this.elfhUserRepository.GetByIdAsync(id);

user.PasswordLifeCounter++;

await this.lhUserRepository.UpdateAsync(id, user);
await this.elfhUserRepository.UpdateAsync(id, user);

await this.InvalidateElfhUserCacheAsync(user.Id, user.UserName, token);
}
Expand Down Expand Up @@ -958,14 +959,14 @@ public async Task<bool> ValidateUserRoleUpgrade(string currentPrimaryEmail, stri
/// <inheritdoc/>
public async Task<bool> CheckSamePrimaryemailIsPendingToValidate(string secondaryEmail, int currentUserId)
{
var userRoleUpgrades = this.userRoleUpgradeRepository.GetByEmailAddressAsync(secondaryEmail, currentUserId);
var userRoleUpgrades = this.userRoleUpgradeRepository.GetByEmailAddressAsync(secondaryEmail, currentUserId);

if (userRoleUpgrades.Count() > 0)
{
if (userRoleUpgrades.Count() > 0)
{
return true;
}
}

return false;
return false;
}

/// <summary>
Expand All @@ -977,6 +978,8 @@ public async Task<bool> CheckSamePrimaryemailIsPendingToValidate(string secondar
public async Task UpdateMyAccountPersonalDetails(PersonalDetailsViewModel personalDetailsViewModel, int currentUserId)
{
User user = await this.elfhUserRepository.GetByIdAsync(personalDetailsViewModel.UserId);
user.FirstName = personalDetailsViewModel.FirstName;
user.LastName = personalDetailsViewModel.LastName;
user.PreferredName = personalDetailsViewModel.PreferredName;
user.AltEmailAddress = personalDetailsViewModel.SecondaryEmailAddress;

Expand Down
18 changes: 10 additions & 8 deletions LearningHub.Nhs.UserApi/Controllers/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ public async Task<IActionResult> AuthenticateElfhHubAsync([FromBody] Login login
{
var loginResult = await this.authenticationService.AuthenticateAsync(login);

// if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
// {
// await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
// }
if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
{
await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
}

return this.Ok(loginResult);
}

Expand All @@ -80,10 +81,11 @@ public async Task<IActionResult> AuthenticateSsoAsync([FromBody] LoginSso reques

var loginResult = await this.authenticationService.CheckUserCredentialsSsoAsync(request.UserId);

// if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
// {
// await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
// }
if (loginResult.IsAuthenticated && !string.IsNullOrWhiteSpace(loginResult.UserName))
{
await this.elfhUserService.SyncLHUserAsync(loginResult.UserId, loginResult.UserName);
}

return this.Ok(loginResult);
}

Expand Down
Loading