mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
move userdevicesessionid_uiaarequest to service
This commit is contained in:
parent
a1fe0f3fff
commit
fb534d8140
5 changed files with 42 additions and 70 deletions
|
|
@ -1,9 +1,11 @@
|
|||
use std::{collections::BTreeMap, sync::RwLock};
|
||||
|
||||
use ruma::{
|
||||
api::client::{
|
||||
error::ErrorKind,
|
||||
uiaa::{AuthData, AuthType, Password, UiaaInfo, UserIdentifier},
|
||||
},
|
||||
CanonicalJsonValue, DeviceId, UserId,
|
||||
CanonicalJsonValue, DeviceId, OwnedDeviceId, OwnedUserId, UserId,
|
||||
};
|
||||
use tracing::error;
|
||||
|
||||
|
|
@ -16,10 +18,20 @@ mod data;
|
|||
pub(crate) use data::Data;
|
||||
|
||||
pub(crate) struct Service {
|
||||
pub(crate) db: &'static dyn Data,
|
||||
db: &'static dyn Data,
|
||||
userdevicesessionid_uiaarequest: RwLock<
|
||||
BTreeMap<(OwnedUserId, OwnedDeviceId, String), CanonicalJsonValue>,
|
||||
>,
|
||||
}
|
||||
|
||||
impl Service {
|
||||
pub(crate) fn new(db: &'static dyn Data) -> Self {
|
||||
Self {
|
||||
db,
|
||||
userdevicesessionid_uiaarequest: RwLock::new(BTreeMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new Uiaa session. Make sure the session token is unique.
|
||||
pub(crate) fn create(
|
||||
&self,
|
||||
|
|
@ -28,14 +40,20 @@ impl Service {
|
|||
uiaainfo: &UiaaInfo,
|
||||
json_body: &CanonicalJsonValue,
|
||||
) -> Result<()> {
|
||||
self.db.set_uiaa_request(
|
||||
user_id,
|
||||
device_id,
|
||||
// TODO: better session error handling (why is it optional in
|
||||
// ruma?)
|
||||
uiaainfo.session.as_ref().expect("session should be set"),
|
||||
json_body,
|
||||
)?;
|
||||
self.userdevicesessionid_uiaarequest.write().unwrap().insert(
|
||||
(
|
||||
user_id.to_owned(),
|
||||
device_id.to_owned(),
|
||||
// TODO: better session error handling (why is it optional in
|
||||
// ruma?)
|
||||
uiaainfo
|
||||
.session
|
||||
.as_ref()
|
||||
.expect("session should be set")
|
||||
.to_owned(),
|
||||
),
|
||||
json_body.to_owned(),
|
||||
);
|
||||
self.db.update_uiaa_session(
|
||||
user_id,
|
||||
device_id,
|
||||
|
|
@ -160,6 +178,14 @@ impl Service {
|
|||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Option<CanonicalJsonValue> {
|
||||
self.db.get_uiaa_request(user_id, device_id, session)
|
||||
self.userdevicesessionid_uiaarequest
|
||||
.read()
|
||||
.unwrap()
|
||||
.get(&(
|
||||
user_id.to_owned(),
|
||||
device_id.to_owned(),
|
||||
session.to_owned(),
|
||||
))
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,8 @@
|
|||
use ruma::{api::client::uiaa::UiaaInfo, CanonicalJsonValue, DeviceId, UserId};
|
||||
use ruma::{api::client::uiaa::UiaaInfo, DeviceId, UserId};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
pub(crate) trait Data: Send + Sync {
|
||||
fn set_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
request: &CanonicalJsonValue,
|
||||
) -> Result<()>;
|
||||
|
||||
fn get_uiaa_request(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
device_id: &DeviceId,
|
||||
session: &str,
|
||||
) -> Option<CanonicalJsonValue>;
|
||||
|
||||
fn update_uiaa_session(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue