2024-04-17 15:49:34 +03:30
|
|
|
|
using Back.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Shared.DTOs;
|
|
|
|
|
|
|
|
|
|
namespace Back.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
2024-04-18 00:33:46 +03:30
|
|
|
|
[Authorize]
|
2024-04-17 15:49:34 +03:30
|
|
|
|
[ApiController]
|
|
|
|
|
public class UserController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly servUser _servUser;
|
|
|
|
|
public UserController(servUser servUser)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_servUser = servUser;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
[HttpPost("authenticate")]
|
|
|
|
|
[AllowAnonymous]
|
2024-04-18 00:33:46 +03:30
|
|
|
|
public async Task<ActionResult<UserAuthenticationDTO>> Login([FromBody]Authentication model)
|
2024-04-17 15:49:34 +03:30
|
|
|
|
{
|
|
|
|
|
var result = await _servUser.UserAuthentication(model.Username, model.Password);
|
|
|
|
|
if (result != null) return Ok(result);
|
|
|
|
|
else return NotFound("کاربری با این مشخصات یافت نشد");
|
2024-04-18 00:33:46 +03:30
|
|
|
|
}
|
2024-04-18 18:26:12 +03:30
|
|
|
|
[HttpGet("CheckAuthenticate")]
|
|
|
|
|
public async Task<ActionResult<UserAuthenticationDTO>> CheckAuthenticate()
|
2024-04-18 00:33:46 +03:30
|
|
|
|
{
|
2024-04-18 18:26:12 +03:30
|
|
|
|
// var accessToken = Request.Headers["Authorization"].ToString().Split(' ')[1];
|
2024-04-17 15:49:34 +03:30
|
|
|
|
|
2024-04-18 18:26:12 +03:30
|
|
|
|
var claim = HttpContext.User.Claims.First(c => c.Type == "UserID");
|
|
|
|
|
var UserID = claim.Value;
|
|
|
|
|
var result = await _servUser.UserAuthentication(UserID,newtoken:false);
|
|
|
|
|
return Ok(result);
|
2024-04-17 15:49:34 +03:30
|
|
|
|
|
|
|
|
|
}
|
2024-04-18 18:26:12 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-04-17 15:49:34 +03:30
|
|
|
|
}
|
|
|
|
|
}
|