chore: format via csharpier

This commit is contained in:
2026-01-09 15:13:57 -05:00
parent 284c5e927e
commit 7a2eb699f4
35 changed files with 784 additions and 464 deletions
+59 -27
View File
@@ -16,7 +16,13 @@ namespace SharpbinV3.Server.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class UserController(UserService userService, AppDbContext db, TotpVerificationProvider totp, VerificationService verificationService, IOptions<AuthSettings> authSettings) : ControllerBase
public class UserController(
UserService userService,
AppDbContext db,
TotpVerificationProvider totp,
VerificationService verificationService,
IOptions<AuthSettings> authSettings
) : ControllerBase
{
private readonly UserService _userService = userService;
private readonly AppDbContext _db = db;
@@ -52,12 +58,16 @@ namespace SharpbinV3.Server.Controllers
[HttpPatch("uuid/{uuid}")]
[Authorize]
public async Task<IActionResult> UpdateByUUID(Guid uuid, [FromBody] UpdateUserDto updatedUser)
public async Task<IActionResult> UpdateByUUID(
Guid uuid,
[FromBody] UpdateUserDto updatedUser
)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var jwtUser = HttpContext.GetJwtUser();
if (jwtUser == null) return Forbid();
if (jwtUser == null)
return Forbid();
var user = await _userService.GetByUUID(uuid);
if (user == null)
return NotFound();
@@ -65,7 +75,11 @@ namespace SharpbinV3.Server.Controllers
return Forbid();
if (user.Roles.Contains(255) && !jwtUser.Roles.Contains(255))
return Forbid();
if (jwtUser.Roles.Contains(255) && !jwtUser.TotpEnabled && _authSettings.Admins_Require_2FA)
if (
jwtUser.Roles.Contains(255)
&& !jwtUser.TotpEnabled
&& _authSettings.Admins_Require_2FA
)
return Forbid();
user.DisplayName = updatedUser.DisplayName ?? user.DisplayName;
@@ -78,11 +92,16 @@ namespace SharpbinV3.Server.Controllers
{
if (updatedUser.Roles.Contains(255) && jwtUser.TotpEnabled)
{
if (string.IsNullOrEmpty(updatedUser.TotpCode) || !await _totp.VerifyAsync(new VerificationContext
{
UserUUID = jwtUser.UUID,
Code = updatedUser.TotpCode
}))
if (
string.IsNullOrEmpty(updatedUser.TotpCode)
|| !await _totp.VerifyAsync(
new VerificationContext
{
UserUUID = jwtUser.UUID,
Code = updatedUser.TotpCode,
}
)
)
{
return Unauthorized(new { message = "Invalid TOTP code." });
}
@@ -99,32 +118,44 @@ namespace SharpbinV3.Server.Controllers
public async Task<IActionResult> DeleteByUUID(Guid uuid, [FromBody] DeleteUserDto dto)
{
var jwtUser = HttpContext.GetJwtUser();
if (jwtUser == null) return Forbid();
if (jwtUser == null)
return Forbid();
var user = await _userService.GetByUUID(uuid);
if (user == null) return Forbid();
if (user == null)
return Forbid();
if (!jwtUser.Roles.Any(r => r == 255) && user.UUID != jwtUser.UUID)
return Forbid();
if (jwtUser.Roles.Contains(255) && !jwtUser.TotpEnabled && _authSettings.Admins_Require_2FA)
if (
jwtUser.Roles.Contains(255)
&& !jwtUser.TotpEnabled
&& _authSettings.Admins_Require_2FA
)
return Forbid();
if (jwtUser.TotpEnabled)
{
if (string.IsNullOrEmpty(dto.TotpCode) || !await _totp.VerifyAsync(new VerificationContext
{
UserUUID = jwtUser.UUID,
Code = dto.TotpCode
}))
if (
string.IsNullOrEmpty(dto.TotpCode)
|| !await _totp.VerifyAsync(
new VerificationContext { UserUUID = jwtUser.UUID, Code = dto.TotpCode }
)
)
{
return Unauthorized(new { message = "Invalid TOTP code." });
}
}
else
{
if (string.IsNullOrEmpty(dto.Token) || !await _verificationService.VerifyAsync(new VerificationContext
{
Token = dto.Token,
Ip = HttpContext.GetRequestIP()
}))
if (
string.IsNullOrEmpty(dto.Token)
|| !await _verificationService.VerifyAsync(
new VerificationContext
{
Token = dto.Token,
Ip = HttpContext.GetRequestIP(),
}
)
)
{
return Unauthorized(new { message = "Invalid verification token." });
}
@@ -137,7 +168,8 @@ namespace SharpbinV3.Server.Controllers
private async Task<object> BuildUserResponse(User user, int page = 1)
{
var isAuthenticatedUser = HttpContext.User?.FindFirst("UUID")?.Value == user.UUID.ToString();
var isAuthenticatedUser =
HttpContext.User?.FindFirst("UUID")?.Value == user.UUID.ToString();
var pasteQuery = _db.Pastes.AsNoTracking().Where(p => p.AuthorUUID == user.UUID);
if (!isAuthenticatedUser)
{
@@ -170,7 +202,7 @@ namespace SharpbinV3.Server.Controllers
p.Views,
p.Visibility,
p.EditedAt,
p.ExpiresAt
p.ExpiresAt,
})
.ToListAsync();
@@ -179,7 +211,7 @@ namespace SharpbinV3.Server.Controllers
Page = page,
PageSize = pageSize,
TotalCount = totalCount,
TotalPages = totalPages
TotalPages = totalPages,
};
if (isAuthenticatedUser)
@@ -195,7 +227,7 @@ namespace SharpbinV3.Server.Controllers
user.Roles,
user.Visibility,
Pastes = pastes,
Pagination = pagination
Pagination = pagination,
};
}
@@ -207,7 +239,7 @@ namespace SharpbinV3.Server.Controllers
user.DisplayName,
user.Roles,
Pastes = pastes,
Pagination = pagination
Pagination = pagination,
};
}
}