mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-14 20:56:49 +00:00
Split login case bodies into handlers.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
3056b60159
commit
2a2486182a
4 files changed
+175
-147
No files matched your search
@@ -0,0 +1,48 @@
|
||||
use ruma::{
|
||||
OwnedUserId, UserId,
|
||||
api::client::{
|
||||
session::login::v3::{ApplicationService, Request},
|
||||
uiaa,
|
||||
},
|
||||
};
|
||||
use tuwunel_core::{Err, Result, err};
|
||||
use tuwunel_service::Services;
|
||||
|
||||
use crate::Ruma;
|
||||
|
||||
pub(super) async fn handle_login(
|
||||
services: &Services,
|
||||
body: &Ruma<Request>,
|
||||
info: &ApplicationService,
|
||||
) -> Result<OwnedUserId> {
|
||||
#[allow(deprecated)]
|
||||
let ApplicationService { identifier, user } = info;
|
||||
|
||||
let Some(ref info) = body.appservice_info else {
|
||||
return Err!(Request(MissingToken("Missing appservice token.")));
|
||||
};
|
||||
|
||||
let user_id = if let Some(uiaa::UserIdentifier::UserIdOrLocalpart(user_id)) = identifier {
|
||||
UserId::parse_with_server_name(user_id, &services.config.server_name)
|
||||
} else if let Some(user) = user {
|
||||
UserId::parse_with_server_name(user, &services.config.server_name)
|
||||
} else {
|
||||
return Err!(Request(Unknown(debug_warn!(
|
||||
?body.login_info,
|
||||
"Valid identifier or username was not provided (invalid or unsupported login type?)"
|
||||
))));
|
||||
}
|
||||
.map_err(|e| err!(Request(InvalidUsername(warn!("Username is invalid: {e}")))))?;
|
||||
|
||||
if !services.globals.user_is_local(&user_id) {
|
||||
return Err!(Request(Unknown("User ID does not belong to this homeserver")));
|
||||
}
|
||||
|
||||
let emergency_mode_enabled = services.config.emergency_password.is_some();
|
||||
|
||||
if !info.is_user_match(&user_id) && !emergency_mode_enabled {
|
||||
return Err!(Request(Exclusive("Username is not in an appservice namespace.")));
|
||||
}
|
||||
|
||||
Ok(user_id)
|
||||
}
|
||||
Reference in new issue
Block a user