fix(db): Correct casing and escaping in DB queries
Updates the database queries to handle casing inconsistencies and improves SQL query parameter escaping for better security and compatibility. Refactors group existence checks for simplicity, enhancing readability and maintainability. Addresses issues related to unique constraints in user registration by improving error handling for duplicate usernames.
This commit is contained in:
parent
2d839e3609
commit
de602a91d4
2 changed files with 33 additions and 34 deletions
|
|
@ -253,13 +253,7 @@ namespace TShockAPI.DB
|
|||
/// </summary>
|
||||
/// <param name="group">The group.</param>
|
||||
/// <returns><c>true</c> if it does; otherwise, <c>false</c>.</returns>
|
||||
public bool GroupExists(string group)
|
||||
{
|
||||
if (group == "superadmin")
|
||||
return true;
|
||||
|
||||
return groups.Any(g => g.Name.Equals(group));
|
||||
}
|
||||
public bool GroupExists(string group) => group is "superadmin" || groups.Any(g => g.Name.Equals(group));
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
|
|
@ -270,21 +264,14 @@ namespace TShockAPI.DB
|
|||
/// Gets the enumerator.
|
||||
/// </summary>
|
||||
/// <returns>The enumerator.</returns>
|
||||
public IEnumerator<Group> GetEnumerator()
|
||||
{
|
||||
return groups.GetEnumerator();
|
||||
}
|
||||
public IEnumerator<Group> GetEnumerator() => groups.GetEnumerator();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the group matching the specified name.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>The group.</returns>
|
||||
public Group GetGroupByName(string name)
|
||||
{
|
||||
var ret = groups.Where(g => g.Name == name);
|
||||
return 1 == ret.Count() ? ret.ElementAt(0) : null;
|
||||
}
|
||||
public Group GetGroupByName(string name) => groups.FirstOrDefault(g => g.Name == name);
|
||||
|
||||
/// <summary>
|
||||
/// Adds group with name and permissions if it does not exist.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue