refactor: distribute the domain folder

This commit is contained in:
nikita
2024-12-26 13:38:43 +03:00
parent 43edab2912
commit 36026b3afb
22 changed files with 98 additions and 67 deletions

@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Http;
using System;
namespace Mirea.Api.Security.Common.Model;
public class CookieOptions
{
public required string Domain { get; set; }
public required string Path { get; set; }
internal void SetCookie(HttpContext context, string name, string value, DateTimeOffset? expires = null)
{
var cookieOptions = new Microsoft.AspNetCore.Http.CookieOptions
{
Expires = expires,
Path = Path,
Domain = Domain,
HttpOnly = true,
#if !DEBUG
Secure = true
#endif
};
context.Response.Cookies.Append(name, value, cookieOptions);
}
internal void DropCookie(HttpContext context, string name) =>
SetCookie(context, name, "", DateTimeOffset.MinValue);
}

@ -0,0 +1,15 @@
namespace Mirea.Api.Security.Common.Model;
public class PasswordPolicy(
int minimumLength = 8,
bool requireLetter = true,
bool requireLettersDifferentCase = true,
bool requireDigit = true,
bool requireSpecialCharacter = true)
{
public int MinimumLength { get; set; } = minimumLength;
public bool RequireLetter { get; set; } = requireLetter;
public bool RequireLettersDifferentCase { get; set; } = requireLettersDifferentCase;
public bool RequireDigit { get; set; } = requireDigit;
public bool RequireSpecialCharacter { get; set; } = requireSpecialCharacter;
}

@ -0,0 +1,7 @@
namespace Mirea.Api.Security.Common.Model;
public enum TwoFactorAuthenticator
{
None,
Totp
}

@ -0,0 +1,16 @@
using Mirea.Api.Security.Common.Domain;
using System.Collections.Generic;
namespace Mirea.Api.Security.Common.Model;
public class User
{
public required string Id { get; set; }
public required string Username { get; set; }
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public required string Salt { get; set; }
public required TwoFactorAuthenticator TwoFactorAuthenticator { get; set; }
public string? SecondFactorToken { get; set; }
public Dictionary<OAuthProvider, OAuthUser>? OAuthProviders { get; set; }
}