diff --git a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Controllers/AuthController.cs b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Controllers/AuthController.cs index eae79d9..c1eb121 100644 --- a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Controllers/AuthController.cs +++ b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Controllers/AuthController.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Mvc; +using Suspectus.Gandalf.Bridgekeeper.Contracts.Controller.Auth; namespace Suspectus.Gandalf.Bridgekeeper.Api.Controllers; @@ -12,13 +13,29 @@ public class AuthController : ControllerBase return Ok(true); } - [HttpGet("[action]")] - public async Task Login() + [HttpPost("[action]")] + public async Task Login([FromBody] LoginCommand loginCommand) { - return Ok(true); + Response.Cookies.Append("MithrandirSession", loginCommand.UsernameOrEmail, new CookieOptions + { + Secure = true, + HttpOnly = true, + SameSite = SameSiteMode.Lax, + Expires = DateTime.UtcNow.AddMinutes(30) + }); + + return Ok(); } [HttpGet("[action]")] + public async Task Logout() + { + Response.Cookies.Delete("MithrandirSession"); + + return Ok(); + } + + [HttpPost("[action]")] public async Task Register() { return Ok(true); diff --git a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Program.cs b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Program.cs index 7688653..0e90986 100644 --- a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Program.cs +++ b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Program.cs @@ -1,23 +1,16 @@ var builder = WebApplication.CreateBuilder(args); -// Add services to the container. - builder.Services.AddControllers(); -// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi builder.Services.AddOpenApi(); var app = builder.Build(); -// Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); } app.UseHttpsRedirection(); - app.UseAuthorization(); - app.MapControllers(); - app.Run(); \ No newline at end of file diff --git a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Suspectus.Gandalf.Bridgekeeper.Api.csproj b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Suspectus.Gandalf.Bridgekeeper.Api.csproj index 34507d4..0be938e 100644 --- a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Suspectus.Gandalf.Bridgekeeper.Api.csproj +++ b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Api/Suspectus.Gandalf.Bridgekeeper.Api.csproj @@ -11,4 +11,13 @@ + + + + + + + + + diff --git a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Controller/Auth/LoginCommand.cs b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Controller/Auth/LoginCommand.cs new file mode 100644 index 0000000..3b08c5f --- /dev/null +++ b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Controller/Auth/LoginCommand.cs @@ -0,0 +1,9 @@ +using Suspectus.Gandalf.Core.Abstractions.CQRS; + +namespace Suspectus.Gandalf.Bridgekeeper.Contracts.Controller.Auth; + +public class LoginCommand : ICommand +{ + public required string UsernameOrEmail { get; set; } + public required string Password { get; set; } +} \ No newline at end of file diff --git a/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Suspectus.Gandalf.Bridgekeeper.Contracts.csproj b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Suspectus.Gandalf.Bridgekeeper.Contracts.csproj new file mode 100644 index 0000000..3553e7f --- /dev/null +++ b/src/dotnet/Suspectus.Gandalf.Bridgekeeper.Contracts/Suspectus.Gandalf.Bridgekeeper.Contracts.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/src/dotnet/Suspectus.Gandalf.Core.Abstractions/CQRS/ICommand.cs b/src/dotnet/Suspectus.Gandalf.Core.Abstractions/CQRS/ICommand.cs new file mode 100644 index 0000000..be4d069 --- /dev/null +++ b/src/dotnet/Suspectus.Gandalf.Core.Abstractions/CQRS/ICommand.cs @@ -0,0 +1,6 @@ +using LanguageExt.Common; +using MediatR; + +namespace Suspectus.Gandalf.Core.Abstractions.CQRS; + +public interface ICommand : IRequest>; \ No newline at end of file diff --git a/src/dotnet/Suspectus.Gandalf.Core.Abstractions/Suspectus.Gandalf.Core.Abstractions.csproj b/src/dotnet/Suspectus.Gandalf.Core.Abstractions/Suspectus.Gandalf.Core.Abstractions.csproj new file mode 100644 index 0000000..179a9cd --- /dev/null +++ b/src/dotnet/Suspectus.Gandalf.Core.Abstractions/Suspectus.Gandalf.Core.Abstractions.csproj @@ -0,0 +1,14 @@ + + + + net9.0 + enable + enable + + + + + + + + diff --git a/src/dotnet/Suspectus.Gandalf.sln b/src/dotnet/Suspectus.Gandalf.sln index 0bdda57..6037e87 100644 --- a/src/dotnet/Suspectus.Gandalf.sln +++ b/src/dotnet/Suspectus.Gandalf.sln @@ -16,6 +16,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Suspectus.Gandalf.Bridgekee EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{3E672AE3-D2E4-49C0-AB18-65E799E5277A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Suspectus.Gandalf.Core.Abstractions", "Suspectus.Gandalf.Core.Abstractions\Suspectus.Gandalf.Core.Abstractions.csproj", "{F8333692-CA81-4298-A2F5-CF7D3ACCE230}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Suspectus.Gandalf.Bridgekeeper.Contracts", "Suspectus.Gandalf.Bridgekeeper.Contracts\Suspectus.Gandalf.Bridgekeeper.Contracts.csproj", "{4ED2E3BC-FE29-4041-8274-987EB60BD5FF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,6 +46,14 @@ Global {264B8A9E-7A70-4DE3-906B-7E0722D09205}.Debug|Any CPU.Build.0 = Debug|Any CPU {264B8A9E-7A70-4DE3-906B-7E0722D09205}.Release|Any CPU.ActiveCfg = Release|Any CPU {264B8A9E-7A70-4DE3-906B-7E0722D09205}.Release|Any CPU.Build.0 = Release|Any CPU + {F8333692-CA81-4298-A2F5-CF7D3ACCE230}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8333692-CA81-4298-A2F5-CF7D3ACCE230}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8333692-CA81-4298-A2F5-CF7D3ACCE230}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8333692-CA81-4298-A2F5-CF7D3ACCE230}.Release|Any CPU.Build.0 = Release|Any CPU + {4ED2E3BC-FE29-4041-8274-987EB60BD5FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4ED2E3BC-FE29-4041-8274-987EB60BD5FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4ED2E3BC-FE29-4041-8274-987EB60BD5FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4ED2E3BC-FE29-4041-8274-987EB60BD5FF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {44C283FD-2E01-496C-9E8F-4E43C26C9733} = {A82EA24B-1379-41B2-A363-CDCBF9F18833} @@ -49,5 +61,7 @@ Global {B4AF6985-3268-4C2E-9C50-D92DA7D3711D} = {A82EA24B-1379-41B2-A363-CDCBF9F18833} {C8C3047B-ED0B-4516-A282-8B07E3EEB430} = {A82EA24B-1379-41B2-A363-CDCBF9F18833} {264B8A9E-7A70-4DE3-906B-7E0722D09205} = {D54D8A40-A5C3-4273-B4D7-F2B83056161B} + {F8333692-CA81-4298-A2F5-CF7D3ACCE230} = {3E672AE3-D2E4-49C0-AB18-65E799E5277A} + {4ED2E3BC-FE29-4041-8274-987EB60BD5FF} = {D54D8A40-A5C3-4273-B4D7-F2B83056161B} EndGlobalSection EndGlobal