Compare commits
5 Commits
ae0f437e2c
...
e8450400c7
Author | SHA1 | Date | |
---|---|---|---|
e8450400c7 | |||
65709e1f83 | |||
1e204c948c | |||
0ced152fc9 | |||
6f9bfd3880 |
@ -5,9 +5,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Winsomnia</Company>
|
<Company>Winsomnia</Company>
|
||||||
<Version>1.0.0-a0</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>1.0.0.0</AssemblyVersion>
|
<AssemblyVersion>1.0.3.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.0.0</FileVersion>
|
<FileVersion>1.0.3.0</FileVersion>
|
||||||
<AssemblyName>Mirea.Api.Dto</AssemblyName>
|
<AssemblyName>Mirea.Api.Dto</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
@ -9,10 +9,11 @@ namespace Mirea.Api.Endpoint.Common.Attributes;
|
|||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public class TokenAuthenticationAttribute : Attribute, IActionFilter
|
public class TokenAuthenticationAttribute : Attribute, IActionFilter
|
||||||
{
|
{
|
||||||
|
public const string AuthToken = "AuthToken";
|
||||||
public void OnActionExecuting(ActionExecutingContext context)
|
public void OnActionExecuting(ActionExecutingContext context)
|
||||||
{
|
{
|
||||||
var setupToken = context.HttpContext.RequestServices.GetRequiredService<ISetupToken>();
|
var setupToken = context.HttpContext.RequestServices.GetRequiredService<ISetupToken>();
|
||||||
if (!context.HttpContext.Request.Cookies.TryGetValue("AuthToken", out string? tokenFromCookie))
|
if (!context.HttpContext.Request.Cookies.TryGetValue(AuthToken, out string? tokenFromCookie))
|
||||||
{
|
{
|
||||||
context.Result = new UnauthorizedResult();
|
context.Result = new UnauthorizedResult();
|
||||||
return;
|
return;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
using Microsoft.AspNetCore.Mvc.Versioning;
|
using Microsoft.AspNetCore.Mvc.Versioning;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class ApiVersioningConfiguration
|
public static class ApiVersioningConfiguration
|
||||||
{
|
{
|
@ -3,7 +3,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Mirea.Api.Endpoint.Common.Settings;
|
using Mirea.Api.Endpoint.Common.Settings;
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
using Mirea.Api.Endpoint.Configuration.General.Settings;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class CacheConfiguration
|
public static class CacheConfiguration
|
||||||
{
|
{
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class EnvironmentConfiguration
|
public static class EnvironmentConfiguration
|
||||||
{
|
{
|
@ -7,7 +7,7 @@ using Mirea.Api.Security.Common.Interfaces;
|
|||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class JwtConfiguration
|
public static class JwtConfiguration
|
||||||
{
|
{
|
@ -9,7 +9,7 @@ using Serilog.Filters;
|
|||||||
using Serilog.Formatting.Compact;
|
using Serilog.Formatting.Compact;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class LoggerConfiguration
|
public static class LoggerConfiguration
|
||||||
{
|
{
|
@ -6,7 +6,7 @@ using Mirea.Api.Endpoint.Configuration.General.Settings;
|
|||||||
using Mirea.Api.Security;
|
using Mirea.Api.Security;
|
||||||
using Mirea.Api.Security.Common.Interfaces;
|
using Mirea.Api.Security.Common.Interfaces;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class SecureConfiguration
|
public static class SecureConfiguration
|
||||||
{
|
{
|
@ -4,12 +4,12 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Mirea.Api.Endpoint.Common.Services;
|
using Mirea.Api.Endpoint.Common.Services;
|
||||||
using Mirea.Api.Endpoint.Configuration.Swagger;
|
using Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.AppConfig;
|
namespace Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
|
|
||||||
public static class SwaggerConfiguration
|
public static class SwaggerConfiguration
|
||||||
{
|
{
|
@ -5,7 +5,7 @@ using Microsoft.OpenApi.Models;
|
|||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.Swagger;
|
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||||
|
|
||||||
public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions>
|
public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions<SwaggerGenOptions>
|
||||||
{
|
{
|
@ -6,7 +6,7 @@ using System;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.Swagger;
|
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||||
|
|
||||||
public class SwaggerDefaultValues : IOperationFilter
|
public class SwaggerDefaultValues : IOperationFilter
|
||||||
{
|
{
|
@ -3,7 +3,7 @@ using Mirea.Api.Endpoint.Common.Attributes;
|
|||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Mirea.Api.Endpoint.Configuration.Swagger;
|
namespace Mirea.Api.Endpoint.Configuration.SwaggerOptions;
|
||||||
|
|
||||||
public class SwaggerExampleFilter : ISchemaFilter
|
public class SwaggerExampleFilter : ISchemaFilter
|
||||||
{
|
{
|
@ -20,6 +20,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
@ -68,9 +69,10 @@ public class SetupController(
|
|||||||
[HttpGet("CheckToken")]
|
[HttpGet("CheckToken")]
|
||||||
public ActionResult<bool> CheckToken([FromQuery] string token)
|
public ActionResult<bool> CheckToken([FromQuery] string token)
|
||||||
{
|
{
|
||||||
if (!setupToken.MatchToken(Convert.FromBase64String(token))) return Unauthorized("The token is not valid");
|
if (!setupToken.MatchToken(Convert.FromBase64String(token)))
|
||||||
|
return Unauthorized("The token is not valid");
|
||||||
|
|
||||||
Response.Cookies.Append("AuthToken", token, new CookieOptions
|
Response.Cookies.Append(TokenAuthenticationAttribute.AuthToken, token, new CookieOptions
|
||||||
{
|
{
|
||||||
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
|
||||||
Domain = HttpContext.GetCurrentDomain(),
|
Domain = HttpContext.GetCurrentDomain(),
|
||||||
@ -93,6 +95,10 @@ public class SetupController(
|
|||||||
connection.Open();
|
connection.Open();
|
||||||
connection.Close();
|
connection.Close();
|
||||||
|
|
||||||
|
if (connection is SqliteConnection)
|
||||||
|
SqliteConnection.ClearAllPools();
|
||||||
|
}
|
||||||
|
|
||||||
var general = GeneralConfig;
|
var general = GeneralConfig;
|
||||||
general.DbSettings = new DbSettings
|
general.DbSettings = new DbSettings
|
||||||
{
|
{
|
||||||
@ -152,12 +158,21 @@ public class SetupController(
|
|||||||
else
|
else
|
||||||
Directory.CreateDirectory(path, UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
Directory.CreateDirectory(path, UnixFileMode.UserRead | UnixFileMode.UserWrite);
|
||||||
}
|
}
|
||||||
else
|
else if (Directory.GetDirectories(path).Length != 0 ||
|
||||||
|
!Directory.GetFiles(path).Select(x => string.Equals(Path.GetFileName(x), "database.db3")).All(x => x))
|
||||||
throw new ControllerArgumentException("Such a folder exists. Enter a different name");
|
throw new ControllerArgumentException("Such a folder exists. Enter a different name");
|
||||||
|
|
||||||
string connectionString = $"Data Source={PathBuilder.Combine(path, "database.db3")}";
|
var filePath = Path.Combine(path, "database.db3");
|
||||||
|
var connectionString = $"Data Source={filePath}";
|
||||||
|
|
||||||
return SetDatabase<SqliteConnection, SqliteException>(connectionString, DbSettings.DatabaseEnum.Sqlite);
|
//System.IO.File.Create(filePath);
|
||||||
|
|
||||||
|
var result = SetDatabase<SqliteConnection, SqliteException>(connectionString, DbSettings.DatabaseEnum.Sqlite);
|
||||||
|
|
||||||
|
foreach (var file in Directory.GetFiles(path))
|
||||||
|
System.IO.File.Delete(file);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("SetRedis")]
|
[HttpPost("SetRedis")]
|
||||||
@ -211,7 +226,7 @@ public class SetupController(
|
|||||||
[BadRequestResponse]
|
[BadRequestResponse]
|
||||||
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user)
|
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user)
|
||||||
{
|
{
|
||||||
if (PasswordHashService.HasPasswordInPolicySecurity(user.Password))
|
if (!PasswordHashService.HasPasswordInPolicySecurity(user.Password))
|
||||||
throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character.");
|
throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character.");
|
||||||
|
|
||||||
if (!MailAddress.TryCreate(user.Email, out _))
|
if (!MailAddress.TryCreate(user.Email, out _))
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Winsomnia</Company>
|
<Company>Winsomnia</Company>
|
||||||
<Version>1.0.0-b3</Version>
|
<Version>1.0.0-rc0</Version>
|
||||||
<AssemblyVersion>1.0.1.3</AssemblyVersion>
|
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.1.3</FileVersion>
|
<FileVersion>1.0.2.0</FileVersion>
|
||||||
<AssemblyName>Mirea.Api.Endpoint</AssemblyName>
|
<AssemblyName>Mirea.Api.Endpoint</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
@ -34,8 +34,8 @@
|
|||||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
|
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.7.2" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.7.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.Versioning" Version="2.0.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore.Versioning" Version="2.0.0" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -11,7 +11,7 @@ using Mirea.Api.DataAccess.Persistence.Common;
|
|||||||
using Mirea.Api.Endpoint.Common.Interfaces;
|
using Mirea.Api.Endpoint.Common.Interfaces;
|
||||||
using Mirea.Api.Endpoint.Common.Services;
|
using Mirea.Api.Endpoint.Common.Services;
|
||||||
using Mirea.Api.Endpoint.Common.Settings;
|
using Mirea.Api.Endpoint.Common.Settings;
|
||||||
using Mirea.Api.Endpoint.Configuration.AppConfig;
|
using Mirea.Api.Endpoint.Configuration.ApplicationConfiguration;
|
||||||
using Mirea.Api.Endpoint.Configuration.General;
|
using Mirea.Api.Endpoint.Configuration.General;
|
||||||
using Mirea.Api.Endpoint.Configuration.General.Validators;
|
using Mirea.Api.Endpoint.Configuration.General.Validators;
|
||||||
using Mirea.Api.Endpoint.Middleware;
|
using Mirea.Api.Endpoint.Middleware;
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Winsomnia</Company>
|
<Company>Winsomnia</Company>
|
||||||
<Version>1.0.0-rc0</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
<AssemblyVersion>1.0.3.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.2.0</FileVersion>
|
<FileVersion>1.0.3.0</FileVersion>
|
||||||
<AssemblyName>Mirea.Api.Security</AssemblyName>
|
<AssemblyName>Mirea.Api.Security</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Winsomnia</Company>
|
<Company>Winsomnia</Company>
|
||||||
<Version>1.0.0-rc0</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
<AssemblyVersion>1.0.3.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.2.0</FileVersion>
|
<FileVersion>1.0.3.0</FileVersion>
|
||||||
<AssemblyName>Mirea.Api.DataAccess.Application</AssemblyName>
|
<AssemblyName>Mirea.Api.DataAccess.Application</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
<ImplicitUsings>disable</ImplicitUsings>
|
<ImplicitUsings>disable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Company>Winsomnia</Company>
|
<Company>Winsomnia</Company>
|
||||||
<Version>1.0.0-rc0</Version>
|
<Version>1.0.0</Version>
|
||||||
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
<AssemblyVersion>1.0.3.0</AssemblyVersion>
|
||||||
<FileVersion>1.0.2.0</FileVersion>
|
<FileVersion>1.0.3.0</FileVersion>
|
||||||
<AssemblyName>Mirea.Api.DataAccess.Persistence</AssemblyName>
|
<AssemblyName>Mirea.Api.DataAccess.Persistence</AssemblyName>
|
||||||
<RootNamespace>$(AssemblyName)</RootNamespace>
|
<RootNamespace>$(AssemblyName)</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user