fix(web): registration page should work now

This commit is contained in:
əlemi 2024-06-23 17:12:52 +02:00
parent fc744e7604
commit 523cb8b90f
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 39 additions and 10 deletions

View file

@ -131,7 +131,7 @@ pub fn PostBox(advanced: WriteSignal<bool>) -> impl IntoView {
for mention in mentions.get().as_deref().unwrap_or(&[]) { for mention in mentions.get().as_deref().unwrap_or(&[]) {
to_vec.push(mention.to_string()); to_vec.push(mention.to_string());
} }
let payload = serde_json::Value::Object(serde_json::Map::default()) let payload = apb::new()
.set_object_type(Some(apb::ObjectType::Note)) .set_object_type(Some(apb::ObjectType::Note))
.set_summary(summary.as_deref()) .set_summary(summary.as_deref())
.set_content(Some(&content)) .set_content(Some(&content))

View file

@ -2,6 +2,23 @@ use leptos::*;
use reqwest::Method; use reqwest::Method;
use crate::prelude::*; use crate::prelude::*;
macro_rules! get_ref {
($r:ident) => {
$r.get().map(|x| x.value()).filter(|x| !x.is_empty())
}
}
// TODO this should get moved in a common crate so its not duplicated across FE/BE
#[derive(Debug, Clone, serde::Serialize)]
pub struct RegisterForm {
username: String,
password: String,
display_name: Option<String>,
summary: Option<String>,
avatar_url: Option<String>,
banner_url: Option<String>,
}
#[component] #[component]
pub fn RegisterPage() -> impl IntoView { pub fn RegisterPage() -> impl IntoView {
let auth = use_context::<Auth>().expect("missing auth context"); let auth = use_context::<Auth>().expect("missing auth context");
@ -17,17 +34,29 @@ pub fn RegisterPage() -> impl IntoView {
<div class="border ma-2 pa-1"> <div class="border ma-2 pa-1">
<form on:submit=move|ev| { <form on:submit=move|ev| {
ev.prevent_default(); ev.prevent_default();
logging::log!("registering new user..."); let email = get_ref!(username_ref);
let _email = username_ref.get().map(|x| x.value()).unwrap_or("".into()); let password = get_ref!(password_ref);
let _password = password_ref.get().map(|x| x.value()).unwrap_or("".into()); let display_name = get_ref!(display_name_ref);
let summary = get_ref!(summary_ref);
let avatar_url = get_ref!(avatar_url_ref);
let banner_url = get_ref!(banner_url_ref);
if email.is_none() || password.is_none() {
set_error.set(Some(
view! { <blockquote>no credentials provided</blockquote> }
));
}
spawn_local(async move { spawn_local(async move {
match Http::request::<()>( let payload = RegisterForm {
Method::PUT, &format!("{URL_BASE}/auth"), None, auth username: email.unwrap_or_default(),
).await { password: password.unwrap_or_default(),
Ok(_x) => {}, display_name, summary, avatar_url, banner_url
Err(e) => set_error.set(Some( };
if let Err(e) = Http::request(Method::PUT, &format!("{URL_BASE}/auth"), Some(&payload), auth).await {
set_error.set(Some(
view! { <blockquote>{e.to_string()}</blockquote> } view! { <blockquote>{e.to_string()}</blockquote> }
)), ));
} }
}); });
} > } >