refactor(comments): remove privacy consent checkbox and consented param
This commit is contained in:
parent
358dff152d
commit
59d5b9222a
@ -9,7 +9,6 @@ pub async fn create_comment(
|
|||||||
author_email: String,
|
author_email: String,
|
||||||
author_url: Option<String>,
|
author_url: Option<String>,
|
||||||
content_md: String,
|
content_md: String,
|
||||||
consented: bool,
|
|
||||||
) -> Result<CommentResponse, ServerFnError> {
|
) -> Result<CommentResponse, ServerFnError> {
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
{
|
{
|
||||||
@ -33,14 +32,6 @@ pub async fn create_comment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !consented {
|
|
||||||
return Ok(CommentResponse {
|
|
||||||
success: false,
|
|
||||||
message: "请同意隐私政策".to_string(),
|
|
||||||
error_code: Some("invalid_input".into()),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(e) = validate_comment_name(&author_name) {
|
if let Err(e) = validate_comment_name(&author_name) {
|
||||||
return Ok(CommentResponse {
|
return Ok(CommentResponse {
|
||||||
success: false,
|
success: false,
|
||||||
@ -200,8 +191,8 @@ pub async fn create_comment(
|
|||||||
.query_one(
|
.query_one(
|
||||||
"INSERT INTO comments \
|
"INSERT INTO comments \
|
||||||
(post_id, parent_id, depth, author_name, author_email, author_url, \
|
(post_id, parent_id, depth, author_name, author_email, author_url, \
|
||||||
content_md, content_html, content_hash, status, ip_address, user_agent, consented_at) \
|
content_md, content_html, content_hash, status, ip_address, user_agent) \
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'pending', $10, $11, NOW()) \
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'pending', $10, $11) \
|
||||||
RETURNING id",
|
RETURNING id",
|
||||||
&[
|
&[
|
||||||
&post_id,
|
&post_id,
|
||||||
|
|||||||
@ -14,7 +14,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
let mut author_url = use_signal(String::new);
|
let mut author_url = use_signal(String::new);
|
||||||
let mut content_md = use_signal(String::new);
|
let mut content_md = use_signal(String::new);
|
||||||
let mut honeypot = use_signal(String::new);
|
let mut honeypot = use_signal(String::new);
|
||||||
let mut consented = use_signal(|| false);
|
|
||||||
let mut submitting = use_signal(|| false);
|
let mut submitting = use_signal(|| false);
|
||||||
let mut message = use_signal(|| Option::<(String, &'static str)>::None);
|
let mut message = use_signal(|| Option::<(String, &'static str)>::None);
|
||||||
|
|
||||||
@ -103,22 +102,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
oninput: move |e| honeypot.set(e.value()),
|
oninput: move |e| honeypot.set(e.value()),
|
||||||
}
|
}
|
||||||
|
|
||||||
div { class: "flex items-start gap-2",
|
|
||||||
input {
|
|
||||||
r#type: "checkbox",
|
|
||||||
id: "consent-{post_id}-{parent_id.unwrap_or(0)}",
|
|
||||||
checked: consented(),
|
|
||||||
disabled: submitting(),
|
|
||||||
class: "mt-1 rounded border-gray-300 text-paper-accent focus:ring-paper-accent/30",
|
|
||||||
onchange: move |e| consented.set(e.checked()),
|
|
||||||
}
|
|
||||||
label {
|
|
||||||
r#for: "consent-{post_id}-{parent_id.unwrap_or(0)}",
|
|
||||||
class: "text-sm text-paper-secondary select-none cursor-pointer",
|
|
||||||
"同意隐私政策"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
button {
|
button {
|
||||||
class: BUTTON_PRIMARY_CLASS,
|
class: BUTTON_PRIMARY_CLASS,
|
||||||
disabled: submitting(),
|
disabled: submitting(),
|
||||||
@ -130,7 +113,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
let url_val = author_url();
|
let url_val = author_url();
|
||||||
let content = content_md();
|
let content = content_md();
|
||||||
let hp = honeypot();
|
let hp = honeypot();
|
||||||
let consent = consented();
|
|
||||||
|
|
||||||
if !hp.is_empty() {
|
if !hp.is_empty() {
|
||||||
return;
|
return;
|
||||||
@ -141,11 +123,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !consent {
|
|
||||||
message.set(Some(("请同意隐私政策".to_string(), "error")));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
submitting.set(true);
|
submitting.set(true);
|
||||||
message.set(None);
|
message.set(None);
|
||||||
|
|
||||||
@ -157,7 +134,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
email,
|
email,
|
||||||
if url_val.trim().is_empty() { None } else { Some(url_val) },
|
if url_val.trim().is_empty() { None } else { Some(url_val) },
|
||||||
content,
|
content,
|
||||||
consent,
|
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
submitting.set(false);
|
submitting.set(false);
|
||||||
@ -166,7 +142,6 @@ pub fn CommentForm(post_id: i32, parent_id: Option<i64>) -> Element {
|
|||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
if resp.success {
|
if resp.success {
|
||||||
content_md.set(String::new());
|
content_md.set(String::new());
|
||||||
consented.set(false);
|
|
||||||
message.set(Some((resp.message, "success")));
|
message.set(Some((resp.message, "success")));
|
||||||
if parent_id.is_some() {
|
if parent_id.is_some() {
|
||||||
active_reply.set(None);
|
active_reply.set(None);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user