Auth basic working - unsafe

This commit is contained in:
SinTan1729 2023-04-08 02:52:16 -05:00
parent 7d5ff40893
commit 34b2b116ba
5 changed files with 294 additions and 19 deletions

205
actix/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -11,3 +11,4 @@ actix-files = "0.6.2"
rusqlite = "0.29.0" rusqlite = "0.29.0"
regex = "1.7.3" regex = "1.7.3"
rand = "0.8.5" rand = "0.8.5"
actix-session = {version = "0.7.2", features = ["cookie-session"]}

View File

@ -9,8 +9,22 @@ const getSiteUrl = async () => await fetch("/api/siteurl")
} }
}); });
const auth_fetch = async (link) => {
let reply = await fetch(link).then(res => res.text());
if (reply == "logged_out") {
pass = prompt("Please enter passkey to access this website");
await fetch("/api/login", {
method: "POST",
body: pass
});
return auth_fetch(link);
} else {
return reply;
}
}
const refreshData = async () => { const refreshData = async () => {
let data = await fetch("/api/all").then(res => res.text()); let data = await auth_fetch("/api/all");
data = data data = data
.split("\n") .split("\n")
.filter(line => line !== "") .filter(line => line !== "")

22
actix/src/auth.rs Normal file
View File

@ -0,0 +1,22 @@
use actix_session::Session;
pub fn validate(session: Session) -> bool {
let token = session.get::<i32>("session-token");
if token.is_err() {
false
} else if !check(token.unwrap()) {
false
} else {
true
}
}
fn check(token: Option<i32>) -> bool {
if token.is_none() {
false
} else if token.unwrap() != 123 {
false
} else {
true
}
}

File diff suppressed because it is too large Load Diff