|
|
|
@ -1,18 +1,37 @@ |
|
|
|
using System.Threading.Tasks; |
|
|
|
using System; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using MyCompanyName.MyProjectName.Localization; |
|
|
|
using Volo.Abp.Account.Localization; |
|
|
|
using Volo.Abp.UI.Navigation; |
|
|
|
using Volo.Abp.Users; |
|
|
|
|
|
|
|
namespace MyCompanyName.MyProjectName.Blazor |
|
|
|
{ |
|
|
|
public class MyProjectNameMenuContributor : IMenuContributor |
|
|
|
{ |
|
|
|
public Task ConfigureMenuAsync(MenuConfigurationContext context) |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
|
|
|
public MyProjectNameMenuContributor(IConfiguration configuration) |
|
|
|
{ |
|
|
|
if(context.Menu.DisplayName != StandardMenus.Main) |
|
|
|
_configuration = configuration; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task ConfigureMenuAsync(MenuConfigurationContext context) |
|
|
|
{ |
|
|
|
if (context.Menu.Name == StandardMenus.Main) |
|
|
|
{ |
|
|
|
return Task.CompletedTask; |
|
|
|
await ConfigureMainMenuAsync(context); |
|
|
|
} |
|
|
|
else if (context.Menu.Name == StandardMenus.User) |
|
|
|
{ |
|
|
|
await ConfigureUserMenuAsync(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private Task ConfigureMainMenuAsync(MenuConfigurationContext context) |
|
|
|
{ |
|
|
|
var l = context.GetLocalizer<MyProjectNameResource>(); |
|
|
|
|
|
|
|
context.Menu.Items.Insert( |
|
|
|
@ -27,5 +46,27 @@ namespace MyCompanyName.MyProjectName.Blazor |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
|
|
|
|
private Task ConfigureUserMenuAsync(MenuConfigurationContext context) |
|
|
|
{ |
|
|
|
var accountStringLocalizer = context.GetLocalizer<AccountResource>(); |
|
|
|
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>(); |
|
|
|
|
|
|
|
var identityServerUrl = _configuration["AuthServer:Authority"] ?? ""; |
|
|
|
|
|
|
|
if (currentUser.IsAuthenticated) |
|
|
|
{ |
|
|
|
context.Menu.AddItem(new ApplicationMenuItem( |
|
|
|
"Account.Manage", |
|
|
|
accountStringLocalizer["ManageYourProfile"], |
|
|
|
$"{identityServerUrl.EnsureEndsWith('/')}Account/Manage", |
|
|
|
icon: "fa fa-cog", |
|
|
|
order: 1000, |
|
|
|
null, |
|
|
|
"_blank")); |
|
|
|
} |
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|