Compare commits
No commits in common. "d985211b664ec9a457de715ed243506338f854ac" and "380e81f8c9163a69cafec9a9c07005f5650b2b15" have entirely different histories.
d985211b66
...
380e81f8c9
4 changed files with 9 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -676,7 +676,6 @@ dependencies = [
|
|||
"justerror",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
"tower-http",
|
||||
"tower-sessions",
|
||||
|
|
|
@ -10,7 +10,6 @@ axum = { version = "0.7", default-features = false, features = ["tokio", "http1"
|
|||
justerror = { version = "1" }
|
||||
serde = { version = "1", default-features = false, features = ["derive"] }
|
||||
thiserror = { version = "1" }
|
||||
time = { version = "0.3.34", default-features = false }
|
||||
tokio = { version = "1", default-features = false, features = ["rt-multi-thread"] }
|
||||
tower-http = { version = "0.5.2", default-features = false, features = ["fs"] }
|
||||
tower-sessions = { version = "0.10", default-features = false, features = ["axum-core", "memory-store"] }
|
||||
|
|
|
@ -88,7 +88,7 @@ pub async fn post_edit_signup(
|
|||
}
|
||||
|
||||
/// Called from Stripe with the receipt of payment.
|
||||
pub async fn payment_success(session: Session, receipt: Option<Path<String>>) -> impl IntoResponse {
|
||||
pub async fn signup_success(session: Session, receipt: Option<Path<String>>) -> impl IntoResponse {
|
||||
let user: User = session.get(SIGNUP_KEY).await.unwrap().unwrap_or_default();
|
||||
if user == User::default() {
|
||||
return SignupErrorPage("who you?".to_string()).into_response();
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -2,13 +2,16 @@ use std::net::SocketAddr;
|
|||
|
||||
use axum::{routing::get, Router};
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer};
|
||||
use tower_sessions::{MemoryStore, SessionManagerLayer};
|
||||
|
||||
// "extern crate" is this olde-timey way to bring macros into the current live
|
||||
// namespace; I'm not sure why it's needed here; we're using this to allow to do
|
||||
// like such as #[derive(Error)] before a struct or enum.
|
||||
#[macro_use]
|
||||
extern crate justerror;
|
||||
|
||||
mod handlers;
|
||||
use handlers::{get_signup, payment_success, post_signup};
|
||||
use handlers::{get_signup, post_signup, signup_success};
|
||||
|
||||
mod templates;
|
||||
|
||||
|
@ -23,19 +26,17 @@ async fn main() {
|
|||
|
||||
// just for signups
|
||||
let session_store = MemoryStore::default();
|
||||
let session_layer = SessionManagerLayer::new(session_store)
|
||||
.with_secure(true)
|
||||
.with_expiry(Expiry::OnInactivity(time::Duration::hours(16)));
|
||||
let session_layer = SessionManagerLayer::new(session_store).with_secure(true);
|
||||
|
||||
// the core application, defining the routes and handlers
|
||||
let app = Router::new()
|
||||
.nest_service("/assets", assets_svc)
|
||||
.route("/signup", get(get_signup).post(post_signup))
|
||||
.route("/payment_success/:receipt", get(payment_success))
|
||||
.route("/signup_success/:receipt", get(signup_success))
|
||||
.layer(session_layer)
|
||||
.into_make_service();
|
||||
|
||||
// listening on the network
|
||||
// listing on the network
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
|
||||
let listener = tokio::net::TcpListener::bind(&addr).await.unwrap();
|
||||
axum::serve(listener, app).await.unwrap();
|
||||
|
|
Loading…
Reference in a new issue