mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-24 09:06:10 +03:00
login redirect fixes for fake and real nodes
This commit is contained in:
parent
2c85baa634
commit
af91718fa5
@ -29,11 +29,7 @@
|
|||||||
<div id="password-err" class="login-row row" style="display: none;"> Incorrect Password </div>
|
<div id="password-err" class="login-row row" style="display: none;"> Incorrect Password </div>
|
||||||
<div class="col" style="width: 100%; line-height: 1.5;">
|
<div class="col" style="width: 100%; line-height: 1.5;">
|
||||||
<button> Login </button>
|
<button> Login </button>
|
||||||
<div class="login-row col" style="margin-left: 0.4em; font-size: 0.8em; line-height: 1.5;">
|
<div class="login-row col" id="fake-or-not" style="margin-left: 0.4em; font-size: 0.8em; line-height: 1.5;">
|
||||||
Registered as ${node_type} node
|
|
||||||
</div>
|
|
||||||
<div class="login-row col" style="margin-left: 0.4em; font-size: 0.8em; line-height: 1.5;">
|
|
||||||
Restart node to change networking info
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
@ -45,7 +41,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// TODO replace ${node} and ${node_type} with correct values
|
if ('${fake}') {
|
||||||
|
document.getElementById("fake-or-not").innerHTML = "Fake node -- any password will work!";
|
||||||
|
} else {
|
||||||
|
document.getElementById("fake-or-not").innerHTML = "Restart node to change networking info";
|
||||||
|
}
|
||||||
|
|
||||||
async function login(password) {
|
async function login(password) {
|
||||||
document.getElementById("signup-form").style.display = "none";
|
document.getElementById("signup-form").style.display = "none";
|
||||||
document.getElementById("loading").style.display = "flex";
|
document.getElementById("loading").style.display = "flex";
|
||||||
@ -56,7 +57,9 @@
|
|||||||
body: JSON.stringify({ password }),
|
body: JSON.stringify({ password }),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.status > 399) {
|
if (result.status == 200) {
|
||||||
|
window.location.href = "/";
|
||||||
|
} else {
|
||||||
document.getElementById("signup-form").style.display = "flex";
|
document.getElementById("signup-form").style.display = "flex";
|
||||||
document.getElementById("loading").style.display = "none";
|
document.getElementById("loading").style.display = "none";
|
||||||
document.getElementById("password").value = "";
|
document.getElementById("password").value = "";
|
||||||
@ -64,8 +67,6 @@
|
|||||||
document.getElementById("password").focus();
|
document.getElementById("password").focus();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise should get redirected by the server
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
@ -164,11 +164,20 @@ async fn serve(
|
|||||||
.and(warp::any().map(move || cloned_print_tx.clone()))
|
.and(warp::any().map(move || cloned_print_tx.clone()))
|
||||||
.and_then(ws_handler);
|
.and_then(ws_handler);
|
||||||
|
|
||||||
|
#[cfg(feature = "simulation-mode")]
|
||||||
|
let fake_node = "true";
|
||||||
|
#[cfg(not(feature = "simulation-mode"))]
|
||||||
|
let fake_node = "false";
|
||||||
|
|
||||||
// filter to receive and handle login requests
|
// filter to receive and handle login requests
|
||||||
|
let login_html: &'static str = LOGIN_HTML
|
||||||
|
.replace("${node}", &our)
|
||||||
|
.replace("${fake}", fake_node)
|
||||||
|
.leak();
|
||||||
let cloned_our = our.clone();
|
let cloned_our = our.clone();
|
||||||
let login = warp::path("login").and(warp::path::end()).and(
|
let login = warp::path("login").and(warp::path::end()).and(
|
||||||
warp::get()
|
warp::get()
|
||||||
.map(|| warp::reply::with_status(warp::reply::html(LOGIN_HTML), StatusCode::OK))
|
.map(move || warp::reply::with_status(warp::reply::html(login_html), StatusCode::OK))
|
||||||
.or(warp::post()
|
.or(warp::post()
|
||||||
.and(warp::body::content_length_limit(1024 * 16))
|
.and(warp::body::content_length_limit(1024 * 16))
|
||||||
.and(warp::body::json())
|
.and(warp::body::json())
|
||||||
@ -207,6 +216,11 @@ async fn login_handler(
|
|||||||
our: Arc<String>,
|
our: Arc<String>,
|
||||||
encoded_keyfile: Arc<Vec<u8>>,
|
encoded_keyfile: Arc<Vec<u8>>,
|
||||||
) -> Result<impl warp::Reply, warp::Rejection> {
|
) -> Result<impl warp::Reply, warp::Rejection> {
|
||||||
|
#[cfg(feature = "simulation-mode")]
|
||||||
|
let info = LoginInfo {
|
||||||
|
password: "secret".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
match keygen::decode_keyfile(&encoded_keyfile, &info.password) {
|
match keygen::decode_keyfile(&encoded_keyfile, &info.password) {
|
||||||
Ok(keyfile) => {
|
Ok(keyfile) => {
|
||||||
let token = match register::generate_jwt(&keyfile.jwt_secret_bytes, our.as_ref()) {
|
let token = match register::generate_jwt(&keyfile.jwt_secret_bytes, our.as_ref()) {
|
||||||
@ -222,7 +236,7 @@ async fn login_handler(
|
|||||||
|
|
||||||
let mut response = warp::reply::with_status(
|
let mut response = warp::reply::with_status(
|
||||||
warp::reply::json(&base64::encode(encoded_keyfile.to_vec())),
|
warp::reply::json(&base64::encode(encoded_keyfile.to_vec())),
|
||||||
StatusCode::FOUND,
|
StatusCode::OK,
|
||||||
)
|
)
|
||||||
.into_response();
|
.into_response();
|
||||||
|
|
||||||
@ -341,8 +355,6 @@ async fn http_handler(
|
|||||||
send_to_loop: MessageSender,
|
send_to_loop: MessageSender,
|
||||||
print_tx: PrintSender,
|
print_tx: PrintSender,
|
||||||
) -> Result<impl warp::Reply, warp::Rejection> {
|
) -> Result<impl warp::Reply, warp::Rejection> {
|
||||||
// TODO this is all so dirty. Figure out what actually matters.
|
|
||||||
|
|
||||||
// trim trailing "/"
|
// trim trailing "/"
|
||||||
let original_path = normalize_path(path.as_str());
|
let original_path = normalize_path(path.as_str());
|
||||||
let _ = print_tx
|
let _ = print_tx
|
||||||
@ -361,35 +373,29 @@ async fn http_handler(
|
|||||||
let bound_path = route.handler();
|
let bound_path = route.handler();
|
||||||
|
|
||||||
if bound_path.authenticated {
|
if bound_path.authenticated {
|
||||||
match serialized_headers.get("cookie") {
|
if !auth_cookie_valid(
|
||||||
Some(auth_token) => {
|
&our,
|
||||||
// they have an auth token, validate
|
serialized_headers.get("cookie").unwrap_or(&"".to_string()),
|
||||||
if !auth_cookie_valid(&our, &auth_token, &jwt_secret_bytes) {
|
&jwt_secret_bytes,
|
||||||
return Ok(
|
) {
|
||||||
warp::reply::with_status(vec![], StatusCode::UNAUTHORIZED).into_response()
|
// redirect to login page so they can get an auth token
|
||||||
);
|
let _ = print_tx
|
||||||
}
|
.send(Printout {
|
||||||
}
|
verbosity: 1,
|
||||||
None => {
|
content: format!("redirecting request from {socket_addr:?} to login page"),
|
||||||
// redirect to login page so they can get an auth token
|
})
|
||||||
let _ = print_tx
|
.await;
|
||||||
.send(Printout {
|
return Ok(warp::http::Response::builder()
|
||||||
verbosity: 1,
|
.status(StatusCode::TEMPORARY_REDIRECT)
|
||||||
content: format!("redirecting request from {socket_addr:?} to login page"),
|
.header(
|
||||||
})
|
"Location",
|
||||||
.await;
|
format!(
|
||||||
return Ok(warp::http::Response::builder()
|
"http://{}/login",
|
||||||
.status(StatusCode::TEMPORARY_REDIRECT)
|
host.unwrap_or(Authority::from_static("localhost"))
|
||||||
.header(
|
),
|
||||||
"Location",
|
)
|
||||||
format!(
|
.body(vec![])
|
||||||
"http://{}/login",
|
.into_response());
|
||||||
host.unwrap_or(Authority::from_static("localhost"))
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.body(vec![])
|
|
||||||
.into_response());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user