mirror of
https://git.alemi.dev/guestbook.rs.git
synced 2024-11-12 19:39:28 +01:00
fix: always same avatar for anon users
This commit is contained in:
parent
76ae5bcdd2
commit
189226f841
3 changed files with 1 additions and 12 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -906,7 +906,6 @@ dependencies = [
|
|||
"html-escape",
|
||||
"mail-send",
|
||||
"md-5",
|
||||
"rand",
|
||||
"sailfish",
|
||||
"serde",
|
||||
"serde-inline-default",
|
||||
|
|
|
@ -15,7 +15,6 @@ edition = "2021"
|
|||
# core
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = "0.3"
|
||||
rand = "0.8"
|
||||
md-5 = "0.10"
|
||||
toml = "0.8"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
|
11
src/model.rs
11
src/model.rs
|
@ -1,5 +1,4 @@
|
|||
use md5::{Md5, Digest};
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use chrono::{DateTime, Utc};
|
||||
use sqlx::Row;
|
||||
|
@ -52,7 +51,7 @@ pub struct PageView {
|
|||
impl From<&Page> for PageView {
|
||||
fn from(page: &Page) -> Self {
|
||||
let mut hasher = Md5::new();
|
||||
hasher.update(page.contact.as_deref().unwrap_or(&random_string(36)).as_bytes());
|
||||
hasher.update(page.contact.as_deref().unwrap_or(&format!("{} - {}", page.body, page.timestamp)).as_bytes());
|
||||
let avatar = format!("{:x}", hasher.finalize());
|
||||
|
||||
let url = match page.contact.as_deref() {
|
||||
|
@ -127,11 +126,3 @@ fn _non_empty_string(input: String) -> Option<String> {
|
|||
false => Some(input),
|
||||
}
|
||||
}
|
||||
|
||||
fn random_string(len: usize) -> String {
|
||||
rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(len)
|
||||
.map(char::from)
|
||||
.collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue