feat(gpodder): add create_user method to AuthStore
This commit is contained in:
parent
2a8917f21d
commit
b44a47fefd
4 changed files with 40 additions and 7 deletions
|
|
@ -1,8 +1,8 @@
|
|||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
use argon2::{Argon2, PasswordHash, PasswordVerifier};
|
||||
use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use rand::Rng;
|
||||
use rand::{rngs::OsRng, Rng};
|
||||
|
||||
use crate::{
|
||||
models,
|
||||
|
|
@ -41,6 +41,17 @@ impl GpodderRepository {
|
|||
self.store.get_user(username)?.ok_or(AuthErr::UnknownUser)
|
||||
}
|
||||
|
||||
pub fn create_user(&self, username: &str, password: &str) -> Result<models::User, AuthErr> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
|
||||
let password_hash = Argon2::default()
|
||||
.hash_password(password.as_bytes(), &salt)
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
self.store.insert_user(username, &password_hash)
|
||||
}
|
||||
|
||||
pub fn validate_credentials(
|
||||
&self,
|
||||
username: &str,
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ pub trait AuthStore {
|
|||
/// Retrieve the user with the given username
|
||||
fn get_user(&self, username: &str) -> Result<Option<User>, AuthErr>;
|
||||
|
||||
/// Insert a new user into the data store
|
||||
fn insert_user(&self, username: &str, password_hash: &str) -> Result<User, AuthErr>;
|
||||
|
||||
/// Create a new session for a user with the given session ID
|
||||
fn insert_session(&self, session: &Session) -> Result<(), AuthErr>;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue