Skip to content

Commit

Permalink
implement sendgrid hand-rolled
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Oct 22, 2023
1 parent 5aee6b5 commit bb9c05e
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 10 deletions.
174 changes: 173 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ repository = "https://github.com/plabayo/bucket"
askama = { version = "0.12", features = ["with-axum"] }
askama_axum = "0.3"
axum = "0.6"
serde = { version = "1.0.188", features = ["derive"] }
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
shuttle-axum = "0.29"
shuttle-runtime = "0.29"
shuttle-secrets = "0.29"
tokio = "1.28"
tower = { version = "0.4.13", features = ["tracing"] }
tower = { version = "0.4", features = ["tracing"] }
tower-http = { version = "0.4", features = ["fs", "trace", "compression-full", "normalize-path"] }
tracing = "0.1"
26 changes: 24 additions & 2 deletions src/router/login.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use std::sync::Arc;

use askama_axum::{IntoResponse, Response};
use axum::{extract::Query, http::StatusCode, response::Redirect, Form};
use axum::{
extract::{Query, State},
http::StatusCode,
response::Redirect,
Form,
};
use serde::Deserialize;

#[derive(Deserialize)]
Expand All @@ -22,7 +29,10 @@ pub struct PostParams {
email: String,
}

pub async fn post(Form(params): Form<PostParams>) -> Response {
pub async fn post(
State(state): State<Arc<crate::router::State>>,
Form(params): Form<PostParams>,
) -> Response {
if params.email.is_empty() {
return (
StatusCode::BAD_REQUEST,
Expand All @@ -33,6 +43,18 @@ pub async fn post(Form(params): Form<PostParams>) -> Response {
)
.into_response();
}

if let Err((msg, status)) = state.auth.send_magic_link(&params.email).await {
return (
status,
super::shared::ErrorTemplate {
title: "failed to send magic link".to_string(),
message: msg,
},
)
.into_response();
}

super::shared::InfoTemplate {
title: format!("email sent to {}", params.email),
message: format!("Magic link has been sent to {}. Please open the link in the email to login to this site.", params.email),
Expand Down
Loading

0 comments on commit bb9c05e

Please sign in to comment.