This commit is contained in:
Eugene ;) 2023-02-19 00:43:43 +01:00
parent 9719a0c0fd
commit 1e66851113
146 changed files with 738 additions and 382 deletions

View File

@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class AtLeastOnePropertyAttribute : ValidationAttribute

View File

@ -1,7 +1,9 @@
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
public static class Constants
{
public const int MaxAvatarNameLength = 32;
public const int MaxAvatarBiographyLength = 5_000;
public const int MinPasswordLength = 7;
public const int MaxPasswordLength = 1025;
public const int GroupInvitationLength = 64;

View File

@ -1,4 +1,4 @@
namespace SocialPub.ClientModels.Data
namespace PrivaPub.ClientModels.Data
{
public class ViewLanguage
{

View File

@ -1,10 +1,10 @@
using SocialPub.ClientModels.Resources;
using SocialPub.ClientModels.ValidatorAttributes;
using PrivaPub.ClientModels.Resources;
using PrivaPub.ClientModels.ValidatorAttributes;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
public class LoginForm
{

View File

@ -1,9 +1,9 @@
using SocialPub.ClientModels.Resources;
using PrivaPub.ClientModels.Resources;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
public class NewPasswordForm
{

View File

@ -1,8 +1,8 @@
using SocialPub.ClientModels.Resources;
using PrivaPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
[AtLeastOneProperty(nameof(UserName), nameof(Email),
ErrorMessageResourceName = "AtLeastOneProperty",

View File

@ -1,4 +1,4 @@
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
public static class Policies
{

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace SocialPub.ClientModels.Resources {
namespace PrivaPub.ClientModels.Resources {
using System;
@ -39,7 +39,7 @@ namespace SocialPub.ClientModels.Resources {
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SocialPub.ClientModels.Resources.ErrorsResource", typeof(ErrorsResource).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PrivaPub.ClientModels.Resources.ErrorsResource", typeof(ErrorsResource).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -8,7 +8,7 @@
// </auto-generated>
//------------------------------------------------------------------------------
namespace SocialPub.ClientModels.Resources {
namespace PrivaPub.ClientModels.Resources {
using System;
@ -39,7 +39,7 @@ namespace SocialPub.ClientModels.Resources {
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SocialPub.ClientModels.Resources.FieldsNameResource", typeof(FieldsNameResource).Assembly);
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PrivaPub.ClientModels.Resources.FieldsNameResource", typeof(FieldsNameResource).Assembly);
resourceMan = temp;
}
return resourceMan;

View File

@ -0,0 +1,35 @@
using PrivaPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
using System.Security.AccessControl;
using System.Text.Json.Serialization;
using System.Xml.Linq;
namespace PrivaPub.ClientModels.User.Avatar
{
[JsonSerializable(typeof(InsertAvatarForm))]
public class InsertAvatarForm
{
[JsonIgnore]
public string RootId { get; set; }
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
StringLength(Constants.MaxAvatarNameLength, ErrorMessageResourceName = "StringLength", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(Name), ResourceType = typeof(FieldsNameResource))]
public string Name { get; set; }//name
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
StringLength(Constants.MaxAvatarNameLength, ErrorMessageResourceName = "StringLength", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(UserName), ResourceType = typeof(FieldsNameResource))]
public string UserName { get; set; }//preferredUsername
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
StringLength(Constants.MaxAvatarBiographyLength, ErrorMessageResourceName = "StringLength", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(Biography), ResourceType = typeof(FieldsNameResource))]
public string Biography { get; set; }//summary
public ViewAvatarSettings Settings { get; set; } = new();
public Dictionary<string, string> Fields { get; set; } = new();
public string PersonalNote { get; set; }
}
}

View File

@ -0,0 +1,31 @@
using PrivaPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace PrivaPub.ClientModels.User.Avatar
{
[JsonSerializable(typeof(UpdateAvatarForm))]
public class UpdateAvatarForm
{
[JsonIgnore]
public string RootId { get; set; }
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(AvatarId), ResourceType = typeof(FieldsNameResource))]
public string AvatarId { get; set; }
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
StringLength(Constants.MaxAvatarNameLength, ErrorMessageResourceName = "StringLength", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(Name), ResourceType = typeof(FieldsNameResource))]
public string Name { get; set; }//name
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
StringLength(Constants.MaxAvatarBiographyLength, ErrorMessageResourceName = "StringLength", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(Biography), ResourceType = typeof(FieldsNameResource))]
public string Biography { get; set; }//summary
public ViewAvatarSettings Settings { get; set; } = new();
public Dictionary<string, string> Fields { get; set; } = new();
public string PersonalNote { get; set; }
}
}

View File

@ -0,0 +1,26 @@
using System.Text.Json.Serialization;
namespace PrivaPub.ClientModels.User.Avatar
{
[JsonSerializable(typeof(ViewAvatar))]
public class ViewAvatar
{
public string Url { get; set; }//url
public string Name { get; set; }//name
public string UserName { get; set; }//preferredUsername
public string Biography { get; set; }//summary
public Dictionary<string, string> Fields { get; set; } = new();
public string PictureURL { get; set; }//icon
public string ThumbnailURL { get; set; }//image
public Dictionary<string, string> SharedPersonalContacts { get; set; } = new();
public ViewAvatarState AccountState { get; set; } = ViewAvatarState.Normal;
public ViewAvatarServer ServerType { get; set; } = ViewAvatarServer.Unknown;
public ViewAvatarSettings Settings { get; set; } = new();
public DateTime UpdatedAt { get; set; }
public DateTime CreatedAt { get; set; }
}
}

View File

@ -1,25 +1,29 @@
using SocialPub.ClientModels.Resources;
using PrivaPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace SocialPub.ClientModels.User
namespace PrivaPub.ClientModels.User.Avatar
{
public class ViewUserSettings
[JsonSerializable(typeof(ViewAvatarSettings))]
public class ViewAvatarSettings
{
[Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(ErrorsResource)),
Display(Name = nameof(LanguageCode), ResourceType = typeof(FieldsNameResource))]
public string LanguageCode { get; set; } = "en";
public string LanguageCode { get; set; } = "en-GB";
public bool IsDefault { get; set; } = true;
[Range(-2, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
public short IconsThemeIndexColour { get; set; } = 25;
[Range(0, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
public short LightThemeIndexColour { get; set; } = 25;
[Range(0, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
public short DarkThemeIndexColour { get; set; } = 215;
[Range(-2, 359, ErrorMessageResourceName = nameof(Range), ErrorMessageResourceType = typeof(ErrorsResource))]
public short IconsThemeIndexColour { get; set; } = 25;
public bool PreferSystemTheming { get; set; } = false;
public bool PreferSystemTheming { get; set; } = true;
public bool ThemeIsDarkMode { get; set; } = false;
public bool ThemeIsLightGray { get; set; } = false;
public bool ThemeIsLightGray { get; set; } = true;
public bool ThemeIsDarkGray { get; set; } = false;
}
}
}

View File

@ -1,4 +1,4 @@
namespace SocialPub.ClientModels.User
namespace PrivaPub.ClientModels.User
{
public class JwtUser
{
@ -8,6 +8,6 @@
public List<string> Policies { get; set; } = new();
public string Token { get; set; }
public long Expiration { get; set; }
public ViewUserSettings UserSettings { get; set; } = new();
public ViewAvatarServer UserSettings { get; set; } = new();
}
}

View File

@ -1,9 +1,9 @@
using SocialPub.ClientModels.Resources;
using PrivaPub.ClientModels.Resources;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels.User
namespace PrivaPub.ClientModels.User
{
public class UserForm
{

View File

@ -1,4 +1,4 @@
namespace SocialPub.ClientModels.User
namespace PrivaPub.ClientModels.User
{
public class UsersIds
{

View File

@ -0,0 +1,12 @@
namespace PrivaPub.ClientModels.User
{
public enum ViewAvatarServer
{
Unknown,
Pleroma,
Mastodon,
Akkoma,
Misskey,
PrivaPub
}
}

View File

@ -0,0 +1,11 @@
namespace PrivaPub.ClientModels.User
{
public enum ViewAvatarState
{
Normal,
Silenced,
Suspended,
Banned,
Deleted
}
}

View File

@ -1,8 +1,8 @@
using SocialPub.ClientModels.Resources;
using PrivaPub.ClientModels.Resources;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.ClientModels.ValidatorAttributes
namespace PrivaPub.ClientModels.ValidatorAttributes
{
[AttributeUsage(AttributeTargets.Property)]
public class NoWhiteSpacesAttribute : ValidationAttribute

View File

@ -1,7 +1,7 @@
using System.Net;
using System.Text.Json.Serialization;
namespace SocialPub.ClientModels
namespace PrivaPub.ClientModels
{
public class WebResult
{

View File

@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialPub", "SocialPub\SocialPub.csproj", "{EB2A0BD2-0150-405A-939E-5B0F6F642539}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrivaPub", "PrivaPub\PrivaPub.csproj", "{EB2A0BD2-0150-405A-939E-5B0F6F642539}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SocialPub.ClientModels", "SocialPub.ClientModels\SocialPub.ClientModels.csproj", "{5E63C68C-0E60-4418-A53A-FF4EF0007080}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrivaPub.ClientModels", "PrivaPub.ClientModels\PrivaPub.ClientModels.csproj", "{5E63C68C-0E60-4418-A53A-FF4EF0007080}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

View File

@ -2,25 +2,25 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using SocialPub.ClientModels;
using SocialPub.ClientModels.User;
using SocialPub.Extensions;
using SocialPub.Resources;
using SocialPub.Services;
using PrivaPub.ClientModels;
using PrivaPub.ClientModels.User;
using PrivaPub.Extensions;
using PrivaPub.Resources;
using PrivaPub.Services;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.Controllers.ClientToServer
namespace PrivaPub.Controllers.ClientToServer
{
[ApiController,
Route("clientapi/admin")]
public class AdminController : ControllerBase
{
readonly IRootUsersService RootUsersService;
readonly ILogger<UserController> Logger;
readonly ILogger<RootUserController> Logger;
readonly IStringLocalizer Localizer;
public AdminController(ILogger<UserController> logger,
public AdminController(ILogger<RootUserController> logger,
IStringLocalizer<GenericRes> localizer,
IRootUsersService rootUsersService)
{

View File

@ -1,11 +1,11 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SocialPub.ClientModels;
using SocialPub.ClientModels.Data;
using SocialPub.Services.ClientToServer.Public;
using PrivaPub.ClientModels;
using PrivaPub.ClientModels.Data;
using PrivaPub.Services.ClientToServer.Public;
namespace SocialPub.Controllers.ClientToServer
namespace PrivaPub.Controllers.ClientToServer
{
[ApiController,
Route("clientapi/data")]
@ -41,7 +41,7 @@ namespace SocialPub.Controllers.ClientToServer
{
Name = l.NativeName,
International2Code = l.International2Code
}).ToList());
}).ToArray());
return Ok(viewLanguages);
}

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
namespace SocialPub.Controllers.ClientToServer
namespace PrivaPub.Controllers.ClientToServer
{
[ApiController,
Route("clientapi/moderator")]

View File

@ -0,0 +1,75 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using PrivaPub.ClientModels;
using PrivaPub.Extensions;
using PrivaPub.Resources;
using PrivaPub.Services.ClientToServer.Private;
using PrivaPub.ClientModels.User.Avatar;
namespace PrivaPub.Controllers.ClientToServer
{
[ApiController,
Route("clientapi/avatar/private"),
Authorize(Policy = Policies.IsUser)]
public class PrivateAvatarController : ControllerBase
{
readonly ILogger<PrivateAvatarController> _logger;
readonly IPrivateAvatarUsersService _privateAvatarUsersService;
readonly IStringLocalizer _localizer;
public PrivateAvatarController(IPrivateAvatarUsersService privateAvatarUsersService,
IStringLocalizer<GenericRes> localizer,
ILogger<PrivateAvatarController> logger)
{
_privateAvatarUsersService = privateAvatarUsersService;
_localizer = localizer;
_logger = logger;
}
[HttpPost, Route("/clientapi/avatar/private/insert")]
public async Task<IActionResult> InsertAvatar(InsertAvatarForm model)
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(_localizer["Invalid model."]));
try
{
model.RootId = User.GetUserId();
result = await _privateAvatarUsersService.InsertAvatar(model);
if (!result.IsValid)
return StatusCode(result.StatusCode, result);
return Ok(result.Data);
}
catch (Exception ex)
{
_logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(InsertAvatar)}()");
return BadRequest(result.Invalidate(ex.Message));
}
}
[HttpPost, Route("/clientapi/avatar/private/update")]
public async Task<IActionResult> UpdateAvatar(UpdateAvatarForm model)
{
var result = new WebResult();
if (!ModelState.IsValid)
return BadRequest(result.Invalidate(_localizer["Invalid model."]));
try
{
model.RootId = User.GetUserId();
result = await _privateAvatarUsersService.UpdateAvatar(model);
if (!result.IsValid)
return StatusCode(result.StatusCode, result);
return Ok(result.Data);
}
catch (Exception ex)
{
_logger.LogError(ex, $"{nameof(PrivateAvatarController)}.{nameof(UpdateAvatar)}()");
return BadRequest(result.Invalidate(ex.Message));
}
}
}
}

View File

@ -3,32 +3,32 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using SocialPub.ClientModels;
using SocialPub.ClientModels.Resources;
using SocialPub.ClientModels.User;
using SocialPub.Extensions;
using SocialPub.Models.User;
using SocialPub.Resources;
using SocialPub.Services;
using SocialPub.StaticServices;
using PrivaPub.ClientModels;
using PrivaPub.ClientModels.Resources;
using PrivaPub.ClientModels.User;
using PrivaPub.Extensions;
using PrivaPub.Models.User;
using PrivaPub.Resources;
using PrivaPub.Services;
using PrivaPub.StaticServices;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.Controllers.ClientToServer
namespace PrivaPub.Controllers.ClientToServer
{
[ApiController,
Route("clientapi/user")]
public class UserController : ControllerBase
public class RootUserController : ControllerBase
{
readonly IRootUsersService UsersService;
readonly AuthTokenManager AuthTokenManager;
readonly ILogger<UserController> Logger;
readonly ILogger<RootUserController> Logger;
readonly IStringLocalizer Localizer;
public UserController(IRootUsersService usersService,
public RootUserController(IRootUsersService usersService,
AuthTokenManager authTokenManager,
IStringLocalizer<GenericRes> localizer,
ILogger<UserController> logger)
ILogger<RootUserController> logger)
{
UsersService = usersService;
AuthTokenManager = authTokenManager;
@ -51,7 +51,7 @@ namespace SocialPub.Controllers.ClientToServer
if (!result.IsValid)
return StatusCode(result.StatusCode, result);
(var user, var userSettings) = ((RootUser, ViewUserSettings))result.Data;
(var user, var userSettings) = ((RootUser, ViewAvatarServer))result.Data;
var jwtUser = AuthTokenManager.GenerateToken(user, userSettings);
Logger.LogInformation(
$"{nameof(SignUp)}();IP:[{HttpContext.Connection?.RemoteIpAddress}];\nUser-Agent:[{Request.Headers["User-Agent"]}];\nUserId:[{user.ID}]");
@ -78,7 +78,7 @@ namespace SocialPub.Controllers.ClientToServer
return StatusCode(result.StatusCode, result);
var (user, userSettings) =
((RootUser, ViewUserSettings))result.Data;
((RootUser, ViewAvatarServer))result.Data;
var jwtUser = AuthTokenManager.GenerateToken(user, userSettings);
Logger.LogInformation(
$"{nameof(Login)}();IP:[{HttpContext.Connection?.RemoteIpAddress}];\nUser-Agent:[{Request.Headers["User-Agent"]}];\nUserId:[{user.ID}]");
@ -223,7 +223,7 @@ namespace SocialPub.Controllers.ClientToServer
}
[HttpPost, Route("/clientapi/user/update/settings"), Authorize(Policy = Policies.IsUser)]
public async Task<IActionResult> UpdateUserSettings(ViewUserSettings userSettings)
public async Task<IActionResult> UpdateUserSettings(ViewAvatarServer userSettings)
{
var result = new WebResult();
if (!ModelState.IsValid)

View File

@ -2,16 +2,16 @@
using Microsoft.AspNetCore.Mvc;
using SocialPub.ClientModels.Resources;
using SocialPub.Extensions;
using SocialPub.Models.ActivityPub;
using SocialPub.Models.Group;
using SocialPub.Services;
using PrivaPub.ClientModels.Resources;
using PrivaPub.Extensions;
using PrivaPub.Models.ActivityPub;
using PrivaPub.Models.Group;
using PrivaPub.Services;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace SocialPub.Controllers.ServerToServer
namespace PrivaPub.Controllers.ServerToServer
{
[ApiController,
Route("peasants"), Produces("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"; charset=utf-8")]

View File

@ -1,15 +1,15 @@
using Markdig;
using Microsoft.AspNetCore.Mvc;
using SocialPub.ClientModels.Resources;
using SocialPub.Extensions;
using SocialPub.Models.ActivityPub;
using SocialPub.Models.Group;
using SocialPub.Services;
using PrivaPub.ClientModels.Resources;
using PrivaPub.Extensions;
using PrivaPub.Models.ActivityPub;
using PrivaPub.Models.Group;
using PrivaPub.Services;
using System.ComponentModel.DataAnnotations;
namespace SocialPub.Controllers.ServerToServer
namespace PrivaPub.Controllers.ServerToServer
{
[ApiController,
Route("users"), Produces("application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"; charset=utf-8")]

View File

@ -1,12 +1,12 @@
using MongoDB.Entities;
using SocialPub.Models.Data;
using SocialPub.StaticServices;
using PrivaPub.Models.Data;
using PrivaPub.StaticServices;
using System.Text;
using System.Text.Json;
namespace SocialPub.Data
namespace PrivaPub.Data
{
public static class InitDb
{

View File

@ -1,4 +1,4 @@
namespace SocialPub.Data
namespace PrivaPub.Data
{
public class LanguagesRow
{

View File

@ -1,15 +1,15 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.IdentityModel.Tokens;
using SocialPub.Services;
using PrivaPub.Services;
using System.Text;
namespace SocialPub.Extensions
namespace PrivaPub.Extensions
{
public static class AddAuthExtension
{
public static AuthenticationBuilder AddSocialPubAuth(this AuthenticationBuilder builder, IConfiguration configuration)
public static AuthenticationBuilder AddPrivaPubAuth(this AuthenticationBuilder builder, IConfiguration configuration)
{
builder.AddJwtBearer(options => {
#if DEBUG

View File

@ -7,14 +7,14 @@ using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.X509;
using SocialPub.ClientModels;
using PrivaPub.ClientModels;
using System.Security.Cryptography.X509Certificates;
using Org.BouncyCastle.Math;
using SocialPub.Models.User;
using PrivaPub.Models.User;
using System.Security.Claims;
namespace SocialPub.Extensions
namespace PrivaPub.Extensions
{
public static class Extensions
{

View File

@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace SocialPub.Extensions
namespace PrivaPub.Extensions
{
public class OperationCancelledExceptionFilter : ExceptionFilterAttribute
{

View File

@ -1,8 +1,8 @@
using SocialPub.ClientModels;
using PrivaPub.ClientModels;
using System.Security.Claims;
namespace SocialPub.Extensions
namespace PrivaPub.Extensions
{
public static class StringExtensions
{

View File

@ -1,52 +1,45 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.ResponseCompression;
using SocialPub.ClientModels;
using SocialPub.Extensions;
using SocialPub.Models;
using SocialPub.Services;
using SocialPub.StaticServices;
using NSign.AspNetCore;
using PrivaPub.ClientModels;
using PrivaPub.Extensions;
using PrivaPub.Models;
using PrivaPub.Services;
using PrivaPub.StaticServices;
using System.Text.Json.Serialization;
using NSign.Providers;
using NSign;
using System.Security.Cryptography.X509Certificates;
using NSign.Signatures;
using System.Net.Http.Headers;
using Microsoft.Extensions.DependencyInjection;
using System.Security.Claims;
using Microsoft.Extensions.Caching.Memory;
using NSign.Client;
using static NSign.Constants;
using System.Text;
using Microsoft.OpenApi.Models;
using SocialPub.Services.ClientToServer.Public;
using PrivaPub.Services.ClientToServer.Public;
namespace SocialPub.Middleware
namespace PrivaPub.Middleware
{
public static class SocialPubConfigurations
public static class PrivaPubConfigurations
{
public static IServiceCollection socialPubAppSettingsConfiguration(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection PrivaPubAppSettingsConfiguration(this IServiceCollection service, IConfiguration configuration)
{
return service
.Configure<MongoSettings>(configuration.GetSection(nameof(MongoSettings)))
.Configure<AppConfiguration>(configuration.GetSection(nameof(AppConfiguration)));
}
public static IServiceCollection socialPubWorkersConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubWorkersConfiguration(this IServiceCollection service)
{
return service;
//.AddHostedService<DiscussionsWorker>()
//.AddHostedService<GroupsCleanerWorker>()
//.AddHostedService<PoliciesCleanerWorker>();
}
public static IServiceCollection socialPubHTTPSignature(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection PrivaPubHTTPSignature(this IServiceCollection service, IConfiguration configuration)
{
//HTTP CLIENT
service.Configure<AddDigestOptions>(options => options.WithHash(AddDigestOptions.Hash.Sha256))
.ConfigureMessageSigningOptions(options =>
{
options.SignatureName = "SocialPub";
options.SignatureName = "PrivaPub";
options
.WithMandatoryComponent(SignatureComponent.Path)
.WithMandatoryComponent(SignatureComponent.RequestTarget)
@ -84,7 +77,7 @@ namespace SocialPub.Middleware
// //httpContextAccessor.HttpContext.Request.
// var cert = memoryCache.GetOrCreate("SocialPub", (cacheEntry) => Extensions.Extensions.GetX509Certificate2("socialPubCert"));
// var cert = memoryCache.GetOrCreate("PrivaPub", (cacheEntry) => Extensions.Extensions.GetX509Certificate2("PrivaPubCert"));
// return new RsaPkcs15Sha256SignatureProvider(cert, "anon");
//})
//.ConfigureMessageSigningOptions(options =>
@ -109,7 +102,7 @@ namespace SocialPub.Middleware
// new X509Certificate2(@"path\to\certificate.pfx", "PasswordForPfx"),
// "my-cert"));
}
public static IServiceCollection socialPubAuthServicesConfiguration(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection PrivaPubAuthServicesConfiguration(this IServiceCollection service, IConfiguration configuration)
{
return service
.AddAuthorization(options =>
@ -124,19 +117,19 @@ namespace SocialPub.Middleware
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddSocialPubAuth(configuration)
.AddPrivaPubAuth(configuration)
.Services
.AddSingleton<AuthTokenManager>()
.AddSingleton<IPasswordHasher, PasswordHasher>();
}
public static IServiceCollection socialPubInternalizationConfiguration(this IServiceCollection service, IConfiguration configuration)
public static IServiceCollection PrivaPubInternalizationConfiguration(this IServiceCollection service, IConfiguration configuration)
{
return service
.AddLocalization()
.AddSingleton<RequestLocalizationOptionsService>();
}
public static IServiceCollection socialPubOptimizationConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubOptimizationConfiguration(this IServiceCollection service)
{
return service.AddResponseCompression(opts =>
{
@ -145,24 +138,24 @@ namespace SocialPub.Middleware
});
}
public static IServiceCollection socialPubDataBaseConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubDataBaseConfiguration(this IServiceCollection service)
{
return service.AddSingleton<DbEntities>();
}
public static IServiceCollection socialPubServicesConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubServicesConfiguration(this IServiceCollection service)
{
return service
.AddTransient<IDataService, DataService>()
.AddTransient<IRootUsersService, RootUsersService>()
.AddTransient<IGroupUsersService, GroupUsersService>()
.AddTransient<IPublicAvatarUsersService, PublicAvatarUsersService>()
.AddSingleton<AppConfigurationService>()
.AddHttpContextAccessor()
.AddMemoryCache()
.AddSingleton<IPasswordHasher, PasswordHasher>();
}
public static IServiceCollection socialPubMiddlewareConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubMiddlewareConfiguration(this IServiceCollection service)
{
return service
.AddEndpointsApiExplorer()
@ -203,7 +196,7 @@ namespace SocialPub.Middleware
}).Services;
}
public static IServiceCollection socialPubCORSConfiguration(this IServiceCollection service)
public static IServiceCollection PrivaPubCORSConfiguration(this IServiceCollection service)
{
return service.AddCors(options =>
{

View File

@ -1,8 +1,8 @@
using SocialPub.Models.ActivityPub.Extra;
using PrivaPub.Models.ActivityPub.Extra;
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubActivity))]
public class ActivityPubActivity : ActivityPubObject

View File

@ -1,8 +1,8 @@
using SocialPub.Models.ActivityPub.Extra;
using PrivaPub.Models.ActivityPub.Extra;
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubActor))]
public class ActivityPubActor : ActivityPubObject
@ -34,10 +34,10 @@ namespace SocialPub.Models.ActivityPub
public bool Discoverable { get; set; } = true;
[JsonPropertyName("publicKey")]
public ActivityPubPublicKey PublicKey { get; set; }
public ActivityPubPublicKey PublicKey { get; set; } = new();
[JsonPropertyName("endpoints")]
public ActivityPubActorEndpoints Endpoints { get; set; }
public ActivityPubActorEndpoints Endpoints { get; set; } = new();
[JsonPropertyName("attachment")]
public IEnumerable<ActivityPubAttachment> Attachment { get; set; } = Enumerable.Empty<ActivityPubAttachment>();

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubCollection))]
public class ActivityPubCollection : ActivityPubObject

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubCollectionPage))]
public class ActivityPubCollectionPage : ActivityPubCollection

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubLink))]
public class ActivityPubLink : ActivityPubObject

View File

@ -1,8 +1,8 @@
using SocialPub.Models.ActivityPub.Extra;
using PrivaPub.Models.ActivityPub.Extra;
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubObject))]
public partial class ActivityPubObject

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubOrderedCollection))]
public class ActivityPubOrderedCollection : ActivityPubCollection

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubOrderedCollectionPage))]
public class ActivityPubOrderedCollectionPage : ActivityPubCollection

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
[JsonSerializable(typeof(ActivityPubTombstone))]
public class ActivityPubTombstone : ActivityPubObject

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub.Extra
namespace PrivaPub.Models.ActivityPub.Extra
{
[JsonSerializable(typeof(ActivityPubPublicKey))]
public class ActivityPubAudience

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub.Extra
namespace PrivaPub.Models.ActivityPub.Extra
{
[JsonSerializable(typeof(ActivityPubPublicKey))]
public class ActivityPubIcon

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub.Extra
namespace PrivaPub.Models.ActivityPub.Extra
{
[JsonSerializable(typeof(ActivityPubPublicKey))]
public class ActivityPubInstrument

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub.Extra
namespace PrivaPub.Models.ActivityPub.Extra
{
[JsonSerializable(typeof(ActivityPubPublicKey))]
public class ActivityPubOrigin

View File

@ -1,6 +1,6 @@
using System.Text.Json.Serialization;
namespace SocialPub.Models.ActivityPub.Extra
namespace PrivaPub.Models.ActivityPub.Extra
{
[JsonSerializable(typeof(ActivityPubPublicKey))]
public class ActivityPubResult

View File

@ -1,4 +1,4 @@
namespace SocialPub.Models.ActivityPub
namespace PrivaPub.Models.ActivityPub
{
public enum MacroType
{

Some files were not shown because too many files have changed in this diff Show More