diff --git a/SharpRSS.Blazor/Auth/SRSSAuthenticationStateProvider.cs b/SharpRSS.Blazor/Auth/SRSSAuthenticationStateProvider.cs new file mode 100644 index 0000000..538c432 --- /dev/null +++ b/SharpRSS.Blazor/Auth/SRSSAuthenticationStateProvider.cs @@ -0,0 +1,32 @@ +using DotBased.Logging; +using Microsoft.AspNetCore.Components.Authorization; +using SharpRSS.Business.Services; +using ILogger = DotBased.Logging.ILogger; + +namespace SharpRSS.Blazor.Auth; + +public class SRSSAuthenticationStateProvider : AuthenticationStateProvider +{ + public SRSSAuthenticationStateProvider(IHttpContextAccessor contextAccessor, AuthService authService) + { + _logger = LogService.RegisterLogger(typeof(SRSSAuthenticationStateProvider)); + if (contextAccessor.HttpContext != null) + _httpContext = contextAccessor.HttpContext; + else + { + var ex = new ApplicationException("HttpContext is null! Cannot setup authentication state provider!"); + _logger.Fatal(ex, "Failed to initialize authentication state provider!"); + throw ex; + } + _authService = authService; + } + + private readonly ILogger _logger; + private readonly HttpContext _httpContext; + private readonly AuthService _authService; + + public override Task GetAuthenticationStateAsync() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/SharpRSS.Blazor/Constants/Routes.cs b/SharpRSS.Blazor/Constants/Routes.cs new file mode 100644 index 0000000..e1e3d11 --- /dev/null +++ b/SharpRSS.Blazor/Constants/Routes.cs @@ -0,0 +1,9 @@ +namespace SharpRSS.Blazor.Constants; + +/// +/// The internal application routes +/// +public static class Routes +{ + +} \ No newline at end of file diff --git a/SharpRSS.Blazor/Program.cs b/SharpRSS.Blazor/Program.cs index 44fc985..1c2f50a 100644 --- a/SharpRSS.Blazor/Program.cs +++ b/SharpRSS.Blazor/Program.cs @@ -12,6 +12,7 @@ builder.UseSRSS(); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); builder.Services.AddMudServices(); +builder.Services.AddHttpContextAccessor(); // HttpContext accessor var app = builder.Build(); diff --git a/SharpRSS.Blazor/Resources/App.Defaults.Designer.cs b/SharpRSS.Blazor/Resources/App.Defaults.Designer.cs new file mode 100644 index 0000000..3633322 --- /dev/null +++ b/SharpRSS.Blazor/Resources/App.Defaults.Designer.cs @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SharpRSS.Blazor.Resources { + using System; + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [System.Diagnostics.DebuggerNonUserCodeAttribute()] + [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class App_Defaults { + + private static System.Resources.ResourceManager resourceMan; + + private static System.Globalization.CultureInfo resourceCulture; + + [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal App_Defaults() { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Resources.ResourceManager ResourceManager { + get { + if (object.Equals(null, resourceMan)) { + System.Resources.ResourceManager temp = new System.Resources.ResourceManager("SharpRSS.Blazor.Resources.App_Defaults", typeof(App_Defaults).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + internal static System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/SharpRSS.Blazor/Resources/App.Defaults.resx b/SharpRSS.Blazor/Resources/App.Defaults.resx new file mode 100644 index 0000000..a4c5284 --- /dev/null +++ b/SharpRSS.Blazor/Resources/App.Defaults.resx @@ -0,0 +1,21 @@ + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SharpRSS.Blazor/SharpRSS.Blazor.csproj b/SharpRSS.Blazor/SharpRSS.Blazor.csproj index 67ebb97..392cb44 100644 --- a/SharpRSS.Blazor/SharpRSS.Blazor.csproj +++ b/SharpRSS.Blazor/SharpRSS.Blazor.csproj @@ -15,4 +15,19 @@ + + + ResXFileCodeGenerator + App.Defaults.Designer.cs + + + + + + True + True + App.Defaults.resx + + + diff --git a/SharpRSS.Business/DependencyInjection.cs b/SharpRSS.Business/DependencyInjection.cs index c0dc4bc..0fafc23 100644 --- a/SharpRSS.Business/DependencyInjection.cs +++ b/SharpRSS.Business/DependencyInjection.cs @@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.EntityFrameworkCore.Diagnostics; using Serilog; +using SharpRSS.Business.Services; using SharpRSS.Core.Configuration; using SharpRSS.Data; @@ -16,7 +17,9 @@ public static class DependencyInjection { public static WebApplicationBuilder UseSRSS(this WebApplicationBuilder builder) { - // Logging (serilog) + /* + * Logging (serilog) + */ var serilogConfig = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).UseBasedExtension(); Log.Logger = serilogConfig.CreateLogger(); @@ -26,7 +29,9 @@ public static class DependencyInjection builder.Logging.ClearProviders(); builder.Logging.AddSerilog(); - // EF Core DbContextFactory + /* + * EF Core DbContextFactory + */ builder.Services.AddDbContextFactory(options => { var dbSettings = new DatabaseSettings(); @@ -53,7 +58,12 @@ public static class DependencyInjection } }); - //TODO: Services, Auth, Settings + /* + * Services + */ + builder.Services.AddScoped(); + + //TODO: Auth, Settings return builder; } } \ No newline at end of file diff --git a/SharpRSS.Business/Services/AuthService.cs b/SharpRSS.Business/Services/AuthService.cs new file mode 100644 index 0000000..be21975 --- /dev/null +++ b/SharpRSS.Business/Services/AuthService.cs @@ -0,0 +1,25 @@ +using DotBased; +using DotBased.Logging; +using SharpRSS.Data.Domains.Auth; + +namespace SharpRSS.Business.Services; + +public class AuthService +{ + public AuthService() + { + _logger = LogService.RegisterLogger(typeof(AuthService)); + } + + private readonly ILogger _logger; + + public async Task LoginUserAsync(LoginModel loginModel) + { + return Result.Failed("NotImplemented"); + } + + public async Task LogoutUserAsync(string id) + { + return Result.Failed("NotImplemented"); + } +} \ No newline at end of file diff --git a/SharpRSS.Data/Domains/Auth/LoginModel.cs b/SharpRSS.Data/Domains/Auth/LoginModel.cs new file mode 100644 index 0000000..5a1044f --- /dev/null +++ b/SharpRSS.Data/Domains/Auth/LoginModel.cs @@ -0,0 +1,7 @@ +namespace SharpRSS.Data.Domains.Auth; + +public class LoginModel +{ + public string UserName { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/SharpRSS.Data/SharpRSS.Data.csproj b/SharpRSS.Data/SharpRSS.Data.csproj index 72648be..8c9e59d 100644 --- a/SharpRSS.Data/SharpRSS.Data.csproj +++ b/SharpRSS.Data/SharpRSS.Data.csproj @@ -15,7 +15,6 @@ -