mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-17 01:00:07 +01:00
feat: offload jwt generation to guhf, move auth code to new controller
This commit is contained in:
41
Controllers/AuthController.cs
Normal file
41
Controllers/AuthController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using QuotifyBE.Data;
|
||||
using QuotifyBE.DTOs;
|
||||
|
||||
namespace QuotifyBE.Controllers;
|
||||
|
||||
|
||||
[ApiController]
|
||||
[Route("api/v1/auth")]
|
||||
public class AuthController : ControllerBase
|
||||
{
|
||||
|
||||
private readonly IConfiguration _appsettings;
|
||||
private readonly ApplicationDbContext _db;
|
||||
|
||||
public AuthController(IConfiguration appsettings, ApplicationDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
_appsettings = appsettings;
|
||||
}
|
||||
|
||||
[HttpPost("login")]
|
||||
public IActionResult Login([FromBody] UserLoginDTO user, GeneralUseHelpers guhf)
|
||||
{
|
||||
if (user.Email == "admin" && user.Password == "password")
|
||||
{
|
||||
var token = guhf.GenerateJwtToken(user.Email, _appsettings);
|
||||
return Ok(new { token });
|
||||
}
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
[HttpGet("some_values")]
|
||||
[Authorize]
|
||||
public IActionResult GetValues()
|
||||
{
|
||||
return Ok(new string[] { "value1", "value2" });
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user