mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: login & registration; enhanced paste view; custom dropdown + search; navbar; global user access via store; auto token refresh; paste creation as user; /api/user/me, returns info on yourself including pastes;
fix: auth check refactor: remove user UID api endpoint
This commit is contained in:
@@ -10,15 +10,7 @@ namespace SharpbinV3.Server.Controllers
|
||||
{
|
||||
private readonly IUserService _userService = userService;
|
||||
|
||||
[HttpGet("{uid}")]
|
||||
public async Task<IActionResult> GetByUid(int uid)
|
||||
{
|
||||
var user = await _userService.GetByUID(uid);
|
||||
if (user == null) return NotFound();
|
||||
|
||||
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
|
||||
}
|
||||
[HttpGet("username/{username}")]
|
||||
[HttpGet("{username}")]
|
||||
public async Task<IActionResult> GetByUsername(string username)
|
||||
{
|
||||
var user = await _userService.GetByUsername(username);
|
||||
@@ -26,12 +18,45 @@ namespace SharpbinV3.Server.Controllers
|
||||
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
|
||||
}
|
||||
[HttpGet("uuid/{uuid}")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetByUUID(Guid uuid)
|
||||
{
|
||||
var user = await _userService.GetByUUID(uuid);
|
||||
if (user == null) return NotFound();
|
||||
return Ok(new { user.UID, user.Username, user.UUID, user.DisplayName });
|
||||
}
|
||||
[HttpGet("me")]
|
||||
[Authorize]
|
||||
public async Task<IActionResult> GetMe()
|
||||
{
|
||||
var httpUser = HttpContext.User;
|
||||
var userUUID = httpUser?.FindFirst("UUID")?.Value;
|
||||
if (userUUID is null)
|
||||
return Unauthorized(new { message = "Invalid token." });
|
||||
var user = await _userService.GetByUUID(Guid.Parse(userUUID), true);
|
||||
if (user == null)
|
||||
return NotFound();
|
||||
var pastes = user.Pastes?.Select(p => new {
|
||||
p.UUID,
|
||||
p.Title,
|
||||
p.Syntax,
|
||||
p.Size,
|
||||
p.TrueSize,
|
||||
p.Views,
|
||||
p.Visibility,
|
||||
p.EditedAt,
|
||||
p.ExpiresAt
|
||||
});
|
||||
return Ok(new {
|
||||
user.UID,
|
||||
user.Username,
|
||||
user.UUID,
|
||||
user.DisplayName,
|
||||
user.Email,
|
||||
user.LastLogin,
|
||||
user.Roles,
|
||||
user.Visibility,
|
||||
Pastes = pastes
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user