feature (accounts): implemented session restoring
This commit is contained in:
parent
e776d8a631
commit
30e1f4cd6b
|
@ -1,5 +1,5 @@
|
|||
target/
|
||||
data/
|
||||
|
||||
# IDE stuff
|
||||
.idea
|
||||
|
||||
# Rust stuff
|
||||
target/
|
||||
|
|
|
@ -14,6 +14,7 @@ pub struct Account {
|
|||
pub async fn account_add(homeserver:&str, username:&str, password:&str) -> anyhow::Result<Account> {
|
||||
let client = Client::builder()
|
||||
.homeserver_url(homeserver)
|
||||
.sled_store("data", Some("supersecure"))?
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
|
@ -38,10 +39,21 @@ pub async fn account_add(homeserver:&str, username:&str, password:&str) -> anyho
|
|||
|
||||
let serialized_account = serde_json::to_string(&account)?;
|
||||
println!("serialized account: {}", serialized_account);
|
||||
// TODO: save serialized account info in userdata dir
|
||||
|
||||
Ok(account)
|
||||
}
|
||||
|
||||
pub async fn account_login(account: Account) -> anyhow::Result<()> {
|
||||
let client = Client::builder()
|
||||
.homeserver_url(account.homeserver)
|
||||
.sled_store("data", Some("supersecure"))?
|
||||
.build()
|
||||
.await?;
|
||||
|
||||
client.restore_login(account.session.clone()).await?;
|
||||
|
||||
println!("restored account: {} device ID: {}", &account.session.user_id, &account.session.device_id);
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,13 +1,19 @@
|
|||
mod ui;
|
||||
mod accounts;
|
||||
|
||||
use matrix_sdk::ruma::exports::serde_json;
|
||||
use tokio::time::{sleep, Duration};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
accounts::account_add("https://nerdcult.net", "test", "abcd1234").await?;
|
||||
// accounts::account_add("https://nerdcult.net", "test", "abcd1234").await?;
|
||||
|
||||
let serialized_account = "{\"homeserver\":\"https://nerdcult.net\",\"session\":{\"access_token\":\"U2XH1vfu3dJTTPV7BIeZh2yGiMN49vBF\",\"user_id\":\"@test:nerdcult.net\",\"device_id\":\"UsdqFbcEC3\"},\"sync_token\":null}";
|
||||
let account: accounts::Account = serde_json::from_str(serialized_account)?;
|
||||
|
||||
accounts::account_login(account).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Reference in New Issue