Introduce extract!(), rewrite part of uiaa username handling
This commit is contained in:
@@ -61,6 +61,16 @@ macro_rules! extract_variant {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! extract {
|
||||||
|
($e:expr_2021, $out:ident in $variant:pat) => {
|
||||||
|
match $e {
|
||||||
|
| $variant => Some($out),
|
||||||
|
| _ => None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/// Functor for !is_empty()
|
/// Functor for !is_empty()
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! is_not_empty {
|
macro_rules! is_not_empty {
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ use ruma::{
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
use tuwunel_core::{
|
use tuwunel_core::{
|
||||||
Err, Result, debug_warn, err, error, implement, utils,
|
Err, Result, debug_warn, err, error, extract, implement,
|
||||||
utils::{hash, string::EMPTY},
|
utils::{self, BoolExt, hash, string::EMPTY},
|
||||||
};
|
};
|
||||||
use tuwunel_database::{Deserialized, Json, Map};
|
use tuwunel_database::{Deserialized, Json, Map};
|
||||||
|
|
||||||
@@ -89,15 +89,9 @@ pub async fn try_auth(
|
|||||||
match auth {
|
match auth {
|
||||||
// Find out what the user completed
|
// Find out what the user completed
|
||||||
| AuthData::Password(Password { identifier, password, user, .. }) => {
|
| AuthData::Password(Password { identifier, password, user, .. }) => {
|
||||||
let username = if let Some(UserIdentifier::UserIdOrLocalpart(username)) = identifier {
|
let username = extract!(identifier, x in Some(UserIdentifier::UserIdOrLocalpart(x)))
|
||||||
username
|
.or_else(|| cfg!(feature = "element_hacks").and(user.as_ref()))
|
||||||
} else if cfg!(feature = "element_hacks")
|
.ok_or(err!(Request(Unrecognized("Identifier type not recognized."))))?;
|
||||||
&& let Some(username) = user
|
|
||||||
{
|
|
||||||
username
|
|
||||||
} else {
|
|
||||||
return Err!(Request(Unrecognized("Identifier type not recognized.")));
|
|
||||||
};
|
|
||||||
|
|
||||||
let user_id_from_username = UserId::parse_with_server_name(
|
let user_id_from_username = UserId::parse_with_server_name(
|
||||||
username.clone(),
|
username.clone(),
|
||||||
|
|||||||
Reference in New Issue
Block a user