refactor: rename DTree to DValue
This commit is contained in:
@@ -45,7 +45,7 @@ void app_init(Request& context)
|
||||
context.call["route"]["page"] = context.params["ROUTE_PAGE"];
|
||||
context.call["route"]["valid"].set_bool(context.params["ROUTE_VALID"] != "0");
|
||||
|
||||
DTree config = get_config();
|
||||
DValue config = get_config();
|
||||
session_start();
|
||||
String requested_theme = first(context.get["theme"], context.session["app_theme"], config["theme"]["key"].to_string());
|
||||
if(config["theme"]["options"][requested_theme].get_type_name() != "array")
|
||||
@@ -53,8 +53,8 @@ void app_init(Request& context)
|
||||
if(context.get["theme"] != "")
|
||||
context.session["app_theme"] = requested_theme;
|
||||
|
||||
DTree selected_theme = config["theme"]["options"][requested_theme];
|
||||
selected_theme.each([&](DTree item, String key) {
|
||||
DValue selected_theme = config["theme"]["options"][requested_theme];
|
||||
selected_theme.each([&](DValue item, String key) {
|
||||
config["theme"][key] = item;
|
||||
});
|
||||
config["theme"]["key"] = requested_theme;
|
||||
|
||||
@@ -50,9 +50,9 @@ struct AppUser
|
||||
return(hash);
|
||||
}
|
||||
|
||||
static DTree read_json_file(String file_name)
|
||||
static DValue read_json_file(String file_name)
|
||||
{
|
||||
DTree result;
|
||||
DValue result;
|
||||
if(!file_exists(file_name))
|
||||
return(result);
|
||||
String raw = trim(file_get_contents(file_name));
|
||||
@@ -61,24 +61,24 @@ struct AppUser
|
||||
return(json_decode(raw));
|
||||
}
|
||||
|
||||
static bool write_json_file(String file_name, DTree data)
|
||||
static bool write_json_file(String file_name, DValue data)
|
||||
{
|
||||
mkdir(dirname(file_name));
|
||||
return(file_put_contents(file_name, json_encode(data)));
|
||||
}
|
||||
|
||||
DTree load(String email)
|
||||
DValue load(String email)
|
||||
{
|
||||
DTree user = read_json_file(file_name(email));
|
||||
DValue user = read_json_file(file_name(email));
|
||||
if(user.get_type_name() != "array")
|
||||
return(DTree());
|
||||
return(DValue());
|
||||
user["id"] = normalize_email(email);
|
||||
return(user);
|
||||
}
|
||||
|
||||
DTree create(String email, String password)
|
||||
DValue create(String email, String password)
|
||||
{
|
||||
DTree result;
|
||||
DValue result;
|
||||
email = normalize_email(email);
|
||||
password = trim(password);
|
||||
result["message"] = "";
|
||||
@@ -95,7 +95,7 @@ struct AppUser
|
||||
return(result);
|
||||
}
|
||||
|
||||
DTree existing = load(email);
|
||||
DValue existing = load(email);
|
||||
if(existing.get_type_name() == "array" && existing["email"].to_string() != "")
|
||||
{
|
||||
result["message"] = "user_exists";
|
||||
@@ -103,12 +103,12 @@ struct AppUser
|
||||
}
|
||||
|
||||
String salt = gen_sha1(std::to_string((u64)time()) + ":" + std::to_string((u64)(time_precise() * 1000000.0)) + ":" + session_id_create()).substr(0, 24);
|
||||
DTree user;
|
||||
DValue user;
|
||||
user["email"] = email;
|
||||
user["salt"] = salt;
|
||||
user["password_hash"] = password_hash(password, salt);
|
||||
user["created"] = std::to_string((u64)time());
|
||||
DTree role;
|
||||
DValue role;
|
||||
role = "user";
|
||||
user["roles"].push(role);
|
||||
|
||||
@@ -120,14 +120,14 @@ struct AppUser
|
||||
return(result);
|
||||
}
|
||||
|
||||
DTree sign_in(String email, String password)
|
||||
DValue sign_in(String email, String password)
|
||||
{
|
||||
DTree result;
|
||||
DValue result;
|
||||
result["result"].set_bool(false);
|
||||
email = normalize_email(email);
|
||||
password = trim(password);
|
||||
|
||||
DTree user = load(email);
|
||||
DValue user = load(email);
|
||||
if(user.get_type_name() != "array" || user["email"].to_string() == "")
|
||||
{
|
||||
result["message"] = "no_such_user";
|
||||
@@ -161,7 +161,7 @@ struct AppUser
|
||||
String user_id = context.session[session_key()];
|
||||
if(user_id == "")
|
||||
return(false);
|
||||
DTree user = load(user_id);
|
||||
DValue user = load(user_id);
|
||||
if(user["email"].to_string() == "")
|
||||
{
|
||||
context.session.erase(session_key());
|
||||
@@ -171,11 +171,11 @@ struct AppUser
|
||||
return(true);
|
||||
}
|
||||
|
||||
DTree current()
|
||||
DValue current()
|
||||
{
|
||||
if(is_signed_in())
|
||||
return(context.call["app"]["current_user"]);
|
||||
return(DTree());
|
||||
return(DValue());
|
||||
}
|
||||
|
||||
void logout()
|
||||
|
||||
Reference in New Issue
Block a user