aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/command/client/account/register.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/command/client/account/register.rs')
-rw-r--r--crates/turtle/src/command/client/account/register.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/crates/turtle/src/command/client/account/register.rs b/crates/turtle/src/command/client/account/register.rs
new file mode 100644
index 00000000..548c2739
--- /dev/null
+++ b/crates/turtle/src/command/client/account/register.rs
@@ -0,0 +1,67 @@
+use clap::Parser;
+use eyre::{Result, bail};
+
+use super::login::or_user_input;
+use crate::atuin_client::settings::{Settings, SyncAuth};
+
+#[derive(Parser, Debug)]
+pub struct Cmd {
+ #[clap(long, short)]
+ pub username: Option<String>,
+
+ #[clap(long, short)]
+ pub password: Option<String>,
+
+ #[clap(long, short)]
+ pub email: Option<String>,
+}
+
+impl Cmd {
+ pub async fn run(&self, settings: &Settings) -> Result<()> {
+ match settings.resolve_sync_auth().await {
+ SyncAuth::Legacy { .. } => {
+ println!("You are already logged in.");
+ println!("Run 'atuin logout' to log out.");
+ return Ok(());
+ }
+
+ SyncAuth::NotLoggedIn { .. } => {}
+ }
+
+ // Legacy registration flow
+ println!("Registering for an Atuin Sync account");
+
+ let username = or_user_input(self.username.clone(), "username");
+ let email = or_user_input(self.email.clone(), "email");
+ let password = self
+ .password
+ .clone()
+ .unwrap_or_else(super::login::read_user_password);
+
+ if password.is_empty() {
+ bail!("please provide a password");
+ }
+
+ let session = crate::atuin_client::api_client::register(
+ settings.sync_address.as_str(),
+ &username,
+ &email,
+ &password,
+ )
+ .await?;
+
+ let meta = Settings::meta_store().await?;
+ meta.save_session(&session.session).await?;
+
+ let _key = crate::atuin_client::encryption::load_key(settings)?;
+
+ println!(
+ "Registration successful! Please make a note of your key (run 'atuin key') and keep it safe."
+ );
+ println!(
+ "You will need it to log in on other devices, and we cannot help recover it if you lose it."
+ );
+
+ Ok(())
+ }
+}