mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-08 06:50:46 +02:00
Get registration timestamp from User.json
The field is not necessarily present so it's put in an optional. (Other fields may not be present either but our json library is way too lenient and just returns default values for them >_>.)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include "common/String.h"
|
||||
#include <optional>
|
||||
|
||||
class UserInfo
|
||||
struct UserInfo
|
||||
{
|
||||
public:
|
||||
int UserID;
|
||||
int age;
|
||||
ByteString username;
|
||||
@@ -18,20 +18,5 @@ public:
|
||||
int topicCount;
|
||||
int topicReplies;
|
||||
int reputation;
|
||||
|
||||
UserInfo(int id, int age, ByteString username, String biography, String location, ByteString website, int saveCount, float averageScore, int highestScore, int topicCount, int topicReplies, int reputation):
|
||||
UserID(id),
|
||||
age(age),
|
||||
username(username),
|
||||
biography(biography),
|
||||
location(location),
|
||||
website(website),
|
||||
saveCount(saveCount),
|
||||
averageScore(averageScore),
|
||||
highestScore(highestScore),
|
||||
topicCount(topicCount),
|
||||
topicReplies(topicReplies),
|
||||
reputation(reputation)
|
||||
{ }
|
||||
UserInfo() {}
|
||||
std::optional<time_t> registeredAt;
|
||||
};
|
||||
|
@@ -18,7 +18,7 @@ namespace http
|
||||
try
|
||||
{
|
||||
auto &user = result["User"];
|
||||
userInfo = UserInfo(
|
||||
userInfo = UserInfo{
|
||||
user["ID"].asInt(),
|
||||
user["Age"].asInt(),
|
||||
user["Username"].asString(),
|
||||
@@ -31,7 +31,11 @@ namespace http
|
||||
user["Forum"]["Topics"].asInt(),
|
||||
user["Forum"]["Replies"].asInt(),
|
||||
user["Forum"]["Reputation"].asInt()
|
||||
);
|
||||
};
|
||||
if (user.isMember("RegisterTime"))
|
||||
{
|
||||
userInfo.registeredAt = ByteString(user["RegisterTime"].asString()).ToNumber<time_t>();
|
||||
}
|
||||
}
|
||||
catch (const std::exception &ex)
|
||||
{
|
||||
|
Reference in New Issue
Block a user