fix many clones()

This commit is contained in:
2023-05-24 12:11:55 +02:00
parent cf45036642
commit 99296d4060
8 changed files with 54 additions and 71 deletions

View File

@ -49,7 +49,7 @@ WHERE id like ?
.ok()
}
pub async fn find_by_name(db: &SqlitePool, name: String) -> Option<Self> {
pub async fn find_by_name(db: &SqlitePool, name: &str) -> Option<Self> {
sqlx::query_as!(
User,
"
@ -79,7 +79,7 @@ ORDER BY name
.unwrap() //TODO: fixme
}
pub async fn create(db: &SqlitePool, name: String, is_guest: bool) -> bool {
pub async fn create(db: &SqlitePool, name: &str, is_guest: bool) -> bool {
sqlx::query!(
"INSERT INTO USER(name, is_guest) VALUES (?,?)",
name,
@ -103,7 +103,7 @@ ORDER BY name
.unwrap(); //Okay, because we can only create a User of a valid id
}
pub async fn login(db: &SqlitePool, name: String, pw: String) -> Result<Self, LoginError> {
pub async fn login(db: &SqlitePool, name: &str, pw: &str) -> Result<Self, LoginError> {
let Some(user) = User::find_by_name(db, name).await else {
return Err(LoginError::InvalidAuthenticationCombo); // Username not found
};
@ -133,7 +133,7 @@ ORDER BY name
.unwrap(); //Okay, because we can only create a User of a valid id
}
pub async fn update_pw(&self, db: &SqlitePool, pw: String) {
pub async fn update_pw(&self, db: &SqlitePool, pw: &str) {
let pw = Self::get_hashed_pw(&pw);
sqlx::query!("UPDATE user SET pw = ? where id = ?", pw, self.id)
.execute(db)