mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-19 22:36:49 +00:00
Add world status webpage
This commit is contained in:
parent
dbf4a5e642
commit
5f2617ef71
4 changed files with 27 additions and 15 deletions
|
@ -18,33 +18,35 @@ struct GateStatus {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn root() -> Html<String> {
|
async fn root() -> Html<String> {
|
||||||
tracing::info!("Requesting gate status...");
|
|
||||||
|
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
let environment = setup_default_environment();
|
let environment = setup_default_environment();
|
||||||
let template = environment.get_template("web.html").unwrap();
|
let template = environment.get_template("web.html").unwrap();
|
||||||
Html(template.render(context! { gate_open => config.gate_open }).unwrap())
|
Html(template.render(context! { }).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn login() -> Html<String> {
|
async fn login() -> Html<String> {
|
||||||
tracing::info!("Requesting gate status...");
|
|
||||||
|
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
let environment = setup_default_environment();
|
let environment = setup_default_environment();
|
||||||
let template = environment.get_template("login.html").unwrap();
|
let template = environment.get_template("login.html").unwrap();
|
||||||
Html(template.render(context! { gate_open => config.gate_open }).unwrap())
|
Html(template.render(context! { }).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn register() -> Html<String> {
|
async fn register() -> Html<String> {
|
||||||
tracing::info!("Requesting gate status...");
|
|
||||||
|
|
||||||
let config = get_config();
|
let config = get_config();
|
||||||
|
|
||||||
let environment = setup_default_environment();
|
let environment = setup_default_environment();
|
||||||
let template = environment.get_template("register.html").unwrap();
|
let template = environment.get_template("register.html").unwrap();
|
||||||
Html(template.render(context! { gate_open => config.gate_open }).unwrap())
|
Html(template.render(context! { }).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn world_status() -> Html<String> {
|
||||||
|
let config = get_config();
|
||||||
|
|
||||||
|
let environment = setup_default_environment();
|
||||||
|
let template = environment.get_template("worldstatus.html").unwrap();
|
||||||
|
Html(template.render(context! { login_open => config.login_open, worlds_open => config.worlds_open }).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -58,12 +60,6 @@ async fn apply(Form(input): Form<Input>) -> Redirect {
|
||||||
|
|
||||||
let mut config = get_config();
|
let mut config = get_config();
|
||||||
|
|
||||||
if let Some(gate_open) = input.gate_open {
|
|
||||||
config.gate_open = gate_open == "on";
|
|
||||||
} else {
|
|
||||||
config.gate_open = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
serde_json::to_writer(
|
serde_json::to_writer(
|
||||||
&std::fs::File::create("config.json").unwrap(),
|
&std::fs::File::create("config.json").unwrap(),
|
||||||
&config,
|
&config,
|
||||||
|
@ -81,6 +77,7 @@ async fn main() {
|
||||||
.route("/", get(root))
|
.route("/", get(root))
|
||||||
.route("/login", get(login))
|
.route("/login", get(login))
|
||||||
.route("/register", get(register))
|
.route("/register", get(register))
|
||||||
|
.route("/worldstatus", get(world_status))
|
||||||
.route("/apply", post(apply));
|
.route("/apply", post(apply));
|
||||||
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 5801));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 5801));
|
||||||
|
|
|
@ -20,6 +20,7 @@ pub fn setup_default_environment() -> Environment<'static> {
|
||||||
env.add_template("web.html", include_str!("../templates/web.html")).unwrap();
|
env.add_template("web.html", include_str!("../templates/web.html")).unwrap();
|
||||||
env.add_template("login.html", include_str!("../templates/login.html")).unwrap();
|
env.add_template("login.html", include_str!("../templates/login.html")).unwrap();
|
||||||
env.add_template("register.html", include_str!("../templates/register.html")).unwrap();
|
env.add_template("register.html", include_str!("../templates/register.html")).unwrap();
|
||||||
|
env.add_template("worldstatus.html", include_str!("../templates/worldstatus.html")).unwrap();
|
||||||
|
|
||||||
env
|
env
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
<a href="/login">Login</a>
|
<a href="/login">Login</a>
|
||||||
<a href="/register">Signup</a>
|
<a href="/register">Signup</a>
|
||||||
|
<a href="/worldstatus">World Status</a>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
13
templates/worldstatus.html
Normal file
13
templates/worldstatus.html
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Kawari - World Status</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>Worlds open: {{ worlds_open }}</p>
|
||||||
|
<p>Login open: {{ login_open }}</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue