mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-10 16:24:45 +00:00
40 lines
1.0 KiB
Rust
40 lines
1.0 KiB
Rust
|
use directories::ProjectDirs;
|
||
|
use ruma_identifiers::UserId;
|
||
|
|
||
|
pub struct Data(sled::Db);
|
||
|
|
||
|
impl Data {
|
||
|
pub fn set_hostname(&self, hostname: &str) {
|
||
|
self.0.insert("hostname", hostname).unwrap();
|
||
|
}
|
||
|
pub fn hostname(&self) -> String {
|
||
|
String::from_utf8(self.0.get("hostname").unwrap().unwrap().to_vec()).unwrap()
|
||
|
}
|
||
|
pub fn load_or_create() -> Self {
|
||
|
Data(
|
||
|
sled::open(
|
||
|
ProjectDirs::from("xyz", "koesters", "matrixserver")
|
||
|
.unwrap()
|
||
|
.data_dir(),
|
||
|
)
|
||
|
.unwrap(),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
pub fn user_exists(&self, user_id: &UserId) -> bool {
|
||
|
self.0
|
||
|
.open_tree("username_password")
|
||
|
.unwrap()
|
||
|
.contains_key(user_id.to_string())
|
||
|
.unwrap()
|
||
|
}
|
||
|
|
||
|
pub fn user_add(&self, user_id: UserId, password: Option<String>) {
|
||
|
self.0
|
||
|
.open_tree("username_password")
|
||
|
.unwrap()
|
||
|
.insert(user_id.to_string(), &*password.unwrap_or_default())
|
||
|
.unwrap();
|
||
|
}
|
||
|
}
|