update .net, setup modern logging
Some checks failed
Build and Publish / Build Yale Access Backend (pull_request) Failing after 1m28s
Build and Publish / Push Yale Access Backend Docker Image (pull_request) Has been skipped
Build and Publish / Build Yale Access Frontend (pull_request) Successful in 1m42s
Build and Publish / Push Yale Access Frontend Docker Image (pull_request) Has been skipped

This commit is contained in:
2026-02-18 08:48:15 +11:00
parent f577617b4d
commit 6d5749acd3
9 changed files with 84 additions and 122 deletions

View File

@@ -4,7 +4,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Serilog;
using System.Security.Claims;
using YaleAccess.Models;
@@ -14,15 +13,8 @@ namespace YaleAccess.Controllers
[Route("api/[controller]")]
[EnableCors]
[Authorize]
public class AuthenticationController : ControllerBase
public class AuthenticationController(IOptions<Models.Options.AuthenticationOptions> authenticationOptions, ILogger<AuthenticationController> logger) : ControllerBase
{
private readonly Models.Options.AuthenticationOptions _authenticationOptions;
public AuthenticationController(IOptions<Models.Options.AuthenticationOptions> authenticationOptions)
{
_authenticationOptions = authenticationOptions.Value;
}
[HttpPost("login")]
[AllowAnonymous]
public async Task<IActionResult> Login([FromBody] string password)
@@ -30,7 +22,7 @@ namespace YaleAccess.Controllers
try
{
// Check if the password is correct
if (password != _authenticationOptions.Password)
if (password != authenticationOptions.Value.Password)
{
return Unauthorized(new ApiResponse("Incorrect password."));
}
@@ -50,7 +42,7 @@ namespace YaleAccess.Controllers
}
catch(Exception ex)
{
Log.Logger.Error(ex, "An error occurred logging in.");
logger.LogError(ex, "An error occurred logging in.");
return BadRequest(new ApiResponse("An error occurred logging in."));
}
}
@@ -68,7 +60,7 @@ namespace YaleAccess.Controllers
}
catch (Exception ex)
{
Log.Logger.Error(ex, "An error occured logging out.");
logger.LogError(ex, "An error occured logging out.");
return BadRequest(new ApiResponse("An error occured logging out."));
}
}