mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-24 16:17:44 +00:00
Separate the login and world gates
This commit is contained in:
parent
ee6b4f2f7f
commit
a063de2eb5
4 changed files with 45 additions and 13 deletions
|
@ -24,13 +24,14 @@ async fn root() -> Html<String> {
|
||||||
|
|
||||||
let environment = setup_default_environment();
|
let environment = setup_default_environment();
|
||||||
let template = environment.get_template("admin.html").unwrap();
|
let template = environment.get_template("admin.html").unwrap();
|
||||||
Html(template.render(context! { gate_open => config.gate_open }).unwrap())
|
Html(template.render(context! { worlds_open => config.worlds_open, login_open => config.login_open }).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct Input {
|
struct Input {
|
||||||
gate_open: Option<String>,
|
worlds_open: Option<String>,
|
||||||
|
login_open: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn apply(Form(input): Form<Input>) -> Redirect {
|
async fn apply(Form(input): Form<Input>) -> Redirect {
|
||||||
|
@ -38,10 +39,16 @@ 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 {
|
if let Some(gate_open) = input.worlds_open {
|
||||||
config.gate_open = gate_open == "on";
|
config.worlds_open = gate_open == "on";
|
||||||
} else {
|
} else {
|
||||||
config.gate_open = false;
|
config.worlds_open = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(gate_open) = input.login_open {
|
||||||
|
config.login_open = gate_open == "on";
|
||||||
|
} else {
|
||||||
|
config.login_open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
serde_json::to_writer(
|
serde_json::to_writer(
|
||||||
|
|
|
@ -12,7 +12,7 @@ struct GateStatus {
|
||||||
status: i32,
|
status: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_gate_status() -> Json<GateStatus> {
|
async fn get_login_status() -> Json<GateStatus> {
|
||||||
tracing::info!("Requesting gate status...");
|
tracing::info!("Requesting gate status...");
|
||||||
|
|
||||||
let mut is_open = 0;
|
let mut is_open = 0;
|
||||||
|
@ -21,7 +21,26 @@ async fn get_gate_status() -> Json<GateStatus> {
|
||||||
if let Ok(data) = std::fs::read_to_string("config.json") {
|
if let Ok(data) = std::fs::read_to_string("config.json") {
|
||||||
let config: Config = serde_json::from_str(&data).expect("Failed to parse");
|
let config: Config = serde_json::from_str(&data).expect("Failed to parse");
|
||||||
|
|
||||||
if config.gate_open {
|
if config.login_open {
|
||||||
|
is_open = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Json(GateStatus {
|
||||||
|
status: is_open
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn get_world_status() -> Json<GateStatus> {
|
||||||
|
tracing::info!("Requesting gate status...");
|
||||||
|
|
||||||
|
let mut is_open = 0;
|
||||||
|
|
||||||
|
// read config
|
||||||
|
if let Ok(data) = std::fs::read_to_string("config.json") {
|
||||||
|
let config: Config = serde_json::from_str(&data).expect("Failed to parse");
|
||||||
|
|
||||||
|
if config.worlds_open {
|
||||||
is_open = 1;
|
is_open = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,8 +95,8 @@ async fn main() {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/worldStatus/gate_status.json", get(get_gate_status))
|
.route("/worldStatus/gate_status.json", get(get_world_status))
|
||||||
.route("/worldStatus/login_status.json", get(get_gate_status))
|
.route("/worldStatus/login_status.json", get(get_login_status))
|
||||||
.route("/news/headline.json", get(get_headline));
|
.route("/news/headline.json", get(get_headline));
|
||||||
|
|
||||||
let addr = SocketAddr::from(([127, 0, 0, 1], 5857));
|
let addr = SocketAddr::from(([127, 0, 0, 1], 5857));
|
||||||
|
|
|
@ -3,7 +3,10 @@ use serde::{Deserialize, Serialize};
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub gate_open: bool,
|
pub worlds_open: bool,
|
||||||
|
|
||||||
|
#[serde(default)]
|
||||||
|
pub login_open: bool,
|
||||||
|
|
||||||
#[serde(default = "default_supported_platforms")]
|
#[serde(default = "default_supported_platforms")]
|
||||||
pub supported_platforms: Vec<String>,
|
pub supported_platforms: Vec<String>,
|
||||||
|
@ -12,7 +15,8 @@ pub struct Config {
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
gate_open: false,
|
worlds_open: false,
|
||||||
|
login_open: false,
|
||||||
supported_platforms: default_supported_platforms()
|
supported_platforms: default_supported_platforms()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<p>Gate open:{{ gate_open }}</p>
|
<p>Gate open:{{ worlds_open }}</p>
|
||||||
|
<p>Gate open:{{ login_open }}</p>
|
||||||
<form action='apply' method='post'>
|
<form action='apply' method='post'>
|
||||||
<input type='checkbox' id='gate_open' name='gate_open' checked/>
|
<input type='checkbox' id='worlds_open' name='worlds_open' checked/>
|
||||||
|
<input type='checkbox' id='login_open' name='login_open' checked/>
|
||||||
<button type='submit'>Apply</button>
|
<button type='submit'>Apply</button>
|
||||||
</form>
|
</form>
|
Loading…
Add table
Reference in a new issue