68 lines
2.6 KiB
C#
68 lines
2.6 KiB
C#
using Application.Endpoints;
|
|
using Application.Endpoints.Authorization.RefreshToken;
|
|
using Application.Endpoints.Authorization.UserLogin;
|
|
using Application.Endpoints.Authorization.UserRegister;
|
|
using Application.Endpoints.Authorization.UserResetPassword;
|
|
using Application.Services.Database.PostgreSQL;
|
|
using Application.Services.Email;
|
|
using Application.Services.Encryption;
|
|
using Application.Services.Jwt;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace API.Controllers;
|
|
|
|
[Route("api/[controller]")]
|
|
public class AuthorizationController(
|
|
IEmailService emailService,
|
|
IJwtService jwtService,
|
|
IPatientRepository patientRepository,
|
|
IDoctorRepository doctorRepository,
|
|
IAdminRepository adminRepository,
|
|
IEncryptionService encryptionService)
|
|
: BaseApiController
|
|
{
|
|
[Authorize(Policy = Policies.AnonymousPolicy)]
|
|
[HttpPost("login")]
|
|
public async Task<ActionResult<BaseResponse>> Login(UserLoginCommand request, CancellationToken token)
|
|
{
|
|
var handler = new UserLoginHandler(jwtService, encryptionService, doctorRepository,
|
|
patientRepository, adminRepository);
|
|
|
|
var result = await handler.Handle(request, token);
|
|
return StatusCode(result.StatusCode, result);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.AnonymousPolicy)]
|
|
[HttpPost("register")]
|
|
public async Task<ActionResult<BaseResponse>> Register(UserRegisterCommand request, CancellationToken token)
|
|
{
|
|
var handler = new UserRegisterHandler(emailService, encryptionService, doctorRepository,
|
|
patientRepository, adminRepository);
|
|
|
|
var result = await handler.Handle(request, token);
|
|
return StatusCode(result.StatusCode, result);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.AnonymousPolicy)]
|
|
[HttpPost("reset_password")]
|
|
public async Task<ActionResult<BaseResponse>> ResetPassword(UserResetPasswordCommand request,
|
|
CancellationToken token)
|
|
{
|
|
var handler = new UserResetPasswordHandler(emailService, encryptionService, doctorRepository,
|
|
patientRepository, adminRepository);
|
|
|
|
var result = await handler.Handle(request, token);
|
|
return StatusCode(result.StatusCode, result);
|
|
}
|
|
|
|
[Authorize(Policy = Policies.AnonymousPolicy)]
|
|
[HttpPost("refresh_token")]
|
|
public async Task<ActionResult<BaseResponse>> RefreshToken([FromBody] RefreshJwtCommand request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var handler = new RefreshJwtHandler(jwtService);
|
|
var result = await handler.Handle(request, cancellationToken);
|
|
return StatusCode(result.StatusCode, result);
|
|
}
|
|
} |