mirror of
https://git.ethanthesleepy.one/ethanaobrien/ew.git
synced 2025-05-13 11:37:33 -05:00
Add ability to export account
This commit is contained in:
parent
dae95f5aa3
commit
0b969eab97
4 changed files with 49 additions and 2 deletions
|
@ -160,6 +160,7 @@ async fn request(req: HttpRequest, body: String) -> HttpResponse {
|
|||
"/api/webui/userInfo" => router::webui::user(req),
|
||||
"/webui/logout" => router::webui::logout(req),
|
||||
"/api/webui/admin" => router::webui::admin(req),
|
||||
"/api/webui/export" => router::webui::export(req),
|
||||
_ => api_req(req, body)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -600,3 +600,14 @@ pub fn set_server_time(time: i64, token: &str) -> JsonValue {
|
|||
pub fn webui_logout(token: &str) {
|
||||
DATABASE.lock_and_exec("DELETE FROM webui WHERE token=?1", params!(token));
|
||||
}
|
||||
|
||||
pub fn export_user(token: &str) -> Option<JsonValue> {
|
||||
let login_token = webui_login_token(token)?;
|
||||
|
||||
Some(object!{
|
||||
userdata: json::stringify(get_acc(&login_token)),
|
||||
userhome: json::stringify(get_acc_home(&login_token)),
|
||||
missions: json::stringify(get_acc_missions(&login_token)),
|
||||
sifcards: json::stringify(get_acc_sif(&login_token))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -215,6 +215,21 @@ pub fn admin_post(req: HttpRequest, body: String) -> HttpResponse {
|
|||
result: "OK"
|
||||
};
|
||||
HttpResponse::Ok()
|
||||
.insert_header(ContentType::json())
|
||||
.body(json::stringify(resp))
|
||||
.insert_header(ContentType::json())
|
||||
.body(json::stringify(resp))
|
||||
}
|
||||
|
||||
pub fn export(req: HttpRequest) -> HttpResponse {
|
||||
let token = get_login_token(&req);
|
||||
if token.is_none() {
|
||||
return error("Not logged in");
|
||||
}
|
||||
let resp = object!{
|
||||
result: "OK",
|
||||
data: userdata::export_user(&token.unwrap()).unwrap()
|
||||
};
|
||||
HttpResponse::Ok()
|
||||
.insert_header(ContentType::json())
|
||||
.body(json::stringify(resp))
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,25 @@ function Home() {
|
|||
const logout = () => {
|
||||
window.location.href = "/webui/logout";
|
||||
}
|
||||
const downloadFile = (contents, name) => {
|
||||
let a = document.createElement("a");
|
||||
a.href = URL.createObjectURL(new Blob([contents], {type: "application/json"}));
|
||||
a.download = name;
|
||||
a.click();
|
||||
}
|
||||
const expor = async (e) => {
|
||||
e.preventDefault();
|
||||
let resp = await Request("/api/webui/export");
|
||||
if (resp.result !== "OK") {
|
||||
error[1](resp.message);
|
||||
return;
|
||||
}
|
||||
downloadFile(resp.data.userdata, "userdata.json");
|
||||
downloadFile(resp.data.userhome, "userhome.json");
|
||||
downloadFile(resp.data.missions, "missions.json");
|
||||
downloadFile(resp.data.sifcards, "sifcards.json");
|
||||
|
||||
}
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
let time = Math.round(new Date(inputValue.trim()).getTime() / 1000);
|
||||
|
@ -135,6 +154,7 @@ function Home() {
|
|||
|
||||
return (
|
||||
<div id="home">
|
||||
<button id="logout" onClick={expor}>Export account</button><br/><br/><br/>
|
||||
<button id="logout" onClick={logout}>Logout</button>
|
||||
<h1>Home</h1>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue