| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> GoogleLogin(GoogleApiModel model)
- {
- var response = await _service.Authenticate(model);
-
- if (response.IsError is true)
- return BadRequest(new { message = response.ErrorMessage });
-
- return Ok(response.Data);
- }
- }
-
- }
|