diff options
author | Martin Ashby <martin@ashbysoft.com> | 2022-12-29 23:32:46 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2022-12-29 23:32:46 +0000 |
commit | 9be5acc275711d0a6a717ac5564a86185ec1d613 (patch) | |
tree | 44ebff30eb551c4358e8c5ccd5fa5602ac78ba86 /comments | |
parent | 30927637f2ae8af9224eb6daeca25793a0675bca (diff) | |
download | mfashby.net-9be5acc275711d0a6a717ac5564a86185ec1d613.tar.gz mfashby.net-9be5acc275711d0a6a717ac5564a86185ec1d613.tar.bz2 mfashby.net-9be5acc275711d0a6a717ac5564a86185ec1d613.tar.xz mfashby.net-9be5acc275711d0a6a717ac5564a86185ec1d613.zip |
comments api appears functional...
Diffstat (limited to 'comments')
-rw-r--r-- | comments/.env | 1 | ||||
-rw-r--r-- | comments/src/main.rs | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/comments/.env b/comments/.env new file mode 100644 index 0000000..e7df468 --- /dev/null +++ b/comments/.env @@ -0,0 +1 @@ +DATABASE_URL=postgres:/// diff --git a/comments/src/main.rs b/comments/src/main.rs index 287b89e..95cd9ae 100644 --- a/comments/src/main.rs +++ b/comments/src/main.rs @@ -135,16 +135,20 @@ struct PostComment { capcha_answer: String, } +struct CapchaAnswer { + answer:String +} + async fn post_comments( State(ctx): State<Ctx>, Form(post_comment): Form<PostComment>) -> Result<Redirect,(StatusCode,String)> { let capcha_id: Uuid = post_comment.capcha_id.parse() .map_err(|_| {(StatusCode::BAD_REQUEST, "Invalid capcha_id".to_string())})?; - let ans: String = sqlx::query_as!("select answer from capchas where id = $1", capcha_id) + let ans: CapchaAnswer = sqlx::query_as!(CapchaAnswer, "select answer from capchas where id = $1", capcha_id) .fetch_one(&ctx.pool) .await .map_err(internal_error)?; - if post_comment.capcha_answer != ans { + if post_comment.capcha_answer != ans.answer { return Err((StatusCode::BAD_REQUEST, "Capcha was wrong!".to_string())); } sqlx::query!("insert into comments(url,author,comment) values($1, $2, $3)", post_comment.url, post_comment.author, post_comment.comment) |