8 #ifndef UPDATEPASSWORDREQUEST_H
9 #define UPDATEPASSWORDREQUEST_H
46 QJsonObject
execute(
const QJsonObject& jsonObj, QMutex& m)
override
48 QMutexLocker locker(&m);
57 response.insert(
"Response", 13);
60 if (jsonObj.contains(
"Data"))
62 QJsonObject dataObj = jsonObj[
"Data"].toObject();
64 if (dataObj.contains(
"email"))
66 email = dataObj.value(
"email").toString();
69 if (dataObj.contains(
"password"))
71 password = dataObj.value(
"password").toString();
74 if (dataObj.contains(
"new_password"))
76 new_password = dataObj.value(
"new_password").toString();
81 qCritical() <<
"Data not found";
93 int user_id = result.
first().value(
"id").toInt();
101 if (result.
first().value(
"password").toString() != password)
107 bool success = dbManager->
where(
"email = ", email)->
update(
"users", {{
"password", new_password}});
114 data.insert(
"status",
int(
true));
115 data.insert(
"message",
"Password updated successfully");
117 response.insert(
"Data", data);
122 QJsonDocument responseDoc(response);
123 QByteArray responseData = responseDoc.toJson();
126 qDebug().noquote() <<
"<-- UpdatePassword::Response :\n" << responseDoc.toJson(QJsonDocument::Indented);
This file contains the declaration of the Request class, which is an abstract base class for handling...
Manages database connections and SQL operations.
Definition: db.h:80
bool update(const QString &table, const QVariantMap &data)
Updates data in a specified table.
Definition: db.cpp:361
DatabaseManager * table(const QString &value)
Sets the table for the query.
Definition: db.cpp:115
DatabaseManager * where(const QString &value, const QVariant &val=QVariant())
Adds a WHERE clause to the query.
Definition: db.cpp:121
DbResult exec()
Executes the built query.
Definition: db.cpp:266
DatabaseManager * select(const QString &value)
Selects columns for the query.
Definition: db.cpp:107
The DbResult class represents a result set returned from a database query.
Definition: dbresult.h:24
QJsonObject first() const
Retrieves the first item in the result set.
Definition: dbresult.cpp:25
bool isEmpty() const
Checks if the result set is empty.
Definition: dbresult.cpp:20
The Request class is an abstract base class for handling different types of requests.
Definition: Request.h:25
QJsonObject CreateErrorResponse(QJsonObject &response, QJsonObject &dataObj, QString message)
Creates a generic error JSON response.
Definition: Request.h:90
QJsonObject CreateDBConnectionError(QJsonObject &response, QJsonObject &dataObj)
Creates a JSON response indicating a database connection error.
Definition: Request.h:65
bool isDBConnectionValid(DB::DatabaseManager *dbManager)
Checks if the database connection is valid.
Definition: Request.h:36
The UpdatePasswordRequest class handles password update requests for users.
Definition: UpdatePasswordRequest.h:21
QJsonObject execute(const QJsonObject &jsonObj, QMutex &m) override
Executes the password update request.
Definition: UpdatePasswordRequest.h:46
UpdatePasswordRequest()
Constructor for the UpdatePasswordRequest class.
Definition: UpdatePasswordRequest.h:31
Database management classes for handling database connections and operations.