diff --git a/SharpRSS.Blazor/Components/Pages/Auth/Login.razor b/SharpRSS.Blazor/Components/Pages/Auth/Login.razor new file mode 100644 index 0000000..9ae2b97 --- /dev/null +++ b/SharpRSS.Blazor/Components/Pages/Auth/Login.razor @@ -0,0 +1,18 @@ +@page "/Auth/Login" +@using SharpRSS.Blazor.Extensions +@inject NavigationManager NavigationManager +@attribute [AllowAnonymous] + +Login | SharpRSS + +@code { + + private string RedirectAfterLogin { get; set; } = string.Empty; + + protected override Task OnInitializedAsync() + { + RedirectAfterLogin = NavigationManager.GetQueryParameters().TryGetValue("RedirectUrl", out var redirectUrl) ? redirectUrl.ToString() : string.Empty; + //TODO: Checking based auth or external (OIDC, etc.) + return base.OnInitializedAsync(); + } +} \ No newline at end of file diff --git a/SharpRSS.Blazor/Components/Redirector.razor b/SharpRSS.Blazor/Components/Redirector.razor new file mode 100644 index 0000000..7f59098 --- /dev/null +++ b/SharpRSS.Blazor/Components/Redirector.razor @@ -0,0 +1,29 @@ +@inject NavigationManager NavigationManager + +Redirecting... + + + + + + +@code { + + [CascadingParameter] + private Task AuthStateTask { get; set; } = null!; + [Parameter] + [EditorRequired] + public string RedirectUri { get; set; } + private bool _isAuthenticated; + + protected override async Task OnInitializedAsync() + { + var authState = await AuthStateTask; + if (authState.User.Identity != null) _isAuthenticated = authState.User.Identity.IsAuthenticated; + + NavigationManager.NavigateTo(RedirectUri); + + await base.OnInitializedAsync(); + } + +} \ No newline at end of file diff --git a/SharpRSS.Blazor/Components/Routes.razor b/SharpRSS.Blazor/Components/Routes.razor index a977289..0705dc9 100644 --- a/SharpRSS.Blazor/Components/Routes.razor +++ b/SharpRSS.Blazor/Components/Routes.razor @@ -1,13 +1,23 @@ - - - - - - - - @*TODO: Manage not found*@ - Not found! - Page not found! - - - \ No newline at end of file + + + + @* + *@ + + + Determining session state, please wait... + + + + + + + + + @*TODO: Manage not found*@ + Not found! + Page not found! + + + + \ No newline at end of file diff --git a/SharpRSS.Blazor/Extensions/NavigationManagerExtensions.cs b/SharpRSS.Blazor/Extensions/NavigationManagerExtensions.cs new file mode 100644 index 0000000..5721a4e --- /dev/null +++ b/SharpRSS.Blazor/Extensions/NavigationManagerExtensions.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.WebUtilities; +using Microsoft.Extensions.Primitives; + +namespace SharpRSS.Blazor.Extensions; + +public static class NavigationManagerExtensions +{ + public static Dictionary GetQueryParameters(this NavigationManager navigationManager) + { + var uri = navigationManager.ToAbsoluteUri(navigationManager.Uri); + return QueryHelpers.ParseQuery(uri.Query); + } +} \ No newline at end of file diff --git a/SharpRSS.Blazor/Program.cs b/SharpRSS.Blazor/Program.cs index f9dd1d9..9ea8342 100644 --- a/SharpRSS.Blazor/Program.cs +++ b/SharpRSS.Blazor/Program.cs @@ -23,8 +23,10 @@ builder.Services.AddBasedServerAuth(options => options.LogoutPath = "/auth/logout"; options.SeedData = service => { - /*service.CreateUserAsync(new UserModel() { UserName = "Admin", Email = "admin@example.com", Enabled = true, PasswordHash = "password", Roles = new List() { new RoleModel() { Name = "Admin", Description = "Administration role." }}}); - service.CreateUserAsync(new UserModel() { UserName = "User", Email = "user@example.com", Enabled = true, PasswordHash = "password"});*/ + service.CreateUserAsync(new UserModel() { UserName = "Admin", Email = "admin@example.com", Enabled = true, PasswordHash = "password", Roles = + [new RoleModel { Name = "Admin", Description = "Administration role." }] + }); + service.CreateUserAsync(new UserModel() { UserName = "User", Email = "user@example.com", Enabled = true, PasswordHash = "password"}); }; options.SetDataRepositoryType(); options.SetSessionStateProviderType(); diff --git a/SharpRSS.Blazor/SRSS.db-shm b/SharpRSS.Blazor/SRSS.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/SharpRSS.Blazor/SRSS.db-shm differ diff --git a/SharpRSS.Blazor/SRSS.db-wal b/SharpRSS.Blazor/SRSS.db-wal new file mode 100644 index 0000000..e69de29
Page not found!
Determining session state, please wait...