add: ability to create seller account
This commit is contained in:
parent
e4468e4768
commit
aea764948c
13 changed files with 356 additions and 0 deletions
|
@ -332,6 +332,10 @@ pub async fn onboarding_account_link_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.seller_data.account_id.is_some() {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let client = match data.3 {
|
||||
Some(ref c) => c,
|
||||
None => return Json(Error::Unknown.into()),
|
||||
|
@ -379,6 +383,10 @@ pub async fn create_seller_account_request(
|
|||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.seller_data.account_id.is_some() {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let client = match data.3 {
|
||||
Some(ref c) => c,
|
||||
None => return Json(Error::Unknown.into()),
|
||||
|
@ -420,3 +428,38 @@ pub async fn create_seller_account_request(
|
|||
Err(e) => return Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn login_link_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await);
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.seller_data.account_id.is_none() | !user.seller_data.completed_onboarding {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
|
||||
let client = match data.3 {
|
||||
Some(ref c) => c,
|
||||
None => return Json(Error::Unknown.into()),
|
||||
};
|
||||
|
||||
match stripe::LoginLink::create(
|
||||
&client,
|
||||
&stripe::AccountId::from_str(&user.seller_data.account_id.unwrap()).unwrap(),
|
||||
&data.0.0.0.host,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(x) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Acceptable".to_string(),
|
||||
payload: Some(x.url),
|
||||
}),
|
||||
Err(e) => Json(Error::MiscError(e.to_string()).into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,6 +520,10 @@ pub fn routes() -> Router {
|
|||
"/service_hooks/stripe/seller/onboarding",
|
||||
post(auth::connections::stripe::onboarding_account_link_request),
|
||||
)
|
||||
.route(
|
||||
"/service_hooks/stripe/seller/login",
|
||||
post(auth::connections::stripe::login_link_request),
|
||||
)
|
||||
// channels
|
||||
.route("/channels", post(channels::channels::create_request))
|
||||
.route(
|
||||
|
|
95
crates/app/src/routes/pages/marketplace.rs
Normal file
95
crates/app/src/routes/pages/marketplace.rs
Normal file
|
@ -0,0 +1,95 @@
|
|||
use super::render_error;
|
||||
use crate::{assets::initial_context, get_lang, get_user_from_token, State};
|
||||
use axum::{
|
||||
response::{Html, IntoResponse},
|
||||
Extension,
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::Error;
|
||||
|
||||
/// `/settings/seller`
|
||||
pub async fn seller_settings_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1.render("marketplace/seller.html", &context).unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn connection_return_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let mut user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
// update user
|
||||
user.seller_data.completed_onboarding = true;
|
||||
if let Err(e) = data
|
||||
.0
|
||||
.update_user_seller_data(user.id, user.seller_data.clone())
|
||||
.await
|
||||
{
|
||||
return Err(Html(render_error(e, &jar, &data, &None).await));
|
||||
}
|
||||
|
||||
// ...
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
context.insert("connection_type", "return");
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("auth/seller_connection.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub async fn connection_reload_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0.0, lang, &Some(user)).await;
|
||||
context.insert("connection_type", "reload");
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("auth/seller_connection.html", &context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
|
@ -5,6 +5,7 @@ pub mod developer;
|
|||
pub mod forge;
|
||||
pub mod journals;
|
||||
pub mod littleweb;
|
||||
pub mod marketplace;
|
||||
pub mod misc;
|
||||
pub mod mod_panel;
|
||||
pub mod profile;
|
||||
|
@ -76,6 +77,14 @@ pub fn routes() -> Router {
|
|||
"/auth/connections_link/app/{id}",
|
||||
get(developer::connection_callback_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/connections_link/seller/reload",
|
||||
get(marketplace::connection_reload_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/connections_link/seller/return",
|
||||
get(marketplace::connection_return_request),
|
||||
)
|
||||
// profile
|
||||
.route("/settings", get(profile::settings_request))
|
||||
.route("/@{username}", get(profile::posts_request))
|
||||
|
@ -146,6 +155,11 @@ pub fn routes() -> Router {
|
|||
.route("/domains/{id}", get(littleweb::domain_request))
|
||||
.route("/net", get(littleweb::browser_home_request))
|
||||
.route("/net/{*uri}", get(littleweb::browser_request))
|
||||
// marketplace
|
||||
.route(
|
||||
"/settings/seller",
|
||||
get(marketplace::seller_settings_request),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn lw_routes() -> Router {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue