Add server basic functions.
This commit is contained in:
parent
c332d15db6
commit
e3f673988f
@ -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
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
namespace Flawless.Communication.Authentication;
|
||||
|
||||
public record AuthenticationStatus
|
||||
{
|
||||
public required bool OpenRegister { get; set; }
|
||||
public required bool OpenLogin { get; set; }
|
||||
}
|
||||
10
Flawless.Communication/Authentication/LoginRequest.cs
Normal file
10
Flawless.Communication/Authentication/LoginRequest.cs
Normal file
@ -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; }
|
||||
}
|
||||
12
Flawless.Communication/Authentication/RegisterRequest.cs
Normal file
12
Flawless.Communication/Authentication/RegisterRequest.cs
Normal file
@ -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; }
|
||||
}
|
||||
10
Flawless.Communication/Authentication/RegisterResult.cs
Normal file
10
Flawless.Communication/Authentication/RegisterResult.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace Flawless.Communication.Authentication;
|
||||
|
||||
public enum RegisterResultStatus
|
||||
{
|
||||
Success,
|
||||
Forbidden,
|
||||
Registered
|
||||
}
|
||||
|
||||
public record RegisterResult(RegisterResultStatus Status);
|
||||
9
Flawless.Communication/Flawless.Communication.csproj
Normal file
9
Flawless.Communication/Flawless.Communication.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
6
Flawless.Core/BinaryDataFormat/DataInserter.cs
Normal file
6
Flawless.Core/BinaryDataFormat/DataInserter.cs
Normal file
@ -0,0 +1,6 @@
|
||||
namespace Flawless.Core.BinaryDataFormat;
|
||||
|
||||
public static class DataInserter
|
||||
{
|
||||
|
||||
}
|
||||
34
Flawless.Server/Controllers/AuthenticationController.cs
Normal file
34
Flawless.Server/Controllers/AuthenticationController.cs
Normal file
@ -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<AuthenticationController> logger)
|
||||
: ControllerBase
|
||||
{
|
||||
|
||||
[HttpGet("status")]
|
||||
public ActionResult<AuthenticationStatus> GetStatus()
|
||||
{
|
||||
logger.LogInformation("Authentication status has sent to {0}", HttpContext.Connection.RemoteIpAddress);
|
||||
return new AuthenticationStatus()
|
||||
{
|
||||
OpenRegister = true,
|
||||
OpenLogin = true,
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("register")]
|
||||
public async Task<ActionResult<RegisterResult>> RegisterAsync(RegisterRequest request)
|
||||
{
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
public async Task<ActionResult<string>> LoginAsync([FromBody] LoginRequest request)
|
||||
{
|
||||
return "SuccessToken";
|
||||
}
|
||||
}
|
||||
20
Flawless.Server/Controllers/DepotTransmissionController.cs
Normal file
20
Flawless.Server/Controllers/DepotTransmissionController.cs
Normal file
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
9
Flawless.Server/Controllers/RepositoryController.cs
Normal file
9
Flawless.Server/Controllers/RepositoryController.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Flawless.Server.Controllers;
|
||||
|
||||
[ApiController, Route("api/repository")]
|
||||
public class RepositoryController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
9
Flawless.Server/Controllers/UserController.cs
Normal file
9
Flawless.Server/Controllers/UserController.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Flawless.Server.Controllers;
|
||||
|
||||
[ApiController, Route("api/user")]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
|
||||
}
|
||||
26
Flawless.Server/Flawless.Server.csproj
Normal file
26
Flawless.Server/Flawless.Server.csproj
Normal file
@ -0,0 +1,26 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2"/>
|
||||
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Flawless.Abstract\Flawless.Abstract.csproj" />
|
||||
<ProjectReference Include="..\Flawless.Communication\Flawless.Communication.csproj" />
|
||||
<ProjectReference Include="..\Flawless.Core\Flawless.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
10
Flawless.Server/Models/FlawlessContext.cs
Normal file
10
Flawless.Server/Models/FlawlessContext.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Flawless.Server.Models;
|
||||
|
||||
public class FlawlessContext : DbContext
|
||||
{
|
||||
public FlawlessContext(DbContextOptions<FlawlessContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
}
|
||||
5
Flawless.Server/Models/FlawlessStorageContext.cs
Normal file
5
Flawless.Server/Models/FlawlessStorageContext.cs
Normal file
@ -0,0 +1,5 @@
|
||||
namespace Flawless.Server.Models;
|
||||
|
||||
public class FlawlessStorageContext(WebApplication app)
|
||||
{
|
||||
}
|
||||
54
Flawless.Server/Program.cs
Normal file
54
Flawless.Server/Program.cs
Normal file
@ -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<DepotTransmissionController>();
|
||||
builder.Services.AddDbContext<FlawlessContext>(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();
|
||||
23
Flawless.Server/Properties/launchSettings.json
Normal file
23
Flawless.Server/Properties/launchSettings.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Flawless.Server/appsettings.Development.json
Normal file
8
Flawless.Server/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Flawless.Server/appsettings.json
Normal file
9
Flawless.Server/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user