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/src/api_client.rs | |
| parent | feat: make history list format configurable (#1638) (diff) | |
| download | atuin-0faf414cd958137ac60a1f37288994f3a1441780.zip | |
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/src/api_client.rs')
| -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 dc835cfb..d53c9a36 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"); + } + } } |
