Login in a more restorable way
This commit is contained in:
parent
808d45b893
commit
d560b860bf
15
src/main.rs
15
src/main.rs
|
@ -8,6 +8,7 @@ use matrix_sdk::ruma::events::SyncMessageEvent;
|
||||||
use matrix_sdk::ruma::UserId;
|
use matrix_sdk::ruma::UserId;
|
||||||
use matrix_sdk::{Client, Session};
|
use matrix_sdk::{Client, Session};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::fs::File;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::io::AsyncReadExt;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
@ -79,14 +80,22 @@ async fn main() -> anyhow::Result<()> {
|
||||||
};
|
};
|
||||||
|
|
||||||
eprintln!("Logging in!");
|
eprintln!("Logging in!");
|
||||||
client
|
|
||||||
|
if config.matrix_persist.exists() {
|
||||||
|
let session: Session = serde_json::from_reader(File::open(config.matrix_persist)?)?;
|
||||||
|
client.restore_login(session).await?;
|
||||||
|
} else {
|
||||||
|
let session: Session = client
|
||||||
.login(
|
.login(
|
||||||
mxid.localpart(),
|
mxid.localpart(),
|
||||||
&config.matrix_password,
|
&config.matrix_password,
|
||||||
Some("mxmonzo"),
|
None,
|
||||||
Some("rei's MxMonzo"),
|
Some("rei's MxMonzo"),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?
|
||||||
|
.into();
|
||||||
|
serde_json::to_writer(File::create(config.matrix_persist)?, &session)?;
|
||||||
|
}
|
||||||
|
|
||||||
eprintln!("Syncing once!");
|
eprintln!("Syncing once!");
|
||||||
client.sync_once(SyncSettings::new()).await?;
|
client.sync_once(SyncSettings::new()).await?;
|
||||||
|
|
|
@ -19,6 +19,7 @@ pub struct Config {
|
||||||
pub matrix_room: String,
|
pub matrix_room: String,
|
||||||
pub matrix_store: PathBuf,
|
pub matrix_store: PathBuf,
|
||||||
pub matrix_password: String,
|
pub matrix_password: String,
|
||||||
|
pub matrix_persist: PathBuf,
|
||||||
pub monzo_persist: PathBuf,
|
pub monzo_persist: PathBuf,
|
||||||
pub monzo_client_id: String,
|
pub monzo_client_id: String,
|
||||||
pub monzo_client_secret: String,
|
pub monzo_client_secret: String,
|
||||||
|
|
Loading…
Reference in New Issue