update deps
This commit is contained in:
1079
Cargo.lock
generated
1079
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
crate-type = ["cdylib", "rlib"]
|
crate-type = ["cdylib", "rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
osiris-client = { path = "../../osiris/client" }
|
||||||
yew = { workspace = true }
|
yew = { workspace = true }
|
||||||
wasm-bindgen = { workspace = true }
|
wasm-bindgen = { workspace = true }
|
||||||
wasm-bindgen-futures = { workspace = true }
|
wasm-bindgen-futures = { workspace = true }
|
||||||
@@ -33,7 +34,7 @@ web-sys = { workspace = true, features = [
|
|||||||
] }
|
] }
|
||||||
js-sys = { workspace = true }
|
js-sys = { workspace = true }
|
||||||
gloo = { workspace = true }
|
gloo = { workspace = true }
|
||||||
gloo-timers = { workspace = true }
|
gloo-timers = { workspace = true, features = ["futures"] }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
serde-wasm-bindgen = "0.6"
|
serde-wasm-bindgen = "0.6"
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ use hex;
|
|||||||
pub struct RegistrationConfig {
|
pub struct RegistrationConfig {
|
||||||
pub server_url: String,
|
pub server_url: String,
|
||||||
pub app_name: String,
|
pub app_name: String,
|
||||||
|
pub osiris_url: Option<String>,
|
||||||
|
pub supervisor_url: Option<String>,
|
||||||
|
pub supervisor_secret: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
@@ -576,12 +579,57 @@ impl Registration {
|
|||||||
fn send_email_verification(&mut self, ctx: &Context<Self>) {
|
fn send_email_verification(&mut self, ctx: &Context<Self>) {
|
||||||
self.email_status = EmailVerificationStatus::Pending;
|
self.email_status = EmailVerificationStatus::Pending;
|
||||||
|
|
||||||
let server_url = ctx.props().config.server_url.clone();
|
let config = ctx.props().config.clone();
|
||||||
let email = self.email.clone();
|
let email = self.email.clone();
|
||||||
let link = ctx.link().clone();
|
let link = ctx.link().clone();
|
||||||
// Send verification request
|
|
||||||
|
// Send verification request via Osiris client
|
||||||
wasm_bindgen_futures::spawn_local(async move {
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
let url = format!("{}/api/send-verification", server_url);
|
// Build Osiris client if configured, otherwise fall back to direct API
|
||||||
|
if let (Some(osiris_url), Some(supervisor_url), Some(supervisor_secret)) =
|
||||||
|
(config.osiris_url.as_ref(), config.supervisor_url.as_ref(), config.supervisor_secret.as_ref()) {
|
||||||
|
|
||||||
|
// Use Osiris client
|
||||||
|
match osiris_client::OsirisClient::builder()
|
||||||
|
.osiris_url(osiris_url)
|
||||||
|
.supervisor_url(supervisor_url)
|
||||||
|
.supervisor_secret(supervisor_secret)
|
||||||
|
.runner_name("osiris")
|
||||||
|
.build()
|
||||||
|
{
|
||||||
|
Ok(client) => {
|
||||||
|
let request = osiris_client::SendVerificationRequest {
|
||||||
|
email: email.clone(),
|
||||||
|
verification_url: Some(format!("{}/verify", config.server_url)),
|
||||||
|
};
|
||||||
|
|
||||||
|
match client.send_verification_email(request).await {
|
||||||
|
Ok(response) => {
|
||||||
|
web_sys::console::log_1(&format!("Email verification sent via Osiris: {}", response.verification_id).into());
|
||||||
|
|
||||||
|
// Poll for verification status
|
||||||
|
let verification_id = response.verification_id;
|
||||||
|
let link_poll = link.clone();
|
||||||
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
|
poll_verification_status(client, verification_id, link_poll).await;
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
web_sys::console::error_1(&format!("Failed to send verification via Osiris: {:?}", e).into());
|
||||||
|
link.send_message(RegistrationMsg::EmailVerificationFailed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
web_sys::console::error_1(&format!("Failed to build Osiris client: {}", e).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback to direct API call
|
||||||
|
let url = format!("{}/api/send-verification", config.server_url);
|
||||||
let body = serde_json::json!({
|
let body = serde_json::json!({
|
||||||
"email": email
|
"email": email
|
||||||
});
|
});
|
||||||
@@ -609,8 +657,8 @@ impl Registration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up SSE connection for verification status
|
// Set up SSE connection for verification status (fallback method)
|
||||||
let sse_url = format!("{}/api/verification-status/{}", server_url, email);
|
let sse_url = format!("{}/api/verification-status/{}", config.server_url, email);
|
||||||
|
|
||||||
match EventSource::new(&sse_url) {
|
match EventSource::new(&sse_url) {
|
||||||
Ok(event_source) => {
|
Ok(event_source) => {
|
||||||
@@ -725,4 +773,42 @@ impl Registration {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to poll verification status
|
||||||
|
async fn poll_verification_status(
|
||||||
|
client: osiris_client::OsirisClient,
|
||||||
|
verification_id: String,
|
||||||
|
link: yew::html::Scope<Registration>,
|
||||||
|
) {
|
||||||
|
use gloo_timers::future::TimeoutFuture;
|
||||||
|
|
||||||
|
// Poll for up to 5 minutes (60 attempts * 5 seconds)
|
||||||
|
for _ in 0..60 {
|
||||||
|
TimeoutFuture::new(5_000).await;
|
||||||
|
|
||||||
|
match client.get_verification_status(&verification_id).await {
|
||||||
|
Ok(verification) => {
|
||||||
|
match verification.status {
|
||||||
|
osiris_client::VerificationStatus::Verified => {
|
||||||
|
link.send_message(RegistrationMsg::EmailVerified);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
osiris_client::VerificationStatus::Failed | osiris_client::VerificationStatus::Expired => {
|
||||||
|
link.send_message(RegistrationMsg::EmailVerificationFailed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Continue polling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
web_sys::console::error_1(&format!("Failed to check verification status: {:?}", e).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timeout after 5 minutes
|
||||||
|
link.send_message(RegistrationMsg::EmailVerificationFailed);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user