mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
refactor(api): migrate account deletion from minimal API to controller
This commit is contained in:
@@ -314,74 +314,6 @@ namespace SharpbinV2.Server
|
||||
|
||||
#region API
|
||||
|
||||
app.MapPost("/api/accounts/delete", async (HttpContext context) =>
|
||||
{
|
||||
var requestdetails = GetRequestDetails(context);
|
||||
if (string.IsNullOrEmpty(requestdetails.Token))
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
await context.Response.WriteAsJsonAsync(new { success = false, message = "No token provided, not authorized." });
|
||||
return;
|
||||
}
|
||||
var user = await Database.UserFromToken(requestdetails.Token);
|
||||
if (user == null)
|
||||
{
|
||||
context.Response.StatusCode = 400;
|
||||
await context.Response.WriteAsJsonAsync(new { success = false, message = "Invalid token." });
|
||||
return;
|
||||
}
|
||||
using (var connection = new SqliteConnection(MainDatabaseConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
using (var command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandText = "DELETE FROM users WHERE UUID = @UUID;";
|
||||
command.Parameters.AddWithValue("@UUID", user.UUID);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
|
||||
using (var connection = new SqliteConnection(MainDatabaseConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
using (var command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandText = "DELETE FROM pastes WHERE AuthorUUID = @AuthorUUID;";
|
||||
command.Parameters.AddWithValue("@AuthorUUID", user.UUID);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
|
||||
using (var connection = new SqliteConnection(MainDatabaseConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
using (var command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandText = "DELETE FROM sessions WHERE UserUUID = @UserUUID;";
|
||||
command.Parameters.AddWithValue("@UserUUID", user.UUID);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
|
||||
using (var connection = new SqliteConnection(MainDatabaseConnection))
|
||||
{
|
||||
await connection.OpenAsync();
|
||||
using (var command = connection.CreateCommand())
|
||||
{
|
||||
command.CommandText = "UPDATE views SET UserUUID = @UserUUID WHERE UserUUID = @OldUserUUID;";
|
||||
command.Parameters.AddWithValue("@UserUUID", "0");
|
||||
command.Parameters.AddWithValue("@OldUserUUID", user.UUID);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
await connection.CloseAsync();
|
||||
}
|
||||
context.Response.StatusCode = 200;
|
||||
await context.Response.WriteAsJsonAsync(new { success = true, message = "Account deleted." });
|
||||
|
||||
}).RequireRateLimiting("auth");
|
||||
app.MapPost("/api/accounts/reset-password", async (HttpContext context) =>
|
||||
{
|
||||
var requestdetails = GetRequestDetails(context);
|
||||
|
||||
Reference in New Issue
Block a user