- Created SelfFreezoneClient in Self components
- Wraps SDK FreezoneScriptClient for Self-specific operations
- Implements send_verification_email method
- Uses Rhai script template for email verification
- Includes template variable substitution
- Added serde-wasm-bindgen dependency
Usage:
let client = SelfFreezoneClient::builder()
.supervisor_url("http://localhost:8080")
.secret("my-secret")
.build()?;
client.send_verification_email(
"user@example.com",
"123456",
"https://verify.com/abc"
).await?;
63 lines
1.6 KiB
Plaintext
63 lines
1.6 KiB
Plaintext
// Email verification script template for Self
|
|
// Variables: {{email}}, {{code}}, {{url}}
|
|
|
|
print("=== Self: Sending Email Verification ===");
|
|
print("Email: {{email}}");
|
|
print("Code: {{code}}");
|
|
|
|
// Get freezone context
|
|
let freezone_pubkey = "04e58314c13ea3f9caed882001a5090797b12563d5f9bbd7f16efe020e060c780b446862311501e2e9653416527d2634ff8a8050ff3a085baccd7ddcb94185ff56";
|
|
let freezone_ctx = get_context([freezone_pubkey]);
|
|
|
|
// Get email client from context
|
|
let email_client = freezone_ctx.get("email_client");
|
|
if email_client == () {
|
|
print("ERROR: Email client not configured in freezone context");
|
|
return #{
|
|
success: false,
|
|
error: "Email client not configured"
|
|
};
|
|
}
|
|
|
|
// Get verification email template
|
|
let template = freezone_ctx.get("verification_email");
|
|
if template == () {
|
|
print("ERROR: Verification email template not found");
|
|
return #{
|
|
success: false,
|
|
error: "Email template not configured"
|
|
};
|
|
}
|
|
|
|
// Create verification record
|
|
let verification = new_verification()
|
|
.email("{{email}}")
|
|
.code("{{code}}")
|
|
.transport("email")
|
|
.expires_in(86400); // 24 hours
|
|
|
|
freezone_ctx.save(verification);
|
|
print("✓ Verification record created");
|
|
|
|
// Send email using template
|
|
let result = email_client.send_from_template(
|
|
template,
|
|
"{{email}}",
|
|
#{
|
|
url: "{{url}}",
|
|
code: "{{code}}"
|
|
}
|
|
);
|
|
|
|
print("✓ Verification email sent successfully");
|
|
print(" To: {{email}}");
|
|
print(" Code: {{code}}");
|
|
|
|
// Return success response
|
|
#{
|
|
success: true,
|
|
email: "{{email}}",
|
|
code: "{{code}}",
|
|
expires_in: 86400
|
|
}
|