add: littleweb base
This commit is contained in:
parent
07a23f505b
commit
c4de17058b
20 changed files with 457 additions and 8 deletions
|
@ -207,6 +207,58 @@ pub async fn stripe_webhook(
|
|||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
EventType::InvoicePaymentFailed => {
|
||||
// payment failed
|
||||
let subscription = match req.data.object {
|
||||
EventObject::Subscription(c) => c,
|
||||
_ => unreachable!("cannot be this"),
|
||||
};
|
||||
|
||||
let customer_id = subscription.customer.id();
|
||||
|
||||
let user = match data.get_user_by_stripe_id(customer_id.as_str()).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Json(e.into()),
|
||||
};
|
||||
|
||||
tracing::info!(
|
||||
"unsubscribe (pay fail) {} (stripe: {})",
|
||||
user.id,
|
||||
customer_id
|
||||
);
|
||||
let new_user_permissions = user.permissions - FinePermission::SUPPORTER;
|
||||
|
||||
if let Err(e) = data
|
||||
.update_user_role(user.id, new_user_permissions, user.clone(), true)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
|
||||
if data.0.0.security.enable_invite_codes && user.was_purchased && user.invite_code == 0
|
||||
{
|
||||
// user doesn't come from an invite code, and is a purchased account
|
||||
// this means their account must be locked if they stop paying
|
||||
if let Err(e) = data
|
||||
.update_user_awaiting_purchased_status(user.id, true, user.clone(), false)
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = data
|
||||
.create_notification(Notification::new(
|
||||
"It seems your recent payment has failed :(".to_string(),
|
||||
"No worries! Your subscription is still active and will be retried. Your supporter status will resume when you have a successful payment."
|
||||
.to_string(),
|
||||
user.id,
|
||||
))
|
||||
.await
|
||||
{
|
||||
return Json(e.into());
|
||||
}
|
||||
}
|
||||
_ => return Json(Error::Unknown.into()),
|
||||
}
|
||||
|
||||
|
|
|
@ -635,6 +635,10 @@ pub fn routes() -> Router {
|
|||
.route("/layouts/{id}/pages", post(layouts::update_pages_request))
|
||||
}
|
||||
|
||||
pub fn lw_routes() -> Router {
|
||||
Router::new()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct LoginProps {
|
||||
pub username: String,
|
||||
|
|
|
@ -46,3 +46,14 @@ pub fn routes(config: &Config) -> Router {
|
|||
// pages
|
||||
.merge(pages::routes())
|
||||
}
|
||||
|
||||
/// These routes are only used when you provide the `LITTLEWEB` environment variable.
|
||||
///
|
||||
/// These routes are NOT for editing. These routes are only for viewing littleweb sites.
|
||||
pub fn lw_routes() -> Router {
|
||||
Router::new()
|
||||
// api
|
||||
.nest("/api/v1", api::v1::lw_routes())
|
||||
// pages
|
||||
.merge(pages::lw_routes())
|
||||
}
|
||||
|
|
|
@ -141,6 +141,10 @@ pub fn routes() -> Router {
|
|||
.route("/x/{note}", get(journals::global_view_request))
|
||||
}
|
||||
|
||||
pub fn lw_routes() -> Router {
|
||||
Router::new()
|
||||
}
|
||||
|
||||
pub async fn render_error(
|
||||
e: Error,
|
||||
jar: &CookieJar,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue