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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using APIViewWeb.Repositories;
using APIViewWeb.Models;


namespace APIViewWeb.Controllers
{
[AllowAnonymous]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IUserProfileManager
public Task<UserProfileModel> TryGetUserProfileByNameAsync(string UserName);
public Task UpdateUserPreferences(ClaimsPrincipal User, UserPreferenceModel preferences);
public Task UpdateUserProfile(ClaimsPrincipal User, string email, HashSet<string> languages, UserPreferenceModel preferences);
public Task SetUserEmailIfNullOrEmpty(ClaimsPrincipal User);
}
}
18 changes: 17 additions & 1 deletion src/dotnet/APIView/APIViewWeb/Managers/UserProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using APIView.Identity;
using APIViewWeb.Models;
using APIViewWeb.Repositories;
using Microsoft.AspNetCore.Authorization;
using Octokit;

namespace APIViewWeb.Managers
{
Expand Down Expand Up @@ -62,5 +63,20 @@ public async Task UpdateUserProfile(ClaimsPrincipal User, string email, HashSet<

await _UserProfileRepository.UpsertUserProfileAsync(User, UserProfile);
}

public async Task SetUserEmailIfNullOrEmpty(ClaimsPrincipal User)
{
var UserProfile = await TryGetUserProfileAsync(User);

if (string.IsNullOrWhiteSpace(UserProfile.Email))
{
var microsoftEmail = User.Claims.FirstOrDefault(c => c.Type == ClaimConstants.Email)?.Value;

if (!string.IsNullOrWhiteSpace(microsoftEmail))
{
await UpdateUserProfile(User, microsoftEmail, null, null);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public async Task OnGetAsync(
IEnumerable<string> search, IEnumerable<string> languages, IEnumerable<string> state,
IEnumerable<string> status, int pageNo=1, int pageSize=_defaultPageSize, string sortField=_defaultSortField)
{
await _userProfileManager.SetUserEmailIfNullOrEmpty(User);

if (!search.Any() && !languages.Any() && !state.Any() && !status.Any())
{
UserPreferenceModel userPreference = await _preferenceCache.GetUserPreferences(User);
Expand Down
4 changes: 2 additions & 2 deletions src/dotnet/APIView/APIViewWeb/Pages/Login.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

Expand All @@ -17,4 +17,4 @@ public IActionResult OnGetAsync()
return Page();
}
}
}
}