mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 12:54:20 +01:00
Compare commits
2 Commits
69eeb5c44e
...
c4ae8ab195
Author | SHA1 | Date | |
---|---|---|---|
|
c4ae8ab195 | ||
|
e8572915de |
42
SharpRSS.Blazor/Auth/SRSSAuthenticationStateProvider.cs
Normal file
42
SharpRSS.Blazor/Auth/SRSSAuthenticationStateProvider.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using Blazored.LocalStorage;
|
||||
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, ILocalStorageService localStorageService)
|
||||
{
|
||||
_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;
|
||||
_localStorageService = localStorageService;
|
||||
}
|
||||
|
||||
/*
|
||||
* Services
|
||||
*/
|
||||
private readonly ILogger _logger;
|
||||
private readonly HttpContext _httpContext;
|
||||
private readonly AuthService _authService;
|
||||
private readonly ILocalStorageService _localStorageService;
|
||||
/*
|
||||
* Consts
|
||||
*/
|
||||
private const string AuthIdName = "srss_auth_id";
|
||||
|
||||
public override Task<AuthenticationState> GetAuthenticationStateAsync()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
9
SharpRSS.Blazor/Constants/Routes.cs
Normal file
9
SharpRSS.Blazor/Constants/Routes.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace SharpRSS.Blazor.Constants;
|
||||
|
||||
/// <summary>
|
||||
/// The internal application routes
|
||||
/// </summary>
|
||||
public static class Routes
|
||||
{
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using Blazored.LocalStorage;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MudBlazor.Services;
|
||||
using SharpRSS.Blazor.Components;
|
||||
|
@ -7,11 +8,13 @@ using SharpRSS.Data;
|
|||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.UseSRSS();
|
||||
builder.Services.AddBlazoredLocalStorage();
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
builder.Services.AddMudServices();
|
||||
builder.Services.AddHttpContextAccessor(); // HttpContext accessor
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
|
48
SharpRSS.Blazor/Resources/App.Defaults.Designer.cs
generated
Normal file
48
SharpRSS.Blazor/Resources/App.Defaults.Designer.cs
generated
Normal file
|
@ -0,0 +1,48 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
21
SharpRSS.Blazor/Resources/App.Defaults.resx
Normal file
21
SharpRSS.Blazor/Resources/App.Defaults.resx
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>1.3</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -12,7 +12,23 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Blazored.LocalStorage" Version="4.5.0" />
|
||||
<PackageReference Include="MudBlazor" Version="6.20.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources\App.Defaults.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>App.Defaults.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources\App.Defaults.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>App.Defaults.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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<SRSSContext>(options =>
|
||||
{
|
||||
var dbSettings = new DatabaseSettings();
|
||||
|
@ -53,7 +58,12 @@ public static class DependencyInjection
|
|||
}
|
||||
});
|
||||
|
||||
//TODO: Services, Auth, Settings
|
||||
/*
|
||||
* Services
|
||||
*/
|
||||
builder.Services.AddScoped<AuthService>();
|
||||
|
||||
//TODO: Auth, Settings
|
||||
return builder;
|
||||
}
|
||||
}
|
30
SharpRSS.Business/Services/AuthService.cs
Normal file
30
SharpRSS.Business/Services/AuthService.cs
Normal file
|
@ -0,0 +1,30 @@
|
|||
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<Result> LoginUserAsync(LoginModel loginModel)
|
||||
{
|
||||
return Result.Failed("NotImplemented");
|
||||
}
|
||||
|
||||
public async Task<Result> LogoutUserAsync(string id)
|
||||
{
|
||||
return Result.Failed("NotImplemented");
|
||||
}
|
||||
|
||||
public async Task<Result> ValidateAuthenticationStateAsync(string id)
|
||||
{
|
||||
return Result.Failed("NotImplemented");
|
||||
}
|
||||
}
|
10
SharpRSS.Data/Domains/Auth/AuthenticationStateModel.cs
Normal file
10
SharpRSS.Data/Domains/Auth/AuthenticationStateModel.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace SharpRSS.Data.Domains.Auth;
|
||||
|
||||
public class AuthenticationStateModel
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public DateTime Created { get; set; } = DateTime.Now;
|
||||
public DateTime LastHit { get; set; }
|
||||
public string UserIdReference { get; set; } = string.Empty;
|
||||
public bool LoggedIn { get; set; }
|
||||
}
|
8
SharpRSS.Data/Domains/Auth/Identity/RoleModel.cs
Normal file
8
SharpRSS.Data/Domains/Auth/Identity/RoleModel.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace SharpRSS.Data.Domains.Auth.Identity;
|
||||
|
||||
public class RoleModel
|
||||
{
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
public string RoleId { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
}
|
15
SharpRSS.Data/Domains/Auth/Identity/UserModel.cs
Normal file
15
SharpRSS.Data/Domains/Auth/Identity/UserModel.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace SharpRSS.Data.Domains.Auth.Identity;
|
||||
|
||||
public class UserModel
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string PasswordHash { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string FamilyName { get; set; } = string.Empty;
|
||||
public DateTime CreatedDate { get; set; } = DateTime.Now;
|
||||
public DateTime LastLogin { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
}
|
7
SharpRSS.Data/Domains/Auth/LoginModel.cs
Normal file
7
SharpRSS.Data/Domains/Auth/LoginModel.cs
Normal file
|
@ -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;
|
||||
}
|
10
SharpRSS.Data/Domains/Auth/RegisterModel.cs
Normal file
10
SharpRSS.Data/Domains/Auth/RegisterModel.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace SharpRSS.Data.Domains.Auth;
|
||||
|
||||
public class RegisterModel
|
||||
{
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string FamilyName { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
}
|
|
@ -15,7 +15,6 @@
|
|||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Domains\" />
|
||||
<Folder Include="Repositories\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user