Validate wallet address when logging in
This commit is contained in:
parent
7e5917a821
commit
9f1f950aa3
3 changed files with 16 additions and 6 deletions
|
@ -8,6 +8,7 @@ use crate::models::users::queries::{
|
|||
get_user_by_name,
|
||||
get_user_by_wallet_address,
|
||||
};
|
||||
use crate::models::users::types::validate_wallet_address;
|
||||
use crate::utils::crypto::verify_password;
|
||||
use super::types::{TokenRequest, TokenResponse};
|
||||
use super::utils::generate_access_token;
|
||||
|
@ -31,7 +32,7 @@ async fn token_view(
|
|||
"ethereum" => {
|
||||
let wallet_address = request_data.wallet_address.as_ref()
|
||||
.ok_or(ValidationError("wallet address is required"))?;
|
||||
// Wallet address must be in lowercase
|
||||
validate_wallet_address(wallet_address)?;
|
||||
get_user_by_wallet_address(db_client, wallet_address).await?
|
||||
},
|
||||
_ => {
|
||||
|
|
|
@ -15,7 +15,10 @@ use crate::models::profiles::queries::{
|
|||
search_profile_by_wallet_address,
|
||||
};
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
use crate::models::users::types::validate_wallet_address;
|
||||
use crate::models::users::types::{
|
||||
validate_wallet_address,
|
||||
WALLET_CURRENCY_CODE,
|
||||
};
|
||||
use super::types::SearchResults;
|
||||
|
||||
enum SearchQuery {
|
||||
|
@ -49,12 +52,12 @@ fn parse_search_query(search_query: &str) -> SearchQuery {
|
|||
};
|
||||
match parse_profile_query(search_query) {
|
||||
Ok((username, instance)) => {
|
||||
return SearchQuery::ProfileQuery(username, instance);
|
||||
SearchQuery::ProfileQuery(username, instance)
|
||||
},
|
||||
Err(_) => {
|
||||
return SearchQuery::Unknown;
|
||||
SearchQuery::Unknown
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async fn search_profiles(
|
||||
|
@ -132,7 +135,11 @@ pub async fn search(
|
|||
},
|
||||
SearchQuery::WalletAddress(address) => {
|
||||
// Search is case insensitive
|
||||
profiles = search_profile_by_wallet_address(db_client, "ETH", &address).await?;
|
||||
profiles = search_profile_by_wallet_address(
|
||||
db_client,
|
||||
WALLET_CURRENCY_CODE,
|
||||
&address,
|
||||
).await?;
|
||||
},
|
||||
SearchQuery::Unknown => (), // ignore
|
||||
};
|
||||
|
|
|
@ -62,6 +62,8 @@ pub fn validate_local_username(username: &str) -> Result<(), ValidationError> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub const WALLET_CURRENCY_CODE: &str = "ETH";
|
||||
|
||||
/// Verifies that wallet address is valid ethereum address
|
||||
pub fn validate_wallet_address(wallet_address: &str) -> Result<(), ValidationError> {
|
||||
// Address should be lowercase
|
||||
|
|
Loading…
Reference in a new issue