2024-01-16 07:03:35 +00:00
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
2023-08-19 00:15:02 +00:00
|
|
|
namespace BotSharp.OpenAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
[ApiController]
|
2023-12-27 15:53:54 +00:00
|
|
|
public class UserController : ControllerBase
|
2023-08-19 00:15:02 +00:00
|
|
|
{
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
|
|
public UserController(IUserService userService)
|
|
|
|
|
{
|
|
|
|
|
_userService = userService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpPost("/token")]
|
2024-01-16 07:03:35 +00:00
|
|
|
public async Task<ActionResult<Token>> GetToken([FromHeader(Name = "Authorization")][Required] string authcode)
|
2023-08-19 00:15:02 +00:00
|
|
|
{
|
2024-01-16 07:03:35 +00:00
|
|
|
if (authcode.Contains(' '))
|
|
|
|
|
{
|
|
|
|
|
authcode = authcode.Split(' ')[1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var token = await _userService.GetToken(authcode);
|
|
|
|
|
|
2023-08-19 00:15:02 +00:00
|
|
|
if (token == null)
|
|
|
|
|
{
|
|
|
|
|
return Unauthorized();
|
|
|
|
|
}
|
|
|
|
|
return Ok(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[HttpPost("/user")]
|
|
|
|
|
public async Task<UserViewModel> CreateUser(UserCreationModel user)
|
|
|
|
|
{
|
|
|
|
|
var createdUser = await _userService.CreateUser(user.ToUser());
|
|
|
|
|
return UserViewModel.FromUser(createdUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/user/my")]
|
|
|
|
|
public async Task<UserViewModel> GetMyUserProfile()
|
|
|
|
|
{
|
|
|
|
|
var user = await _userService.GetMyProfile();
|
|
|
|
|
return UserViewModel.FromUser(user);
|
|
|
|
|
}
|
|
|
|
|
}
|