diff --git a/build.sh b/build.sh index bf6bb35..0fa0380 100644 --- a/build.sh +++ b/build.sh @@ -6,6 +6,7 @@ bin2cpp --file=client/header_top.html --output=server/src/generated bin2cpp --file=client/header_bottom.html --output=server/src/generated bin2cpp --file=client/footer.html --output=server/src/generated +bin2cpp --file=client/login.html --output=server/src/generated bin2cpp --file=client/e404.html --output=server/src/generated bin2cpp --file=client/style.css --output=server/src/generated bin2cpp --file=client/script.js --output=server/src/generated diff --git a/client/header_bottom.html b/client/header_bottom.html index ee255d3..866da5e 100644 --- a/client/header_bottom.html +++ b/client/header_bottom.html @@ -7,7 +7,7 @@
diff --git a/client/login.html b/client/login.html new file mode 100644 index 0000000..9bf3c06 --- /dev/null +++ b/client/login.html @@ -0,0 +1,33 @@ + + + +if you haven't registered, enter a username that doesn't exist and hit 'register'
+ + +wrong password lmao
", "text/html"); + return; + } + } else { + if (username.empty()) { + response.status = 400; + response.set_content("hey you can't have an empty username!!!!1!!!1! >:(
", "text/html"); + return; + } + // register on the fly, same as make_post currently does + User newUser{0, username, bcrypt::generateHash(password)}; + database.addUser(newUser); + user = newUser; + } + + std::optionalcouldn't create a session, sorry
", "text/html"); + return; + } + + // HttpOnly so script.js can't read/leak it, SameSite=Lax so it + // isn't sent on cross-site POSTs (basic CSRF mitigation), + // Max-Age matches the 30 day expiry stored in the DB + response.set_header( + "Set-Cookie", + "session=" + *token + "; Path=/; HttpOnly; SameSite=Lax; Max-Age=2592000" + ); + response.set_redirect("/"); + } catch (const std::runtime_error& e) { + response.status = 500; + response.set_content("there was an error :( it is: " + std::string(e.what()) + "
", "text/html"); + } + }); + svr.Get("/", [&headerTop, &headerBottom, &footer, &database, &data_mutex](const httplib::Request& request, httplib::Response& response) { std::stringstream ss;