This commit is contained in:
parent
c2bfa06faa
commit
a56ca40204
16 changed files with 816 additions and 234 deletions
|
|
@ -2684,4 +2684,43 @@ void UserController::getReferralSettings(const HttpRequestPtr &req,
|
|||
callback(jsonResp(resp));
|
||||
}
|
||||
>> DB_ERROR_MSG(callback, "get settings", "Failed to get settings");
|
||||
}
|
||||
|
||||
void UserController::updateScreensaver(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback) {
|
||||
try {
|
||||
UserInfo user = getUserFromRequest(req);
|
||||
if (user.id == 0) {
|
||||
callback(jsonError("Unauthorized", k401Unauthorized));
|
||||
return;
|
||||
}
|
||||
|
||||
auto json = req->getJsonObject();
|
||||
if (!json) {
|
||||
callback(jsonError("Invalid JSON"));
|
||||
return;
|
||||
}
|
||||
|
||||
bool enabled = (*json).isMember("enabled") ? (*json)["enabled"].asBool() : false;
|
||||
int timeoutMinutes = (*json).isMember("timeout_minutes") ? (*json)["timeout_minutes"].asInt() : 5;
|
||||
|
||||
// Validate timeout range (1-30 minutes)
|
||||
if (timeoutMinutes < 1) timeoutMinutes = 1;
|
||||
if (timeoutMinutes > 30) timeoutMinutes = 30;
|
||||
|
||||
auto dbClient = app().getDbClient();
|
||||
*dbClient << "UPDATE users SET screensaver_enabled = $1, screensaver_timeout_minutes = $2 WHERE id = $3"
|
||||
<< enabled << timeoutMinutes << user.id
|
||||
>> [callback, enabled, timeoutMinutes](const Result&) {
|
||||
Json::Value resp;
|
||||
resp["success"] = true;
|
||||
resp["screensaver"]["enabled"] = enabled;
|
||||
resp["screensaver"]["timeout_minutes"] = timeoutMinutes;
|
||||
callback(jsonResp(resp));
|
||||
}
|
||||
>> DB_ERROR_MSG(callback, "update screensaver settings", "Failed to update screensaver settings");
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERROR << "Exception in updateScreensaver: " << e.what();
|
||||
callback(jsonError("Internal server error"));
|
||||
}
|
||||
}
|
||||
|
|
@ -48,6 +48,8 @@ public:
|
|||
ADD_METHOD_TO(UserController::validateReferralCode, "/api/auth/validate-referral", Post);
|
||||
ADD_METHOD_TO(UserController::registerWithReferral, "/api/auth/register-referral", Post);
|
||||
ADD_METHOD_TO(UserController::getReferralSettings, "/api/settings/referral", Get);
|
||||
// Screensaver settings
|
||||
ADD_METHOD_TO(UserController::updateScreensaver, "/api/user/screensaver", Put);
|
||||
METHOD_LIST_END
|
||||
|
||||
void register_(const HttpRequestPtr &req,
|
||||
|
|
@ -171,6 +173,10 @@ public:
|
|||
void getReferralSettings(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback);
|
||||
|
||||
// Screensaver settings
|
||||
void updateScreensaver(const HttpRequestPtr &req,
|
||||
std::function<void(const HttpResponsePtr &)> &&callback);
|
||||
|
||||
private:
|
||||
// Übercoin helper: Calculate burn rate based on account age
|
||||
// Formula: max(1, 99 * e^(-account_age_days / 180))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue