mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 03:53:26 -08:00
[Server] Serve account self-service updates through the database interface (#7848)
cmdAccountEdit assembled a dynamic UPDATE for the real name, email and country columns in the socket handler, and cmdAccountImage wrote the avatar blob there too. Add AccountUpdateRecord, updateUserAccount and setUserAvatar to Server_DatabaseInterface with fail-closed defaults, implement them with the previous query text and bind values, and keep the password gate, the email permission check, the empty-edit early return and the in-memory userInfo updates in the handler.
This commit is contained in:
parent
8c8dd0c072
commit
f7c6e81347
4 changed files with 75 additions and 30 deletions
|
|
@ -2244,6 +2244,51 @@ void Servatrice_DatabaseInterface::setForcePasswordChange(const QString &user, b
|
|||
execSqlQuery(query);
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::updateUserAccount(const QString &userName, const AccountUpdateRecord &update)
|
||||
{
|
||||
if (!checkSql()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QStringList queryList;
|
||||
if (update.hasRealName) {
|
||||
queryList << "realname=:realName";
|
||||
}
|
||||
if (update.hasEmail) {
|
||||
queryList << "email=:email";
|
||||
}
|
||||
if (update.hasCountry) {
|
||||
queryList << "country=:country";
|
||||
}
|
||||
|
||||
const QString queryText = QString("update {prefix}_users set %1 where name=:userName").arg(queryList.join(", "));
|
||||
QSqlQuery *query = prepareQuery(queryText);
|
||||
if (update.hasRealName) {
|
||||
query->bindValue(":realName", update.realName);
|
||||
}
|
||||
if (update.hasEmail) {
|
||||
query->bindValue(":email", update.email);
|
||||
}
|
||||
if (update.hasCountry) {
|
||||
query->bindValue(":country", update.country);
|
||||
}
|
||||
query->bindValue(":userName", userName);
|
||||
|
||||
return execSqlQuery(query);
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::setUserAvatar(int userId, const QByteArray &image)
|
||||
{
|
||||
if (!checkSql()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlQuery *query = prepareQuery("update {prefix}_users set avatar_bmp=:image where id=:id");
|
||||
query->bindValue(":image", image);
|
||||
query->bindValue(":id", userId);
|
||||
return execSqlQuery(query);
|
||||
}
|
||||
|
||||
bool Servatrice_DatabaseInterface::changeUserPassword(const QString &user,
|
||||
const QString &oldPassword,
|
||||
bool oldPasswordNeedsHash,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue