mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-23 00:21:38 +03:00
WIP
This commit is contained in:
parent
bd00406646
commit
ec66b58f2b
@ -231,17 +231,6 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for redirect parameter on page load
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const redirectPath = urlParams.get('redirect');
|
|
||||||
if (redirectPath) {
|
|
||||||
// Ensure the redirect path starts with a slash
|
|
||||||
const path = redirectPath.startsWith('/') ? redirectPath : '/' + redirectPath;
|
|
||||||
window.location.href = path;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -294,6 +294,8 @@ async fn serve(
|
|||||||
.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())
|
||||||
|
.and(warp::filters::host::optional())
|
||||||
|
.and(warp::query::<HashMap<String, String>>())
|
||||||
.and(warp::any().map(move || cloned_our.clone()))
|
.and(warp::any().map(move || cloned_our.clone()))
|
||||||
.and(warp::any().map(move || encoded_keyfile.clone()))
|
.and(warp::any().map(move || encoded_keyfile.clone()))
|
||||||
.and_then(login_handler)),
|
.and_then(login_handler)),
|
||||||
@ -324,7 +326,12 @@ async fn serve(
|
|||||||
|
|
||||||
/// handle non-GET requests on /login. if POST, validate password
|
/// handle non-GET requests on /login. if POST, validate password
|
||||||
/// and return auth token, which will be stored in a cookie.
|
/// and return auth token, which will be stored in a cookie.
|
||||||
|
///
|
||||||
|
/// if redirect is provided in URL, such as ?redirect=/chess:chess:sys/,
|
||||||
|
/// the browser will be redirected to that path after successful login.
|
||||||
async fn login_handler(
|
async fn login_handler(
|
||||||
|
host: Option<warp::host::Authority>,
|
||||||
|
query_params: HashMap<String, String>,
|
||||||
info: LoginInfo,
|
info: LoginInfo,
|
||||||
our: Arc<String>,
|
our: Arc<String>,
|
||||||
encoded_keyfile: Arc<Vec<u8>>,
|
encoded_keyfile: Arc<Vec<u8>>,
|
||||||
@ -354,7 +361,11 @@ async fn login_handler(
|
|||||||
|
|
||||||
let mut response = warp::reply::with_status(
|
let mut response = warp::reply::with_status(
|
||||||
warp::reply::json(&base64_standard.encode(encoded_keyfile.to_vec())),
|
warp::reply::json(&base64_standard.encode(encoded_keyfile.to_vec())),
|
||||||
StatusCode::OK,
|
if let Some(redirect) = query_params.get("redirect") {
|
||||||
|
StatusCode::FOUND
|
||||||
|
} else {
|
||||||
|
StatusCode::OK
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.into_response();
|
.into_response();
|
||||||
|
|
||||||
@ -366,6 +377,13 @@ async fn login_handler(
|
|||||||
match HeaderValue::from_str(&cookie) {
|
match HeaderValue::from_str(&cookie) {
|
||||||
Ok(v) => {
|
Ok(v) => {
|
||||||
response.headers_mut().append("set-cookie", v);
|
response.headers_mut().append("set-cookie", v);
|
||||||
|
if let Some(redirect) = query_params.get("redirect") {
|
||||||
|
response.headers_mut().append(
|
||||||
|
"Location",
|
||||||
|
HeaderValue::from_str(&format!("{}{redirect}", host.unwrap().host()))
|
||||||
|
.unwrap(),
|
||||||
|
);
|
||||||
|
}
|
||||||
Ok(response)
|
Ok(response)
|
||||||
}
|
}
|
||||||
Err(e) => Ok(warp::reply::with_status(
|
Err(e) => Ok(warp::reply::with_status(
|
||||||
|
Loading…
Reference in New Issue
Block a user