feat: add simple cli user management
This commit is contained in:
parent
3800534a51
commit
cc5f7856f6
3 changed files with 47 additions and 1 deletions
|
|
@ -51,6 +51,22 @@ impl User {
|
|||
.verify_password(password.as_ref().as_bytes(), &password_hash)
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub fn all(pool: &DbPool) -> Result<Vec<Self>, DbError> {
|
||||
let conn = pool.get()?;
|
||||
|
||||
let mut stmt = conn.prepare("select * from users")?;
|
||||
let users: Result<Vec<_>, _> = stmt.query_map((), Self::from_row)?.collect();
|
||||
|
||||
Ok(users?)
|
||||
}
|
||||
|
||||
pub fn remove_by_username(pool: &DbPool, username: impl AsRef<str>) -> Result<bool, DbError> {
|
||||
let conn = pool.get()?;
|
||||
let mut stmt = conn.prepare("delete from users where username = $1")?;
|
||||
|
||||
Ok(stmt.execute((username.as_ref(),))? > 0)
|
||||
}
|
||||
}
|
||||
|
||||
fn hash_password(password: impl AsRef<str>) -> String {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue