Compare commits
2 commits
380e81f8c9
...
d985211b66
Author | SHA1 | Date | |
---|---|---|---|
|
d985211b66 | ||
|
cf0e1d3d8f |
4 changed files with 10 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -676,6 +676,7 @@ dependencies = [
|
|||
"justerror",
|
||||
"serde",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
"tower-http",
|
||||
"tower-sessions",
|
||||
|
|
|
@ -10,6 +10,7 @@ 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 signup_success(session: Session, receipt: Option<Path<String>>) -> impl IntoResponse {
|
||||
pub async fn payment_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,16 +2,13 @@ use std::net::SocketAddr;
|
|||
|
||||
use axum::{routing::get, Router};
|
||||
use tower_http::services::ServeDir;
|
||||
use tower_sessions::{MemoryStore, SessionManagerLayer};
|
||||
use tower_sessions::{Expiry, 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, post_signup, signup_success};
|
||||
use handlers::{get_signup, payment_success, post_signup};
|
||||
|
||||
mod templates;
|
||||
|
||||
|
@ -26,17 +23,19 @@ async fn main() {
|
|||
|
||||
// just for signups
|
||||
let session_store = MemoryStore::default();
|
||||
let session_layer = SessionManagerLayer::new(session_store).with_secure(true);
|
||||
let session_layer = SessionManagerLayer::new(session_store)
|
||||
.with_secure(true)
|
||||
.with_expiry(Expiry::OnInactivity(time::Duration::hours(16)));
|
||||
|
||||
// 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("/signup_success/:receipt", get(signup_success))
|
||||
.route("/payment_success/:receipt", get(payment_success))
|
||||
.layer(session_layer)
|
||||
.into_make_service();
|
||||
|
||||
// listing on the network
|
||||
// listening 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