42 lines
1006 B
C#
42 lines
1006 B
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Trazo.Model;
|
|
|
|
namespace Trazo.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class AuthController(
|
|
SignInManager<User> _signInManager,
|
|
UserManager<User> _userManager,
|
|
IConfiguration _configuration
|
|
) : ControllerBase
|
|
{
|
|
|
|
[HttpPost("login")]
|
|
public async Task<IActionResult> Login([FromBody] LoginRequest request)
|
|
{
|
|
var result = await _signInManager.PasswordSignInAsync(
|
|
request.Email,
|
|
request.Password,
|
|
false,
|
|
false);
|
|
|
|
if (!result.Succeeded)
|
|
return Unauthorized();
|
|
|
|
// Generate your JWT here
|
|
return Ok(new { token = "your-jwt-token" });
|
|
}
|
|
|
|
[Authorize]
|
|
[HttpPost("logout")]
|
|
public async Task<IActionResult> Logout()
|
|
{
|
|
await _signInManager.SignOutAsync();
|
|
return Ok();
|
|
}
|
|
}
|