55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Flexitime.Objects;
|
|
using FlexitimeAPI.Helpers;
|
|
using FlexitimeAPI.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace FlexitimeAPI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class AuthenticationController : ControllerBase
|
|
{
|
|
private readonly IUserService _userService;
|
|
|
|
public AuthenticationController(IUserService userService)
|
|
{
|
|
_userService = userService;
|
|
}
|
|
|
|
[Route("login")]
|
|
[HttpPost]
|
|
public async Task<IActionResult> Authenticate(LoginRequest model)
|
|
{
|
|
var response = await _userService.Authenticate(model);
|
|
|
|
if (response == null)
|
|
return BadRequest(new { message = "Username or password is incorrect" });
|
|
|
|
return Ok(response);
|
|
}
|
|
|
|
[Authorize]
|
|
[Route("logout")]
|
|
[HttpGet]
|
|
public IActionResult Logout()
|
|
{
|
|
//should be able to get the id here and log a message of that user logging out..
|
|
return Ok();
|
|
}
|
|
|
|
[Route("token")]
|
|
[HttpPost]
|
|
public IActionResult TokenAuthenticationRequest(TokenLoginRequest model)
|
|
{
|
|
throw new NotImplementedException();
|
|
var response = _userService.Authenticate(model);
|
|
|
|
if (response == null)
|
|
return BadRequest(new { message = "Username or password is incorrect" });
|
|
|
|
return Ok(response);
|
|
}
|
|
}
|
|
} |