first commit -push
This commit is contained in:
29
RobotNet.IdentityServer/Components/Layout/MainLayout.razor
Normal file
29
RobotNet.IdentityServer/Components/Layout/MainLayout.razor
Normal file
@@ -0,0 +1,29 @@
|
||||
@using MudBlazor
|
||||
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<MudThemeProvider />
|
||||
<MudPopoverProvider @rendermode="InteractiveServer" />
|
||||
|
||||
|
||||
<div class="page">
|
||||
<div class="sidebar-container">
|
||||
<div class="sidebar">
|
||||
<NavMenu />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<main>
|
||||
<article class="content px-2">
|
||||
@Body
|
||||
</article>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<div id="blazor-error-ui" data-nosnippet>
|
||||
An unhandled error has occurred.
|
||||
<a href="." class="reload">Reload</a>
|
||||
<span class="dismiss">🗙</span>
|
||||
</div>
|
||||
123
RobotNet.IdentityServer/Components/Layout/MainLayout.razor.css
Normal file
123
RobotNet.IdentityServer/Components/Layout/MainLayout.razor.css
Normal file
@@ -0,0 +1,123 @@
|
||||
.page {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-color: #f7f7f7;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.content px-2{
|
||||
overflow:hidden;
|
||||
}
|
||||
main {
|
||||
flex: 1;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.sidebar-container {
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
|
||||
border-radius: 15px;
|
||||
box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.3);
|
||||
transform: translateX(5px);
|
||||
}
|
||||
|
||||
.top-row {
|
||||
background-color: #f7f7f7;
|
||||
border-bottom: 1px solid #d6d5d5;
|
||||
justify-content: flex-end;
|
||||
height: 3.5rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.top-row ::deep a, .top-row ::deep .btn-link {
|
||||
white-space: nowrap;
|
||||
margin-left: 1.5rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.top-row ::deep a:first-child {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
@media (max-width: 640.98px) {
|
||||
.top-row {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.top-row ::deep a, .top-row ::deep .btn-link {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
margin-left: 0;
|
||||
width: 80%;
|
||||
max-width: 250px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 641px) {
|
||||
.page {
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.sidebar-container {
|
||||
width: 280px;
|
||||
height: 100vh;
|
||||
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
width: 270px;
|
||||
height: calc(100vh - 20px);
|
||||
position: fixed;
|
||||
top:10px;
|
||||
}
|
||||
|
||||
.top-row {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.top-row.auth ::deep a:first-child {
|
||||
flex: 1;
|
||||
text-align: right;
|
||||
width: 0;
|
||||
}
|
||||
|
||||
.top-row, article {
|
||||
padding-left: 0.75rem !important;
|
||||
padding-right: 0.75rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
#blazor-error-ui {
|
||||
color-scheme: light only;
|
||||
background: lightyellow;
|
||||
bottom: 0;
|
||||
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
|
||||
box-sizing: border-box;
|
||||
display: none;
|
||||
left: 0;
|
||||
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
#blazor-error-ui .dismiss {
|
||||
cursor: pointer;
|
||||
position: absolute;
|
||||
right: 0.75rem;
|
||||
top: 0.5rem;
|
||||
}
|
||||
214
RobotNet.IdentityServer/Components/Layout/NavMenu.razor
Normal file
214
RobotNet.IdentityServer/Components/Layout/NavMenu.razor
Normal file
@@ -0,0 +1,214 @@
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using RobotNet.IdentityServer.Data
|
||||
@using MudBlazor
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Components
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using System.Threading
|
||||
@using RobotNet.IdentityServer.Services
|
||||
@using System.Security.Claims
|
||||
|
||||
@implements IDisposable
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
@inject RobotNet.IdentityServer.Services.IdentityService IdentityService
|
||||
@inject RobotNet.IdentityServer.Services.UserInfoService UserInfoService
|
||||
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
@inject RoleManager<ApplicationRole> RoleManager
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="top-row px-4 py-3 bg-gradient-to-r from-blue-400 to-purple-500 flex items-center">
|
||||
<a class="navbar-brand text-white font-bold text-lg" href="">User Management</a>
|
||||
<button class="navbar-toggler md:hidden">
|
||||
<span class="mdi mdi-menu text-white text-2xl"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="nav-scrollable">
|
||||
<nav class="nav flex-column p-2 space-y-2">
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="nav-item">
|
||||
<NavLink class="nav-link flex items-center space-x-3 text-gray-200 hover:bg-blue-500/20 rounded-lg p-2 transition-all duration-300" href="Account/Usermanager">
|
||||
<span class="mdi mdi-account-cog text-xl"></span>
|
||||
<span class="text-nav">User Info Management</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
<AuthorizeView Roles="Administrator">
|
||||
<Authorized>
|
||||
<div class="nav-item">
|
||||
<NavLink class="nav-link flex items-center space-x-3 text-gray-200 hover:bg-blue-500/20 rounded-lg p-2 transition-all duration-300" href="Account/Rolemanager">
|
||||
<span class="mdi mdi-account-cog text-xl"></span>
|
||||
<span class="text-nav">Role Manager</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item">
|
||||
<NavLink class="nav-link flex items-center space-x-3 text-gray-200 hover:bg-blue-500/20 rounded-lg p-2 transition-all duration-300" href="/Account/OpenIdDictManager">
|
||||
<span class="mdi mdi-database-import-outline text-xl"></span>
|
||||
<span class="text-nav">OpenIdDict</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView>
|
||||
|
||||
<NotAuthorized>
|
||||
<div class="nav-item">
|
||||
<NavLink class="nav-link flex items-center space-x-3 text-gray-200 hover:bg-blue-500/20 rounded-lg p-2 transition-all duration-300" href="Account/Login">
|
||||
<span class="mdi mdi-account-arrow-right text-xl"></span>
|
||||
<span class="text-nav">Login</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
<div class="nav-item">
|
||||
<NavLink class="nav-link flex items-center space-x-3 text-gray-200 hover:bg-blue-500/20 rounded-lg p-2 transition-all duration-300" href="Account/Register">
|
||||
<span class="mdi mdi-account-plus text-xl"></span>
|
||||
<span class="text-nav">Register</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
</NotAuthorized>
|
||||
</AuthorizeView>
|
||||
</nav>
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="user-profile mt-auto">
|
||||
<div class="user-profile-inner">
|
||||
<div class="avatar">
|
||||
@if (string.IsNullOrEmpty(userImageUrl))
|
||||
{
|
||||
<div class="avatar-placeholder">
|
||||
<span class="mdi mdi-account text-3xl"></span>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<img src="@userImageUrl" alt="User Avatar" class="avatar-image" />
|
||||
}
|
||||
</div>
|
||||
<div class="user-info">
|
||||
<div class="username">@userName</div>
|
||||
<div class="user-email">@userEmail</div>
|
||||
</div>
|
||||
<form action="Account/Logout" method="post" class="logout-form">
|
||||
<AntiforgeryToken />
|
||||
<input type="hidden" name="ReturnUrl" value="@currentUrl" />
|
||||
<button type="submit" class="logout-button" title="Logout">
|
||||
<span class=" mdi mdi-account-arrow-left text-xl"></span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
@code {
|
||||
private Func<Task>? _userInfoChangedHandler;
|
||||
private string cacheBuster = "";
|
||||
private string? currentUrl;
|
||||
private ApplicationUser? currentUser;
|
||||
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
private string userName = string.Empty;
|
||||
private string userEmail = string.Empty;
|
||||
private string userImageUrl = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
|
||||
currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
|
||||
NavigationManager.LocationChanged += OnLocationChanged;
|
||||
|
||||
_userInfoChangedHandler = async () =>
|
||||
{
|
||||
await InvokeAsync(async () =>
|
||||
{
|
||||
await LoadUserInfoAsync();
|
||||
StateHasChanged();
|
||||
});
|
||||
};
|
||||
UserInfoService.RegisterHandler(_userInfoChangedHandler);
|
||||
await LoadUserInfoAsync();
|
||||
}
|
||||
|
||||
private async Task UserInfoChangedHandler()
|
||||
{
|
||||
await LoadUserInfoAsync();
|
||||
|
||||
|
||||
await InvokeAsync(() =>
|
||||
{
|
||||
cacheBuster = $"?v={DateTime.Now.Ticks}";
|
||||
StateHasChanged();
|
||||
});
|
||||
}
|
||||
|
||||
private async Task LoadUserInfoAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
|
||||
if (user?.Identity?.IsAuthenticated == true)
|
||||
{
|
||||
var userId = user.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
|
||||
currentUser = await IdentityService.GetUserByIdAsync(userId);
|
||||
if (currentUser != null)
|
||||
{
|
||||
userName = currentUser.UserName ?? string.Empty; ;
|
||||
userEmail = currentUser.Email ?? string.Empty; ;
|
||||
|
||||
if (currentUser.AvatarImage != null)
|
||||
{
|
||||
|
||||
userImageUrl = $"data:{currentUser.AvatarContentType ?? "image/jpeg"};base64,{Convert.ToBase64String(currentUser.AvatarImage)}";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
userImageUrl = "/uploads/avatars/anh.jpg";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Error loading user info: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
||||
{
|
||||
InvokeAsync(() =>
|
||||
{
|
||||
currentUrl = NavigationManager.ToBaseRelativePath(e.Location);
|
||||
StateHasChanged();
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
NavigationManager.LocationChanged -= OnLocationChanged;
|
||||
|
||||
if (UserInfoService != null && _userInfoChangedHandler != null)
|
||||
{
|
||||
UserInfoService.UnregisterHandler(_userInfoChangedHandler);
|
||||
}
|
||||
}
|
||||
}
|
||||
202
RobotNet.IdentityServer/Components/Layout/NavMenu.razor.css
Normal file
202
RobotNet.IdentityServer/Components/Layout/NavMenu.razor.css
Normal file
@@ -0,0 +1,202 @@
|
||||
.navbar-toggler {
|
||||
appearance: none;
|
||||
cursor: pointer;
|
||||
width: 3.5rem;
|
||||
height: 2.5rem;
|
||||
color: turquoise;
|
||||
position: absolute;
|
||||
top: 0.5rem;
|
||||
right: 1rem;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.navbar-toggler:checked {
|
||||
background-color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
.top-row {
|
||||
min-height: 3.5rem;
|
||||
background-color: rgba(0,0,0,0.1);
|
||||
border-radius: 15px 15px 0 0;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
|
||||
.mdi {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
font-size: 26px;
|
||||
background-size: cover;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
font-size: 1.05rem;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.nav-item:first-of-type {
|
||||
padding-top: 0.5rem;
|
||||
}
|
||||
|
||||
.nav-item:last-of-type {
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.nav-item ::deep .nav-link {
|
||||
color: #4a5568;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
height: 3rem;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
line-height: 3rem;
|
||||
width: 100%;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-item ::deep a.active {
|
||||
background-color: rgba(79, 70, 229, 0.2);
|
||||
color: #4338ca;
|
||||
}
|
||||
|
||||
.nav-item ::deep .nav-link:hover {
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
color: #4338ca;
|
||||
}
|
||||
.text-nav {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
.nav-scrollable {
|
||||
display: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: calc(100% - 3.5rem);
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
}
|
||||
|
||||
|
||||
|
||||
.navbar-toggler:checked ~ .nav-scrollable {
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
||||
.user-profile {
|
||||
margin-top: auto;
|
||||
padding: 1rem;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.1);
|
||||
background-color: #e8f0fe;
|
||||
border-radius: 0 0 15px 15px;
|
||||
}
|
||||
|
||||
.user-profile-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0.5rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
min-width: 40px;
|
||||
min-height: 40px;
|
||||
max-width: 40px;
|
||||
max-height: 40px;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
margin-right: 0.75rem;
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.avatar-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: #4a5568;
|
||||
}
|
||||
|
||||
.avatar-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
object-position: center;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.username {
|
||||
color: #4a5568;
|
||||
font-weight: 500;
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.user-email {
|
||||
color: #718096;
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.2;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 150px;
|
||||
}
|
||||
|
||||
.logout-form {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.logout-button {
|
||||
background: none;
|
||||
border: none;
|
||||
color: #718096;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.logout-button:hover {
|
||||
background-color: rgba(79, 70, 229, 0.1);
|
||||
color: #4338ca;
|
||||
}
|
||||
|
||||
@media (min-width: 641px) {
|
||||
.navbar-toggler {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-scrollable {
|
||||
/* Never collapse the sidebar for wide screens */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
/* Allow sidebar to scroll for tall menus */
|
||||
height: calc(100% - 3.5rem);
|
||||
overflow-y: auto;
|
||||
border-radius: 0 0 15px 15px;
|
||||
background: #e8f0fe;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user