Compare commits

..

5 Commits

Author SHA1 Message Date
e8450400c7 build: update ref
Some checks failed
Build and Deploy Docker Container / build-and-deploy (push) Has been cancelled
.NET Test Pipeline / build-and-test (push) Has been cancelled
2024-09-07 04:56:41 +03:00
65709e1f83 refactor: move files to another namespace 2024-09-07 04:28:07 +03:00
1e204c948c refactor: set cookie name to attribute 2024-09-07 04:19:51 +03:00
0ced152fc9 fix: remove database when check connect to sqlite 2024-09-07 04:19:05 +03:00
6f9bfd3880 fix: set correct password condition 2024-09-07 04:18:04 +03:00
18 changed files with 52 additions and 36 deletions

View File

@ -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>

View File

@ -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;

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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>
{ {

View File

@ -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
{ {

View File

@ -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
{ {

View File

@ -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 _))

View File

@ -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>

View File

@ -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;

View File

@ -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>

View File

@ -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>

View File

@ -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>