diff --git a/CollabVMAuthServer/Database.cs b/CollabVMAuthServer/Database.cs index d2a3629..4cce553 100644 --- a/CollabVMAuthServer/Database.cs +++ b/CollabVMAuthServer/Database.cs @@ -344,7 +344,7 @@ public class Database await cmd.ExecuteNonQueryAsync(); } - public async Task ListUsers(string? filterUsername = null, string orderBy = "id", bool descending = false) + public async Task ListUsers(string? filterUsername = null, IPAddress? filterIp = null, string orderBy = "id", bool descending = false) { await using var db = new MySqlConnection(connectionString); await db.OpenAsync(); @@ -355,6 +355,11 @@ public class Database where.Add("username LIKE @filterUsername"); cmd.Parameters.AddWithValue("@filterUsername", filterUsername); } + if (filterIp != null) + { + where.Add("registration_ip = @filterIp"); + cmd.Parameters.AddWithValue("@filterIp", filterIp.GetAddressBytes()); + } cmd.CommandText = $"SELECT * FROM users {(where.Count > 0 ? "WHERE" : "")} {string.Join(" AND ", where)} ORDER BY {orderBy} {(descending ? "DESC" : "ASC")}"; await using var reader = await cmd.ExecuteReaderAsync(); var users = new List(); diff --git a/CollabVMAuthServer/HTTP/AdminRoutes.cs b/CollabVMAuthServer/HTTP/AdminRoutes.cs index 7130771..c2eaf6b 100644 --- a/CollabVMAuthServer/HTTP/AdminRoutes.cs +++ b/CollabVMAuthServer/HTTP/AdminRoutes.cs @@ -460,7 +460,13 @@ public static class AdminRoutes .Replace("_", "!_") .Replace("[", "![") + "%"; } - var users = (await Program.Database.ListUsers(filterUsername, payload.orderBy ?? "id", payload.orderByDescending)).Select(user => new AdminUser + IPAddress? filterIp = null; + if (payload.filterIp != null) + { + filterIp = IPAddress.Parse(payload.filterIp); + } + + var users = (await Program.Database.ListUsers(filterUsername, filterIp, payload.orderBy ?? "id", payload.orderByDescending)).Select(user => new AdminUser { id = user.Id, username = user.Username, diff --git a/CollabVMAuthServer/HTTP/Payloads/AdminUsersPayload.cs b/CollabVMAuthServer/HTTP/Payloads/AdminUsersPayload.cs index a5ee163..6dd7e76 100644 --- a/CollabVMAuthServer/HTTP/Payloads/AdminUsersPayload.cs +++ b/CollabVMAuthServer/HTTP/Payloads/AdminUsersPayload.cs @@ -6,6 +6,7 @@ public class AdminUsersPayload public int resultsPerPage { get; set; } public int page { get; set; } public string? filterUsername { get; set; } + public string? filterIp { get; set; } public string? orderBy { get; set; } public bool orderByDescending { get; set; } = false; } \ No newline at end of file diff --git a/CollabVMAuthServer/Properties/launchSettings.json b/CollabVMAuthServer/Properties/launchSettings.json new file mode 100644 index 0000000..af34f47 --- /dev/null +++ b/CollabVMAuthServer/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "CollabVMAuthServer": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51282;http://localhost:51283" + } + } +} \ No newline at end of file