session
This commit is contained in:
parent
baea64229b
commit
0dc41337da
36 changed files with 324 additions and 95 deletions
|
@ -1,4 +1,7 @@
|
|||
using Femto.Modules.Authentication.Application;
|
||||
using Femto.Api.Sessions;
|
||||
using Femto.Modules.Auth.Application;
|
||||
using Femto.Modules.Auth.Application.Commands.Login;
|
||||
using Femto.Modules.Auth.Application.Commands.Register;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Femto.Api.Controllers.Auth;
|
||||
|
@ -10,23 +13,31 @@ public class AuthController(IAuthenticationModule authModule) : ControllerBase
|
|||
[HttpPost("login")]
|
||||
public async Task<ActionResult<LoginResponse>> Login([FromBody] LoginRequest request)
|
||||
{
|
||||
|
||||
var userId = await authModule.PostCommand(new LoginCommand(request.Username, request.Password));
|
||||
var result = await authModule.PostCommand(
|
||||
new LoginCommand(request.Username, request.Password)
|
||||
);
|
||||
|
||||
HttpContext.SetSession(result.Session);
|
||||
|
||||
throw new NotImplementedException();
|
||||
return new LoginResponse(result.UserId, result.Username);
|
||||
}
|
||||
|
||||
[HttpPost("signup")]
|
||||
public async Task<ActionResult<SignupResponse>> Signup([FromBody] SignupRequest request)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
var result = await authModule.PostCommand(
|
||||
new RegisterCommand(request.Username, request.Password)
|
||||
);
|
||||
|
||||
HttpContext.SetSession(result.Session);
|
||||
|
||||
return new SignupResponse(result.UserId, result.Username);
|
||||
}
|
||||
|
||||
[HttpPost("delete-session")]
|
||||
public async Task<ActionResult> DeleteSession([FromBody] DeleteSessionRequest request)
|
||||
{
|
||||
// TODO
|
||||
return Ok(new {});
|
||||
return Ok(new { });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
namespace Femto.Api.Controllers.Auth;
|
||||
|
||||
public record LoginResponse(Guid UserId, string Username, string SessionToken);
|
||||
public record LoginResponse(Guid UserId, string Username);
|
|
@ -1,3 +1,3 @@
|
|||
namespace Femto.Api.Controllers.Auth;
|
||||
|
||||
public record SignupResponse(Guid UserId, string Username, string SessionToken);
|
||||
public record SignupResponse(Guid UserId, string Username);
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Femto.Modules.Blog\Femto.Modules.Blog.csproj" />
|
||||
<ProjectReference Include="..\Femto.Modules.Authentication\Femto.Modules.Authentication.csproj" />
|
||||
<ProjectReference Include="..\Femto.Modules.Auth\Femto.Modules.Auth.csproj" />
|
||||
<ProjectReference Include="..\Femto.Modules.Media\Femto.Modules.Media.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Femto.Modules.Authentication.Application;
|
||||
using Femto.Modules.Auth.Application;
|
||||
using Femto.Modules.Blog.Application;
|
||||
using Femto.Modules.Media.Application;
|
||||
|
||||
|
|
21
Femto.Api/Sessions/HttpContextSessionExtensions.cs
Normal file
21
Femto.Api/Sessions/HttpContextSessionExtensions.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Femto.Modules.Auth.Application.Dto;
|
||||
|
||||
namespace Femto.Api.Sessions;
|
||||
|
||||
internal static class HttpContextSessionExtensions
|
||||
{
|
||||
public static void SetSession(this HttpContext httpContext, Session session)
|
||||
{
|
||||
httpContext.Response.Cookies.Append(
|
||||
"session",
|
||||
session.SessionId,
|
||||
new CookieOptions
|
||||
{
|
||||
HttpOnly = true,
|
||||
Secure = true,
|
||||
SameSite = SameSiteMode.Strict,
|
||||
Expires = session.Expires,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue