/// Makes sure that a username is valid and not already used
Makes sure that a username is valid and not already used
Makes sure that a username is valid and not already used
pub async fn validate_username(localuname: &'_ str, db: &Database) -> Result<(), GaneshaError> {
    if localuname.len() < 3 {
        return Err(UserSideError::UsernameTooShort.into());
    }
    // A user with that name should not exist!
    let filter = doc! { "localuname": localuname };
    let result = User::collection(db).find_one(filter, None).await?;
    if result.is_some() {
        return Err(UserSideError::UsernameAlreadyUsed(localuname.to_string()).into());
    };
    Ok(())
}
pub async fn validate_username ( localuname : & ' _ str , db : & Database ) -> Result < ( ) , GaneshaError > { if localuname . len ( ) < 3 { return Err ( UserSideError :: UsernameTooShort . into ( ) ) ; } // A user with that name should not exist! let filter = doc ! { " " localuname } ; let result = User :: collection ( db ) . find_one ( filter , None ) . await ? ; if result . is_some ( ) { return Err ( UserSideError :: UsernameAlreadyUsed ( localuname . to_string ( ) ) . into ( ) ) ; } ; Ok ( ( ) ) }
Makes sure that a username is valid and not already used
Makes sure that a username is valid and not already used
localuname
&'_ str
db
&Database