Broken code

pull/5/head
~erin 2021-07-20 11:08:43 -04:00
parent e10eb6c0d2
commit 244c185fc8
7 changed files with 148 additions and 6 deletions

123
Cargo.lock generated
View File

@ -185,6 +185,38 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba"
[[package]]
name = "crc32fast"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
]
[[package]]
name = "crypto-mac"
version = "0.10.0"
@ -279,6 +311,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "fs2"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "fsevent"
version = "0.4.0"
@ -314,6 +356,15 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generic-array"
version = "0.14.4"
@ -498,6 +549,12 @@ version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
@ -510,6 +567,15 @@ version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"
[[package]]
name = "lock_api"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0382880606dff6d15c9476c416d18690b72742aa7b605bb6dd6ec9030fbf07eb"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.3.9"
@ -540,6 +606,15 @@ version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]]
name = "memoffset"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]]
name = "mime"
version = "0.2.6"
@ -662,6 +737,31 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "parking_lot"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb"
dependencies = [
"instant",
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018"
dependencies = [
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "pear"
version = "0.1.4"
@ -710,6 +810,7 @@ dependencies = [
"serde",
"serde_json",
"sha1",
"sled",
"uuid",
]
@ -928,6 +1029,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.126"
@ -984,6 +1091,22 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f173ac3d1a7e3b28003f40de0b5ce7fe2710f9b9dc3fc38664cebee46b3b6527"
[[package]]
name = "sled"
version = "0.34.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d0132f3e393bcb7390c60bb45769498cf4550bcb7a21d7f95c02b69f6362cdc"
dependencies = [
"crc32fast",
"crossbeam-epoch",
"crossbeam-utils",
"fs2",
"fxhash",
"libc",
"log 0.4.14",
"parking_lot",
]
[[package]]
name = "smallvec"
version = "1.6.1"

View File

@ -18,3 +18,4 @@ chrono = { version = "0.4.11", features = ["serde"] }
rocket_contrib = { version = "0.4.10", default-features = false, features = ["json", "serve"] }
once_cell = "1.8.0"
random-string = "1.0"
sled = "0.34.6"

View File

@ -32,13 +32,18 @@ form.addEventListener("submit", async function(event) {
newPin = pin
}
if (newPin === pin) {
let body = `{"name":${uname},"pin":${pin},"changed_event":"name","new_event":${newUname}}`;
} if (newUname == uname) {
let body = `{"name":${uname},"pin":${pin},"changed_event":"pin","new_event":${newPin}}`;
}
try {
const userNotFound = await getUname();
if (userNotFound.status == `fail`) {
document.querySelector("#incorrect").innerHTML = `user ${uname} was not found`
} else {
loginChange()
loginChange(body)
}
} catch {
document.querySelector("#incorrect").innerHTML = 'An Error has Occurred. Try again later.'
@ -51,13 +56,15 @@ async function getUname() {
return responseJson;
}
async function loginChange() {
const rawResponse = await fetch(`/api/users/change/${uname}/${pin}/${newUname}/${newPin}`, {
async function loginChange(body) {
const rawResponse = await fetch(`/api/users/change`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: ""
body: body
});
document.querySelector("#incorrect").innerHTML = 'Login Changed!'
window.location.replace("/login.html")
}

View File

@ -1 +1 @@
http POST 'http://localhost:8000/api/message/send' name=Sarah body="meow" date=2021-07-01 token=NULL
http POST 'http://localhost:8000/api/users/change' name=erin pin=10 changed_event=pin new_event=69

View File

@ -122,7 +122,7 @@ pub fn check_pin(mut cookies: Cookies, name: String, pin: i32) -> JsonValue {
});
}
#[derive(Deserialize)]
#[derive(Deserialize, Debug)]
pub struct Event {
pub name: String,
pub pin: String,
@ -133,6 +133,7 @@ pub struct Event {
// Change info about a user
#[post("/users/change", format = "json", data = "<input>")]
pub fn change_info(input: Json<Event>) -> JsonValue {
println!("{:?}", input);
// read in the users & hash the pin
let mut users: Vec<User> = read_json();
let hashed_pin = sha1::Sha1::from(&input.pin).digest().to_string();

View File

@ -96,3 +96,12 @@ pub fn write_json(users_list: &Vec<User>) -> Result<()> {
};
Ok(())
}
// test sled funtion
pub fn test_sled() {
let db: sled::Db = sled::open("my_db").unwrap();
db.insert("key", "value");
let value = std::str::from_utf8(&db.get("key").unwrap().unwrap()).unwrap();
info!("database: {:?}", &value);
}

View File

@ -18,6 +18,7 @@ mod user;
fn main() {
env_logger::init();
file_io::test_sled();
info!("Started up rocket");
let cors_fairing = AdHoc::on_response("CORS", |_, res| {
res.set_raw_header("Access-Control-Allow-Origin", "*");