some validation, fuck this syntax is annoyingly restrictive
This commit is contained in:
parent
83612ebd53
commit
390ff5d6c9
3 changed files with 14 additions and 6 deletions
|
@ -1,7 +1,7 @@
|
|||
-- base schema
|
||||
|
||||
-- notnulls are tmp till i deal with proper validation
|
||||
create table doll_profiles (
|
||||
create table if not exists doll_profiles (
|
||||
id integer not null primary key, -- 000000 format
|
||||
created_at text not null default current_timestamp,
|
||||
updated_at text,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::db::schema::DollProfile;
|
||||
use sqlx::types::chrono;
|
||||
use sqlx::{pool::PoolConnection, types::chrono, Sqlite};
|
||||
|
||||
use super::schema::{CreateDollProfile, DollTagsDb};
|
||||
|
||||
|
@ -39,7 +39,11 @@ pub async fn check_ids(mut db: DollTagsDb, idents: &Vec<i64>) -> sqlx::Result<Ve
|
|||
query.fetch_all(&mut **db).await
|
||||
}
|
||||
|
||||
pub async fn id_exists(mut db: DollTagsDb, ident: i64, microchip_id: &str) -> sqlx::Result<bool> {
|
||||
pub async fn id_exists(
|
||||
db: &mut PoolConnection<Sqlite>,
|
||||
ident: i64,
|
||||
microchip_id: &str,
|
||||
) -> sqlx::Result<bool> {
|
||||
Ok(sqlx::query!(
|
||||
"select id from doll_profiles where id = ? or microchip_id = ?",
|
||||
ident,
|
||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -2,7 +2,7 @@
|
|||
extern crate rocket;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use db::doll::{self, check_ids};
|
||||
use db::doll::{self, check_ids, id_exists};
|
||||
use db::migrate::run_migrations;
|
||||
use db::schema::{CreateDollProfile, DollTags, DollTagsDb};
|
||||
use regex::Regex;
|
||||
|
@ -113,7 +113,7 @@ fn validate_chassis<'v>(a: &str, b: &str, c: &str, field: &str) -> form::Result<
|
|||
}
|
||||
|
||||
#[post("/register", data = "<tag>")]
|
||||
async fn handle_register(db: DollTagsDb, tag: Form<TagForm<'_>>) -> Template {
|
||||
async fn handle_register(mut db: DollTagsDb, tag: Form<TagForm<'_>>) -> Result<Template, Redirect> {
|
||||
println!("register: {:?}", tag);
|
||||
let id = id_public_to_db(&tag.ident).expect("wrong fmt");
|
||||
let pronouns = format!(
|
||||
|
@ -122,6 +122,10 @@ async fn handle_register(db: DollTagsDb, tag: Form<TagForm<'_>>) -> Template {
|
|||
);
|
||||
let microchip_id = tag.microchip_id.to_lowercase();
|
||||
|
||||
if id_exists(&mut *db, id, µchip_id).await.expect("fuck") {
|
||||
return Err(Redirect::found(uri!("/register")));
|
||||
}
|
||||
|
||||
doll::create(
|
||||
db,
|
||||
CreateDollProfile {
|
||||
|
@ -179,7 +183,7 @@ async fn handle_register(db: DollTagsDb, tag: Form<TagForm<'_>>) -> Template {
|
|||
.await
|
||||
.expect("fuck");
|
||||
|
||||
Template::render("register", context! {})
|
||||
Ok(Template::render("register", context! {ids: vec![123456]}))
|
||||
}
|
||||
|
||||
#[get("/profile?<ident>&<microchip_id>")]
|
||||
|
|
Loading…
Add table
Reference in a new issue