broken
This commit is contained in:
parent
c4f599e394
commit
9373c5c340
3 changed files with 34 additions and 26 deletions
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -245,9 +245,9 @@ checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.89"
|
version = "1.0.90"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
|
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
|
@ -263,9 +263,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.34"
|
version = "0.4.35"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b"
|
checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
@ -395,9 +395,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "env_logger"
|
name = "env_logger"
|
||||||
version = "0.11.2"
|
version = "0.11.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6c012a26a7f605efc424dd53697843a72be7dc86ad2d01f7814337794a12231d"
|
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_filter",
|
"env_filter",
|
||||||
"humantime",
|
"humantime",
|
||||||
|
@ -1100,18 +1100,18 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project"
|
name = "pin-project"
|
||||||
version = "1.1.4"
|
version = "1.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0302c4a0442c456bd56f841aee5c3bfd17967563f6fadc9ceb9f9c23cf3807e0"
|
checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"pin-project-internal",
|
"pin-project-internal",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pin-project-internal"
|
name = "pin-project-internal"
|
||||||
version = "1.1.4"
|
version = "1.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "266c042b60c9c76b8d53061e52b2e0d1116abc57cefc8c5cd671619a56ac3690"
|
checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -42,21 +42,28 @@ pub async fn post_signup(
|
||||||
) -> Result<impl IntoResponse, CreateUserError> {
|
) -> Result<impl IntoResponse, CreateUserError> {
|
||||||
let user = validate_signup(&form).await?;
|
let user = validate_signup(&form).await?;
|
||||||
match session.insert(SIGNUP_KEY, user).await {
|
match session.insert(SIGNUP_KEY, user).await {
|
||||||
Ok(_) => {}
|
Ok(_) => {
|
||||||
|
dbg!("cool");
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!(
|
log::error!("Could not insert validated user form into session, got {e}",);
|
||||||
"Could not insert validated user form into session, got {}",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
return Err(CreateUserErrorKind::UnknownEorr.into());
|
return Err(CreateUserErrorKind::UnknownEorr.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbg!(&*MONTHLY_LINK);
|
||||||
match session.save().await {
|
match session.save().await {
|
||||||
// TODO: pass in as env var/into a state object that the handlers can read from
|
// TODO: pass in as env var/into a state object that the handlers can read from
|
||||||
Ok(_) => Ok(Redirect::to(&MONTHLY_LINK)),
|
Ok(_) => {
|
||||||
|
let resp = Ok(Redirect::to(
|
||||||
|
"https://buy.stripe.com/test_eVa6rrb7ygjNbwk000",
|
||||||
|
));
|
||||||
|
dbg!(&resp);
|
||||||
|
resp
|
||||||
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Could not save session, got {}", e);
|
dbg!("error on save");
|
||||||
|
log::error!("Could not save session, got {e}");
|
||||||
Err(CreateUserErrorKind::UnknownEorr.into())
|
Err(CreateUserErrorKind::UnknownEorr.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -8,11 +8,11 @@ use axum::{
|
||||||
routing::{get, MethodRouter},
|
routing::{get, MethodRouter},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions};
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tower_http::services::ServeDir;
|
use tower_http::services::ServeDir;
|
||||||
use tower_sessions::{Expiry, SessionManagerLayer};
|
use tower_sessions::{Expiry, SessionManagerLayer};
|
||||||
use tower_sessions_sqlx_store::{sqlx::SqlitePool, SqliteStore};
|
use tower_sessions_sqlx_store::SqliteStore;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate justerror;
|
extern crate justerror;
|
||||||
|
@ -35,15 +35,14 @@ async fn main() {
|
||||||
let assets_svc = ServeDir::new(assets_dir.as_path());
|
let assets_svc = ServeDir::new(assets_dir.as_path());
|
||||||
|
|
||||||
let pool = db().await;
|
let pool = db().await;
|
||||||
sqlx::migrate!().run(&pool).await.unwrap();
|
|
||||||
|
|
||||||
let session_store = SqliteStore::new(pool.clone());
|
let session_store = SqliteStore::new(pool.clone());
|
||||||
session_store.migrate().await.unwrap();
|
session_store.migrate().await.unwrap();
|
||||||
session_store.migrate().await.unwrap();
|
|
||||||
let session_layer = SessionManagerLayer::new(session_store)
|
let session_layer = SessionManagerLayer::new(session_store)
|
||||||
.with_secure(false)
|
.with_secure(false)
|
||||||
.with_same_site(tower_sessions::cookie::SameSite::Lax)
|
.with_same_site(tower_sessions::cookie::SameSite::Lax)
|
||||||
.with_expiry(Expiry::OnInactivity(time::Duration::hours(2)));
|
.with_expiry(Expiry::OnInactivity(time::Duration::hours(12)));
|
||||||
|
|
||||||
|
sqlx::migrate!().run(&pool).await.unwrap();
|
||||||
|
|
||||||
// the core application, defining the routes and handlers
|
// the core application, defining the routes and handlers
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
|
@ -52,13 +51,15 @@ async fn main() {
|
||||||
.stripped_clone("/payment_success/", get(payment_success))
|
.stripped_clone("/payment_success/", get(payment_success))
|
||||||
.route("/payment_success/:receipt", get(payment_success))
|
.route("/payment_success/:receipt", get(payment_success))
|
||||||
.layer(session_layer)
|
.layer(session_layer)
|
||||||
.with_state(pool)
|
.with_state(pool.clone())
|
||||||
.into_make_service();
|
.into_make_service();
|
||||||
let listener = mklistener().await;
|
let listener = mklistener().await;
|
||||||
axum::serve(listener, app)
|
axum::serve(listener, app)
|
||||||
.with_graceful_shutdown(shutdown_signal())
|
.with_graceful_shutdown(shutdown_signal())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
pool.close().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-************************************************************************
|
//-************************************************************************
|
||||||
|
@ -79,7 +80,7 @@ async fn db() -> SqlitePool {
|
||||||
let opts = SqliteConnectOptions::new()
|
let opts = SqliteConnectOptions::new()
|
||||||
.foreign_keys(true)
|
.foreign_keys(true)
|
||||||
.create_if_missing(true)
|
.create_if_missing(true)
|
||||||
.journal_mode(sqlx::sqlite::SqliteJournalMode::Persist)
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Wal)
|
||||||
.optimize_on_close(true, None);
|
.optimize_on_close(true, None);
|
||||||
SqlitePoolOptions::new().connect_with(opts).await.unwrap()
|
SqlitePoolOptions::new().connect_with(opts).await.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -138,7 +139,7 @@ async fn shutdown_signal() {
|
||||||
let terminate = std::future::pending::<()>();
|
let terminate = std::future::pending::<()>();
|
||||||
|
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = ctrl_c => {},
|
_ = ctrl_c => {log::info!("shutting down")},
|
||||||
_ = terminate => {},
|
_ = terminate => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue