mirror of
https://github.com/minoplhy/chhoto-url.git
synced 2024-12-22 19:57:57 +00:00
Auth basic working - unsafe
This commit is contained in:
parent
7d5ff40893
commit
34b2b116ba
205
actix/Cargo.lock
generated
205
actix/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -11,3 +11,4 @@ actix-files = "0.6.2"
|
||||
rusqlite = "0.29.0"
|
||||
regex = "1.7.3"
|
||||
rand = "0.8.5"
|
||||
actix-session = {version = "0.7.2", features = ["cookie-session"]}
|
||||
|
@ -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 () => {
|
||||
let data = await fetch("/api/all").then(res => res.text());
|
||||
let data = await auth_fetch("/api/all");
|
||||
data = data
|
||||
.split("\n")
|
||||
.filter(line => line !== "")
|
||||
|
22
actix/src/auth.rs
Normal file
22
actix/src/auth.rs
Normal 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
Loading…
Reference in New Issue
Block a user