diff --git a/Flawless-Version-Control.sln b/Flawless-Version-Control.sln index d5acfa6..3b01626 100644 --- a/Flawless-Version-Control.sln +++ b/Flawless-Version-Control.sln @@ -6,6 +6,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Abstract.Test", "F EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Core", "Flawless.Core\Flawless.Core.csproj", "{FA8139D0-FBA4-4F17-9017-B446A732D0E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Communication", "Flawless.Communication\Flawless.Communication.csproj", "{E0C2A8CE-D382-4DF2-9675-1A41833B30F2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Flawless.Server", "Flawless.Server\Flawless.Server.csproj", "{66142212-034C-4702-92FE-5C625D725048}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +28,13 @@ Global {FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {FA8139D0-FBA4-4F17-9017-B446A732D0E8}.Release|Any CPU.Build.0 = Release|Any CPU + {E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0C2A8CE-D382-4DF2-9675-1A41833B30F2}.Release|Any CPU.Build.0 = Release|Any CPU + {66142212-034C-4702-92FE-5C625D725048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {66142212-034C-4702-92FE-5C625D725048}.Debug|Any CPU.Build.0 = Debug|Any CPU + {66142212-034C-4702-92FE-5C625D725048}.Release|Any CPU.ActiveCfg = Release|Any CPU + {66142212-034C-4702-92FE-5C625D725048}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Flawless.Communication/Authentication/AuthenticationStatus.cs b/Flawless.Communication/Authentication/AuthenticationStatus.cs new file mode 100644 index 0000000..55632f1 --- /dev/null +++ b/Flawless.Communication/Authentication/AuthenticationStatus.cs @@ -0,0 +1,7 @@ +namespace Flawless.Communication.Authentication; + +public record AuthenticationStatus +{ + public required bool OpenRegister { get; set; } + public required bool OpenLogin { get; set; } +} \ No newline at end of file diff --git a/Flawless.Communication/Authentication/LoginRequest.cs b/Flawless.Communication/Authentication/LoginRequest.cs new file mode 100644 index 0000000..c970aff --- /dev/null +++ b/Flawless.Communication/Authentication/LoginRequest.cs @@ -0,0 +1,10 @@ +namespace Flawless.Communication.Authentication; + +public record LoginRequest +{ + public required string Identification { get; init; } + + public required string Password { get; init; } + + public required bool DontExpireHalfMonth { get; set; } +} \ No newline at end of file diff --git a/Flawless.Communication/Authentication/RegisterRequest.cs b/Flawless.Communication/Authentication/RegisterRequest.cs new file mode 100644 index 0000000..f391d98 --- /dev/null +++ b/Flawless.Communication/Authentication/RegisterRequest.cs @@ -0,0 +1,12 @@ +namespace Flawless.Communication.Authentication; + +public record RegisterRequest +{ + public required string Email { get; set; } + + public required string Username { get; set; } + + public required string Password { get; set; } + + public required bool DontExpireHalfMonth { get; set; } +} \ No newline at end of file diff --git a/Flawless.Communication/Authentication/RegisterResult.cs b/Flawless.Communication/Authentication/RegisterResult.cs new file mode 100644 index 0000000..5f2009c --- /dev/null +++ b/Flawless.Communication/Authentication/RegisterResult.cs @@ -0,0 +1,10 @@ +namespace Flawless.Communication.Authentication; + +public enum RegisterResultStatus +{ + Success, + Forbidden, + Registered +} + +public record RegisterResult(RegisterResultStatus Status); \ No newline at end of file diff --git a/Flawless.Communication/Flawless.Communication.csproj b/Flawless.Communication/Flawless.Communication.csproj new file mode 100644 index 0000000..17b910f --- /dev/null +++ b/Flawless.Communication/Flawless.Communication.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/Flawless.Core/BinaryDataFormat/DataInserter.cs b/Flawless.Core/BinaryDataFormat/DataInserter.cs new file mode 100644 index 0000000..05bb892 --- /dev/null +++ b/Flawless.Core/BinaryDataFormat/DataInserter.cs @@ -0,0 +1,6 @@ +namespace Flawless.Core.BinaryDataFormat; + +public static class DataInserter +{ + +} \ No newline at end of file diff --git a/Flawless.Server/Controllers/AuthenticationController.cs b/Flawless.Server/Controllers/AuthenticationController.cs new file mode 100644 index 0000000..cde589b --- /dev/null +++ b/Flawless.Server/Controllers/AuthenticationController.cs @@ -0,0 +1,34 @@ +using Flawless.Communication.Authentication; +using Flawless.Server.Models; +using Microsoft.AspNetCore.Mvc; + +namespace Flawless.Server.Controllers; + +[ApiController, Route("api/auth")] +public class AuthenticationController(FlawlessContext dbContext, ILogger logger) + : ControllerBase +{ + + [HttpGet("status")] + public ActionResult GetStatus() + { + logger.LogInformation("Authentication status has sent to {0}", HttpContext.Connection.RemoteIpAddress); + return new AuthenticationStatus() + { + OpenRegister = true, + OpenLogin = true, + }; + } + + [HttpPost("register")] + public async Task> RegisterAsync(RegisterRequest request) + { + return BadRequest(); + } + + [HttpPost("login")] + public async Task> LoginAsync([FromBody] LoginRequest request) + { + return "SuccessToken"; + } +} \ No newline at end of file diff --git a/Flawless.Server/Controllers/DepotTransmissionController.cs b/Flawless.Server/Controllers/DepotTransmissionController.cs new file mode 100644 index 0000000..dd7dd18 --- /dev/null +++ b/Flawless.Server/Controllers/DepotTransmissionController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Flawless.Server.Controllers; + +[ApiController] +[Route("ws/depot/transmission")] +public class DepotTransmissionController : ControllerBase +{ + [Route("download/{requestId}")] + public async Task DownloadDepotAsync(string requestId) + { + + } + + [Route("upload/{requestId}")] + public async Task UploadDepotAsync(string requestId) + { + + } +} \ No newline at end of file diff --git a/Flawless.Server/Controllers/RepositoryController.cs b/Flawless.Server/Controllers/RepositoryController.cs new file mode 100644 index 0000000..e734d5d --- /dev/null +++ b/Flawless.Server/Controllers/RepositoryController.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Flawless.Server.Controllers; + +[ApiController, Route("api/repository")] +public class RepositoryController : ControllerBase +{ + +} \ No newline at end of file diff --git a/Flawless.Server/Controllers/UserController.cs b/Flawless.Server/Controllers/UserController.cs new file mode 100644 index 0000000..0343c5c --- /dev/null +++ b/Flawless.Server/Controllers/UserController.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Flawless.Server.Controllers; + +[ApiController, Route("api/user")] +public class UserController : ControllerBase +{ + +} \ No newline at end of file diff --git a/Flawless.Server/Flawless.Server.csproj b/Flawless.Server/Flawless.Server.csproj new file mode 100644 index 0000000..62e62b5 --- /dev/null +++ b/Flawless.Server/Flawless.Server.csproj @@ -0,0 +1,26 @@ + + + + net9.0 + enable + enable + + + + + + + + + + + + + + + + + + + + diff --git a/Flawless.Server/Models/FlawlessContext.cs b/Flawless.Server/Models/FlawlessContext.cs new file mode 100644 index 0000000..1da3d46 --- /dev/null +++ b/Flawless.Server/Models/FlawlessContext.cs @@ -0,0 +1,10 @@ +using Microsoft.EntityFrameworkCore; + +namespace Flawless.Server.Models; + +public class FlawlessContext : DbContext +{ + public FlawlessContext(DbContextOptions options) : base(options) + { + } +} \ No newline at end of file diff --git a/Flawless.Server/Models/FlawlessStorageContext.cs b/Flawless.Server/Models/FlawlessStorageContext.cs new file mode 100644 index 0000000..3177eea --- /dev/null +++ b/Flawless.Server/Models/FlawlessStorageContext.cs @@ -0,0 +1,5 @@ +namespace Flawless.Server.Models; + +public class FlawlessStorageContext(WebApplication app) +{ +} \ No newline at end of file diff --git a/Flawless.Server/Program.cs b/Flawless.Server/Program.cs new file mode 100644 index 0000000..e9e8671 --- /dev/null +++ b/Flawless.Server/Program.cs @@ -0,0 +1,54 @@ +using Flawless.Server.Controllers; +using Flawless.Server.Models; +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// Api related +builder.Services.AddOpenApi(); +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(opt => +{ + opt.DocInclusionPredicate((name, api) => api.HttpMethod != null); // Filter out WebSocket methods + opt.SupportNonNullableReferenceTypes(); +}); + +// Authentication related. +builder.Services.AddAuthentication(opt => +{ + opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; +}).AddJwtBearer(opt => +{ + +}); + +// Data connection related. +builder.Services.AddSingleton(); +builder.Services.AddDbContext(opt => +{ + opt.UseInMemoryDatabase("Flawless"); +}); + +var app = builder.Build(); + +app.UseRouting(); +app.UseAuthentication(); +app.UseAuthorization(); +app.UseWebSockets(new WebSocketOptions +{ + KeepAliveInterval = TimeSpan.FromSeconds(60), + KeepAliveTimeout = TimeSpan.FromSeconds(300), +}); +app.MapControllers(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); + app.UseSwagger(); + app.UseSwaggerUI(); +} +app.Run(); diff --git a/Flawless.Server/Properties/launchSettings.json b/Flawless.Server/Properties/launchSettings.json new file mode 100644 index 0000000..28ec8b4 --- /dev/null +++ b/Flawless.Server/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5256", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7020;http://localhost:5256", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Flawless.Server/appsettings.Development.json b/Flawless.Server/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Flawless.Server/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Flawless.Server/appsettings.json b/Flawless.Server/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Flawless.Server/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}