Initial commit with inital CMS
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SlpModularCms.Core.Identity.Models;
|
||||
using SlpModularCms.Core.Identity.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
private readonly IAuthService _authService;
|
||||
|
||||
public AuthController(IAuthService authService)
|
||||
{
|
||||
_authService = authService;
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> Login([FromBody] LoginRequest request)
|
||||
{
|
||||
var response = await _authService.AuthenticateAsync(request.Email, request.Password);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpPost("refresh")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> Refresh([FromBody] RefreshTokenRequest request)
|
||||
{
|
||||
var response = await _authService.RefreshTokenAsync(request.AccessToken, request.RefreshToken);
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpPost("revoke")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> Revoke([FromBody] string refreshToken)
|
||||
{
|
||||
await _authService.RevokeTokenAsync(refreshToken);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SlpModularCms.Core.Identity.Models;
|
||||
using SlpModularCms.Core.Identity.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class SetupController : ControllerBase
|
||||
{
|
||||
private readonly ISetupService _setupService;
|
||||
|
||||
public SetupController(ISetupService setupService)
|
||||
{
|
||||
_setupService = setupService;
|
||||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
public async Task<IActionResult> GetStatus()
|
||||
{
|
||||
var initialized = await _setupService.IsSystemInitializedAsync();
|
||||
return Ok(new { Initialized = initialized });
|
||||
}
|
||||
|
||||
[HttpPost("owner")]
|
||||
public async Task<IActionResult> CreateOwner([FromBody] CreateOwnerRequest request)
|
||||
{
|
||||
await _setupService.CreateInitialOwnerAsync(request.Email, request.Password);
|
||||
return Ok(new { Message = "Systeem succesvol geïnitialiseerd. De eerste eigenaar is aangemaakt." });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SlpModularCms.Core.Identity.Models;
|
||||
using SlpModularCms.Core.Identity.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private readonly IInvitationService _invitationService;
|
||||
|
||||
public UsersController(IInvitationService invitationService)
|
||||
{
|
||||
_invitationService = invitationService;
|
||||
}
|
||||
|
||||
[HttpPost("invite")]
|
||||
[Authorize(Policy = "AdminOnly")]
|
||||
public async Task<IActionResult> Invite([FromBody] InviteUserRequest request)
|
||||
{
|
||||
var token = await _invitationService.CreateInvitationAsync(request.Email, request.Role);
|
||||
// In een echte app zou je hier een email sturen. Voor nu geven we de link terug.
|
||||
var inviteLink = $"/setup/complete?token={Uri.EscapeDataString(token)}";
|
||||
return Ok(new { InviteLink = inviteLink });
|
||||
}
|
||||
|
||||
[HttpPost("complete-setup")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> CompleteSetup([FromBody] CompleteSetupRequest request)
|
||||
{
|
||||
await _invitationService.CompleteInvitationAsync(request.Token, request.Password);
|
||||
return Ok(new { Message = "Account succesvol ingesteld. Je kunt nu inloggen." });
|
||||
}
|
||||
|
||||
[HttpGet("validate-invitation")]
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> ValidateInvitation([FromQuery] string token)
|
||||
{
|
||||
var isValid = await _invitationService.ValidateInvitationAsync(token);
|
||||
return Ok(new { Valid = isValid });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SlpModularCms.Core.Modules;
|
||||
|
||||
namespace SlpModularCms.Modules.Identity;
|
||||
|
||||
public class IdentityModule : IModule
|
||||
{
|
||||
public string Name => "Identity";
|
||||
public string Version => "1.0.0";
|
||||
|
||||
public void RegisterServices(IServiceCollection services)
|
||||
{
|
||||
// Specifieke services voor deze module (indien niet al in Core)
|
||||
}
|
||||
|
||||
public void UseModule(IApplicationBuilder app)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SlpModularCms.Core\SlpModularCms.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user