setting cookies and our.name correctly

This commit is contained in:
realisation 2023-10-17 11:03:31 -04:00
parent ac7e413fba
commit 2b1111d744

View File

@ -135,7 +135,7 @@ async fn handle_boot(
mut encoded_keyfile: Vec<u8>, mut encoded_keyfile: Vec<u8>,
) -> Result<impl Reply, Rejection> { ) -> Result<impl Reply, Rejection> {
println!("hello"); our.name = info.username;
if info.direct { if info.direct {
our.allowed_routers = vec![]; our.allowed_routers = vec![];
@ -143,17 +143,13 @@ async fn handle_boot(
our.ws_routing = None; our.ws_routing = None;
} }
println!("~~~~~"); if encoded_keyfile.is_empty() && !info.keyfile.clone().is_empty() {
match base64::decode(info.keyfile.clone()) {
if encoded_keyfile.is_empty() && !info.keyfile.is_empty() {
match base64::decode(info.keyfile) {
Ok(k) => encoded_keyfile = k, Ok(k) => encoded_keyfile = k,
Err(_) => return Err(warp::reject()), Err(_) => return Err(warp::reject()),
} }
} }
println!("_____");
let decoded_keyfile = if !encoded_keyfile.is_empty() { let decoded_keyfile = if !encoded_keyfile.is_empty() {
match keygen::decode_keyfile(encoded_keyfile.clone(), &info.password) { match keygen::decode_keyfile(encoded_keyfile.clone(), &info.password) {
Ok(k) => k, Ok(k) => k,
@ -176,8 +172,6 @@ async fn handle_boot(
} }
}; };
println!(">>>>>");
if encoded_keyfile.is_empty() { if encoded_keyfile.is_empty() {
encoded_keyfile = keygen::encode_keyfile( encoded_keyfile = keygen::encode_keyfile(
info.password, info.password,
@ -189,8 +183,6 @@ async fn handle_boot(
); );
} }
println!("<<<<<");
let token = match generate_jwt(&decoded_keyfile.jwt_secret_bytes, our.name.clone()) { let token = match generate_jwt(&decoded_keyfile.jwt_secret_bytes, our.name.clone()) {
Some(token) => token, Some(token) => token,
None => return Err(warp::reject()), None => return Err(warp::reject()),
@ -198,9 +190,15 @@ async fn handle_boot(
sender.send((our.clone(), decoded_keyfile, encoded_keyfile.clone())).await.unwrap(); sender.send((our.clone(), decoded_keyfile, encoded_keyfile.clone())).await.unwrap();
let mut response = warp::reply::html("Success".to_string()).into_response(); let encoded_keyfile_str = match info.keyfile.clone().is_empty() {
true => base64::encode(encoded_keyfile),
false => info.keyfile.clone(),
};
println!("ioioioio"); let mut response = warp::reply::with_status(
warp::reply::json((&encoded_keyfile_str)),
StatusCode::OK
).into_response();
let headers = response.headers_mut(); let headers = response.headers_mut();
headers.append(SET_COOKIE, HeaderValue::from_str( headers.append(SET_COOKIE, HeaderValue::from_str(
@ -208,7 +206,8 @@ async fn handle_boot(
headers.append(SET_COOKIE, HeaderValue::from_str( headers.append(SET_COOKIE, HeaderValue::from_str(
&format!("uqbar-ws-auth_{}={};", &our.name, &token)).unwrap()); &format!("uqbar-ws-auth_{}={};", &our.name, &token)).unwrap());
Ok(warp::reply::with_status(warp::reply(), StatusCode::OK)) Ok(response)
} }
async fn handle_info( async fn handle_info(