added rng for registration time
This commit is contained in:
parent
6ec0bcb6c9
commit
571e9c8f84
4 changed files with 16 additions and 2 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1,6 +1,6 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "addr2line"
|
||||
|
@ -449,6 +449,7 @@ dependencies = [
|
|||
name = "dolltags"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"rand",
|
||||
"regex",
|
||||
"rocket",
|
||||
"rocket_db_pools",
|
||||
|
|
|
@ -7,5 +7,10 @@ edition = "2021"
|
|||
rocket = "0.5.1"
|
||||
rocket_dyn_templates = { version = "0.2.0", features = ["tera"] }
|
||||
rocket_db_pools = { version = "0.2.0", features = ["sqlx_sqlite"] }
|
||||
sqlx = { version = "0.7", default-features = false, features = ["sqlite", "macros", "chrono"] }
|
||||
sqlx = { version = "0.7", default-features = false, features = [
|
||||
"sqlite",
|
||||
"macros",
|
||||
"chrono",
|
||||
] }
|
||||
regex = "1.11"
|
||||
rand = "0.8"
|
||||
|
|
|
@ -9,6 +9,7 @@ use rocket_db_pools::Database;
|
|||
use rocket_dyn_templates::{context, Template};
|
||||
|
||||
pub mod db;
|
||||
pub mod rng;
|
||||
|
||||
pub fn id_public_to_db(id: &str) -> Option<i64> {
|
||||
let id_re = Regex::new(r"^\d{6}$").unwrap();
|
||||
|
|
7
src/rng.rs
Normal file
7
src/rng.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
use rand::{distributions::Uniform, prelude::Distribution, thread_rng};
|
||||
|
||||
pub fn generate_ids() -> Vec<i64> {
|
||||
let uniform = Uniform::new_inclusive::<i64, i64>(100_000, 999_999);
|
||||
let mut rng = thread_rng();
|
||||
(1..=10).map(|_| uniform.sample(&mut rng)).collect()
|
||||
}
|
Loading…
Add table
Reference in a new issue