mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 20:40:07 +01:00
42 lines
988 B
C#
42 lines
988 B
C#
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" });
|
|
}
|
|
|
|
}
|