allow to change name
This commit is contained in:
24
src/main.rs
24
src/main.rs
@@ -90,6 +90,30 @@ impl Backend {
|
||||
let lang = language::language(&cookies, headers);
|
||||
(cookies, Req { client, lang })
|
||||
}
|
||||
|
||||
async fn set_client_name(&self, client: &Client, name: &str) -> Result<(), String> {
|
||||
if name.len() > 25 {
|
||||
return Err("Maximum 25 chars are allowed".into());
|
||||
}
|
||||
if name.len() < 3 {
|
||||
return Err("Minimum of 3 chars needed".into());
|
||||
}
|
||||
|
||||
match self {
|
||||
Backend::Sqlite(db) => {
|
||||
sqlx::query!(
|
||||
"UPDATE client SET name = ? WHERE uuid = ?;",
|
||||
name,
|
||||
client.uuid
|
||||
)
|
||||
.execute(db)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
Reference in New Issue
Block a user