AuthController.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Identity;
  3. using Microsoft.AspNetCore.Mvc;
  4. using MTWorkHR.Application.Filters;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Models;
  7. using MTWorkHR.Core.Global;
  8. using MTWorkHR.Identity.Services;
  9. namespace MTWorkHR.API.Controllers
  10. {
  11. [Route("api/[controller]")]
  12. [ApiController]
  13. public class AuthController : ControllerBase
  14. {
  15. private readonly IAuthService _authenticationService;
  16. private readonly IUserService _userService;
  17. public AuthController(IAuthService authenticationService, IUserService userService)
  18. {
  19. _authenticationService = authenticationService;
  20. _userService = userService;
  21. }
  22. [HttpPost("login")]
  23. public async Task<ActionResult<AuthResponse>> Login(AuthRequest request)
  24. {
  25. return Ok( await _authenticationService.Login(request));
  26. }
  27. [HttpPost("register")]
  28. public async Task<ActionResult<UserDto>> Register([FromBody] UserDto input)
  29. {
  30. return await _userService.Create(input);
  31. }
  32. //[HttpPost("IsExpiredToken")]
  33. //[ProducesResponseType(StatusCodes.Status200OK)]
  34. //public async Task<bool> IsExpiredToken([FromBody] ForgetPasswordDto model)
  35. //{
  36. // return await _userService.IsExpiredToken(model);
  37. //}
  38. [HttpPost("forgetPasswordMail")]
  39. [ProducesResponseType(StatusCodes.Status200OK)]
  40. public async Task ForgetPasswordMail(string userId)
  41. {
  42. await _userService.ForgetPasswordMail(userId);
  43. }
  44. [HttpPost("forgetPassword")]
  45. [ProducesResponseType(StatusCodes.Status200OK)]
  46. public async Task<bool> ForgetPassword([FromBody] ForgetPasswordDto model)
  47. {
  48. return await _userService.ForgetPassword(model);
  49. }
  50. [HttpGet("confirmEmail")]
  51. [ProducesResponseType(StatusCodes.Status200OK)]
  52. public async Task<bool> ConfirmEmail(ForgetPasswordDto model)
  53. {
  54. var result = await _userService.ConfirmEmail(model);
  55. return result;
  56. }
  57. }
  58. }