You've already forked AstralRinth
forked from didirus/AstralRinth
Switch to Sendy for newsletter (#2954)
This commit is contained in:
@@ -86,8 +86,9 @@ SITE_VERIFY_EMAIL_PATH=none
|
|||||||
SITE_RESET_PASSWORD_PATH=none
|
SITE_RESET_PASSWORD_PATH=none
|
||||||
SITE_BILLING_PATH=none
|
SITE_BILLING_PATH=none
|
||||||
|
|
||||||
BEEHIIV_PUBLICATION_ID=none
|
SENDY_URL=none
|
||||||
BEEHIIV_API_KEY=none
|
SENDY_LIST_ID=none
|
||||||
|
SENDY_API_KEY=none
|
||||||
|
|
||||||
ANALYTICS_ALLOWED_ORIGINS='["http://127.0.0.1:3000", "http://localhost:3000", "https://modrinth.com", "https://www.modrinth.com", "*"]'
|
ANALYTICS_ALLOWED_ORIGINS='["http://127.0.0.1:3000", "http://localhost:3000", "https://modrinth.com", "https://www.modrinth.com", "*"]'
|
||||||
|
|
||||||
|
|||||||
@@ -460,8 +460,9 @@ pub fn check_env_vars() -> bool {
|
|||||||
failed |= check_var::<String>("SITE_RESET_PASSWORD_PATH");
|
failed |= check_var::<String>("SITE_RESET_PASSWORD_PATH");
|
||||||
failed |= check_var::<String>("SITE_BILLING_PATH");
|
failed |= check_var::<String>("SITE_BILLING_PATH");
|
||||||
|
|
||||||
failed |= check_var::<String>("BEEHIIV_PUBLICATION_ID");
|
failed |= check_var::<String>("SENDY_URL");
|
||||||
failed |= check_var::<String>("BEEHIIV_API_KEY");
|
failed |= check_var::<String>("SENDY_LIST_ID");
|
||||||
|
failed |= check_var::<String>("SENDY_API_KEY");
|
||||||
|
|
||||||
if parse_strings_from_var("ANALYTICS_ALLOWED_ORIGINS").is_none() {
|
if parse_strings_from_var("ANALYTICS_ALLOWED_ORIGINS").is_none() {
|
||||||
warn!(
|
warn!(
|
||||||
|
|||||||
@@ -1430,23 +1430,23 @@ pub async fn delete_auth_provider(
|
|||||||
Ok(HttpResponse::NoContent().finish())
|
Ok(HttpResponse::NoContent().finish())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn sign_up_beehiiv(email: &str) -> Result<(), AuthenticationError> {
|
pub async fn sign_up_sendy(email: &str) -> Result<(), AuthenticationError> {
|
||||||
let id = dotenvy::var("BEEHIIV_PUBLICATION_ID")?;
|
let url = dotenvy::var("SENDY_URL")?;
|
||||||
let api_key = dotenvy::var("BEEHIIV_API_KEY")?;
|
let id = dotenvy::var("SENDY_LIST_ID")?;
|
||||||
|
let api_key = dotenvy::var("SENDY_API_KEY")?;
|
||||||
let site_url = dotenvy::var("SITE_URL")?;
|
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();
|
let client = reqwest::Client::new();
|
||||||
client
|
client
|
||||||
.post(format!(
|
.post(format!("{url}/subscribe"))
|
||||||
"https://api.beehiiv.com/v2/publications/{id}/subscriptions"
|
.form(&form)
|
||||||
))
|
|
||||||
.header(AUTHORIZATION, format!("Bearer {}", api_key))
|
|
||||||
.json(&serde_json::json!({
|
|
||||||
"email": email,
|
|
||||||
"utm_source": "modrinth",
|
|
||||||
"utm_medium": "account_creation",
|
|
||||||
"referring_site": site_url,
|
|
||||||
}))
|
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?
|
.error_for_status()?
|
||||||
@@ -1578,7 +1578,7 @@ pub async fn create_account_with_password(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
if new_account.sign_up_newsletter.unwrap_or(false) {
|
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?;
|
transaction.commit().await?;
|
||||||
@@ -2453,7 +2453,7 @@ pub async fn subscribe_newsletter(
|
|||||||
.1;
|
.1;
|
||||||
|
|
||||||
if let Some(email) = user.email {
|
if let Some(email) = user.email {
|
||||||
sign_up_beehiiv(&email).await?;
|
sign_up_sendy(&email).await?;
|
||||||
|
|
||||||
Ok(HttpResponse::NoContent().finish())
|
Ok(HttpResponse::NoContent().finish())
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user