Skip to content

Commit

Permalink
Verify that user in tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
davidreneuw committed Feb 13, 2025
1 parent 0886d0e commit bdf3c37
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public interface IUserInformationService
Task<bool> UpdatePortalUserAsync(PortalUser updatedUser);
public event EventHandler<PortalUserUpdatedEventArgs> PortalUserUpdated;
Task<bool> IsDailyLogin();
Task<bool> CheckUserInTenant(string email);
}

public static class UserInformationServiceConstants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,9 @@ public Task<bool> IsDailyLogin()
{
return Task.FromResult(false);
}

public Task<bool> CheckUserInTenant(string email)
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,13 @@ public async Task<PortalUser> GetPortalUserWithAchievementsAsync(string userGrap

return portalUser;
}

public async Task<bool> CheckUserInTenant(string email)
{
PrepareAuthenticatedClient();
var users = await graphServiceClient.Users.GetAsync(
test => test.QueryParameters.Filter = $"mail eq '{email}'");
if (users?.Value != null) return users.Value.Count > 0;
return false;
}
}
18 changes: 15 additions & 3 deletions Portal/src/Datahub.Portal/Pages/Public/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,34 @@
_loggingIn = true;
var loginHint = loginModel.Email;
var existingUser = await _userInformationService.GetPortalUserByEmailAsync(loginHint);

// If user is deleted, redirect to register page with deleted flag
if (existingUser is { IsDeleted: true })
{
_navigationManager.NavigateTo($"{Localizer["/register"]}?email={loginHint}&s=d");
return;
}

// If user is locked, redirect to locked page
if (existingUser is { IsLocked: true })
{
_navigationManager.NavigateTo(Localizer["/locked"]);
return;
}


// If there is no portal user associated with the email, then:
if (existingUser is null)
{
_navigationManager.NavigateTo($"{Localizer["/register"]}?email={loginHint}&s=n");
return;
// - first check if the user is registered in the tenant (that means they have registered but not logged in yet)
var registered = await _userInformationService.CheckUserInTenant(loginHint);

// - if not registered, redirect to register page with new flag
if (!registered)
{
_navigationManager.NavigateTo($"{Localizer["/register"]}?email={loginHint}&s=n");
return;
}
// - if they are registered, proceed with the normal login flow
}

if (string.IsNullOrWhiteSpace(redirectUri))
Expand Down

0 comments on commit bdf3c37

Please sign in to comment.