allow for searching by IP
This commit is contained in:
@@ -344,7 +344,7 @@ public class Database
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
public async Task<User[]> ListUsers(string? filterUsername = null, string orderBy = "id", bool descending = false)
|
||||
public async Task<User[]> 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<User>();
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
12
CollabVMAuthServer/Properties/launchSettings.json
Normal file
12
CollabVMAuthServer/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"profiles": {
|
||||
"CollabVMAuthServer": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"applicationUrl": "https://localhost:51282;http://localhost:51283"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user