You've already forked AstralRinth
forked from didirus/AstralRinth
Switch to Sendy for newsletter (#2954)
This commit is contained in:
@@ -1430,23 +1430,23 @@ pub async fn delete_auth_provider(
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
}
|
||||
|
||||
pub async fn sign_up_beehiiv(email: &str) -> Result<(), AuthenticationError> {
|
||||
let id = dotenvy::var("BEEHIIV_PUBLICATION_ID")?;
|
||||
let api_key = dotenvy::var("BEEHIIV_API_KEY")?;
|
||||
pub async fn sign_up_sendy(email: &str) -> Result<(), AuthenticationError> {
|
||||
let url = dotenvy::var("SENDY_URL")?;
|
||||
let id = dotenvy::var("SENDY_LIST_ID")?;
|
||||
let api_key = dotenvy::var("SENDY_API_KEY")?;
|
||||
let site_url = dotenvy::var("SITE_URL")?;
|
||||
|
||||
let mut form = HashMap::new();
|
||||
|
||||
form.insert("api_key", &*api_key);
|
||||
form.insert("email", email);
|
||||
form.insert("list", &*id);
|
||||
form.insert("referrer", &*site_url);
|
||||
|
||||
let client = reqwest::Client::new();
|
||||
client
|
||||
.post(format!(
|
||||
"https://api.beehiiv.com/v2/publications/{id}/subscriptions"
|
||||
))
|
||||
.header(AUTHORIZATION, format!("Bearer {}", api_key))
|
||||
.json(&serde_json::json!({
|
||||
"email": email,
|
||||
"utm_source": "modrinth",
|
||||
"utm_medium": "account_creation",
|
||||
"referring_site": site_url,
|
||||
}))
|
||||
.post(format!("{url}/subscribe"))
|
||||
.form(&form)
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?
|
||||
@@ -1578,7 +1578,7 @@ pub async fn create_account_with_password(
|
||||
)?;
|
||||
|
||||
if new_account.sign_up_newsletter.unwrap_or(false) {
|
||||
sign_up_beehiiv(&new_account.email).await?;
|
||||
sign_up_sendy(&new_account.email).await?;
|
||||
}
|
||||
|
||||
transaction.commit().await?;
|
||||
@@ -2453,7 +2453,7 @@ pub async fn subscribe_newsletter(
|
||||
.1;
|
||||
|
||||
if let Some(email) = user.email {
|
||||
sign_up_beehiiv(&email).await?;
|
||||
sign_up_sendy(&email).await?;
|
||||
|
||||
Ok(HttpResponse::NoContent().finish())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user