using Diligent.WebAPI.Contracts.DTOs.User; namespace Diligent.WebAPI.Host.Controllers.V1 { [ApiVersion("1.0")] [Route("v{version:apiVersion}/authentications")] [ApiController] public class AuthenticationsController : ControllerBase { private readonly IAuthenticationService _service; public AuthenticationsController(IAuthenticationService service) { _service = service; } [HttpGet("ForgotPassword")] public async Task ForgotPassword(string email) { var response = await _service.GetForgotPasswordUrlAsync(email); if (response.IsError is true) return BadRequest(new { message = response.ErrorMessage }); return Ok(response.Data); } [HttpPost("RessetPassword")] public async Task ResetPassword([FromBody] ResetPasswordModel model) { var response = await _service.PasswordResetAsync(email: model.Email, code: model.Code, password: model.Password); if (response.IsError is true) return BadRequest(new { message = response.ErrorMessage }); return Ok(response.Data); } [HttpPost("authenticate")] public async Task Authenticate([FromBody] AuthenticateRequestDto model) { var response = await _service.Authenticate(model); if (response.IsError is true) return BadRequest(new { message = response.ErrorMessage }); return Ok(response.Data); } [HttpPost("refresh")] public async Task RefreshToken([FromBody] RefreshTokenRequestDto model) { var response = await _service.RefreshTokenAsync(model); if (response.Error != null) { return BadRequest(new AuthFailedResponse { Error = response.Error }); } return Ok(response); } [HttpPost("logout")] public async Task Logout(int userId) { var response = await _service.DeleteRefreshToken(userId); if (response.IsError) { return BadRequest(new { message = response.ErrorMessage }); } return Ok(); } [HttpPost("authenticateGoogle")] public async Task GoogleLogin(GoogleApiModel model) { var response = await _service.Authenticate(model); if (response.IsError is true) return BadRequest(new { message = response.ErrorMessage }); return Ok(response.Data); } [HttpPost("register")] public async Task Register(RegisterDTO model) { var response = await _service.Register(model); if (response.IsError is true) return BadRequest(new { message = response.ErrorMessage }); return Ok(response.Data); } } }