diff options
author | TymanWasTaken <ty@blahaj.land> | 2024-01-29 06:17:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-29 11:17:10 +0000 |
commit | 0faf414cd958137ac60a1f37288994f3a1441780 (patch) | |
tree | df7199c0366893dc393d1cc53230a8f39e88d036 /atuin-client | |
parent | e1c2b9c783587547cbf740ee76206507fbbde330 (diff) |
feat: Add change-password command & support on server (#1615)
* Add change-password command & support on server
* Add a test for password change
* review: run format
---------
Co-authored-by: Ellie Huxtable <ellie@elliehuxtable.com>
Diffstat (limited to 'atuin-client')
-rw-r--r-- | atuin-client/src/api_client.rs | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs index dc835cfba..d53c9a364 100644 --- a/atuin-client/src/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -10,8 +10,9 @@ use reqwest::{ use atuin_common::{ api::{ - AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, LoginRequest, - LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, + AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest, + ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse, + SyncHistoryResponse, }, record::RecordStatus, }; @@ -359,4 +360,35 @@ impl<'a> Client<'a> { bail!("Unknown error"); } } + + pub async fn change_password( + &self, + current_password: String, + new_password: String, + ) -> Result<()> { + let url = format!("{}/account/password", self.sync_addr); + let url = Url::parse(url.as_str())?; + + let resp = self + .client + .patch(url) + .json(&ChangePasswordRequest { + current_password, + new_password, + }) + .send() + .await?; + + dbg!(&resp); + + if resp.status() == 401 { + bail!("current password is incorrect") + } else if resp.status() == 403 { + bail!("invalid login details"); + } else if resp.status() == 200 { + Ok(()) + } else { + bail!("Unknown error"); + } + } } |