Fix user deletion (#240)
* Minr change to DB code, not fixed or tested yet * Fix user deletion for good. * Typo * Add scoping Code shamelessly stolen from Cerapter. Thanks for telling me how to scope. Co-Authored-By: Cerapter <43446478+Cerapter@users.noreply.github.com> Co-authored-by: Cerapter <43446478+Cerapter@users.noreply.github.com>
This commit is contained in:
parent
9f6acefdef
commit
8d3a815ca8
@ -198,20 +198,30 @@ bool DBManager::createUser(QString username, QString salt, QString password, uns
|
|||||||
|
|
||||||
bool DBManager::deleteUser(QString username)
|
bool DBManager::deleteUser(QString username)
|
||||||
{
|
{
|
||||||
QSqlQuery username_exists;
|
if (username == "root") {
|
||||||
username_exists.prepare("SELECT ACL FROM users WHERE USERNAME = ?");
|
//To prevent lockout scenarios where an admin may accidentally delete root.
|
||||||
username_exists.addBindValue(username);
|
|
||||||
username_exists.exec();
|
|
||||||
|
|
||||||
if (!username_exists.first())
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QSqlQuery query;
|
{
|
||||||
query.prepare("DELETE FROM users WHERE USERNAME = ?");
|
QSqlQuery username_exists;
|
||||||
|
username_exists.prepare("SELECT EXISTS(SELECT USERNAME FROM users WHERE USERNAME = ?)");
|
||||||
username_exists.addBindValue(username);
|
username_exists.addBindValue(username);
|
||||||
username_exists.exec();
|
username_exists.exec();
|
||||||
|
username_exists.first();
|
||||||
|
//If EXISTS can't find a record, it returns 0.
|
||||||
|
if (username_exists.value(0).toInt() == 0)
|
||||||
|
//We were unable to locate an entry with this name.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
QSqlQuery username_delete;
|
||||||
|
username_delete.prepare("DELETE FROM users WHERE USERNAME = ?");
|
||||||
|
username_delete.addBindValue(username);
|
||||||
|
username_delete.exec();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unsigned long long DBManager::getACL(QString moderator_name)
|
unsigned long long DBManager::getACL(QString moderator_name)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user