summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-01-29 11:04:05 +0000
committerEllie Huxtable <ellie@elliehuxtable.com>2024-01-29 11:04:05 +0000
commitc750510f24ceb95f416157cd3f529c513d670a94 (patch)
tree625dac125727b3d2e9ee09cb03197953b4320f15
parent49ad411c6ba760b51b93c72434843dd57ed84a51 (diff)
review: run formatTymanWasTaken/main
-rw-r--r--atuin-client/src/api_client.rs26
-rw-r--r--atuin-server/src/handlers/user.rs5
-rw-r--r--atuin-server/src/router.rs2
-rw-r--r--atuin/src/command/client/account.rs4
-rw-r--r--atuin/src/command/client/account/change_password.rs18
-rw-r--r--atuin/tests/sync.rs4
6 files changed, 38 insertions, 21 deletions
diff --git a/atuin-client/src/api_client.rs b/atuin-client/src/api_client.rs
index 3999ef80..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, ChangePasswordRequest
+ AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest,
+ ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse,
+ SyncHistoryResponse,
},
record::RecordStatus,
};
@@ -360,17 +361,26 @@ impl<'a> Client<'a> {
}
}
- pub async fn change_password(&self, current_password: String, new_password: String) -> Result<()> {
+ 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?;
+ 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 {
diff --git a/atuin-server/src/handlers/user.rs b/atuin-server/src/handlers/user.rs
index 65050ead..70bea3fe 100644
--- a/atuin-server/src/handlers/user.rs
+++ b/atuin-server/src/handlers/user.rs
@@ -183,7 +183,10 @@ pub async fn change_password<DB: Database>(
) -> Result<Json<ChangePasswordResponse>, ErrorResponseStatus<'static>> {
let db = &state.0.database;
- let verified = verify_str(user.password.as_str(), change_password.current_password.borrow());
+ let verified = verify_str(
+ user.password.as_str(),
+ change_password.current_password.borrow(),
+ );
if !verified {
return Err(
ErrorResponse::reply("password is not correct").with_status(StatusCode::UNAUTHORIZED)
diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs
index b2a61831..dbb55b30 100644
--- a/atuin-server/src/router.rs
+++ b/atuin-server/src/router.rs
@@ -5,7 +5,7 @@ use axum::{
http::Request,
middleware::Next,
response::{IntoResponse, Response},
- routing::{delete, get, post, patch},
+ routing::{delete, get, patch, post},
Router,
};
use eyre::Result;
diff --git a/atuin/src/command/client/account.rs b/atuin/src/command/client/account.rs
index 6d20eade..75f8ed59 100644
--- a/atuin/src/command/client/account.rs
+++ b/atuin/src/command/client/account.rs
@@ -3,11 +3,11 @@ use eyre::Result;
use atuin_client::settings::Settings;
+pub mod change_password;
pub mod delete;
pub mod login;
pub mod logout;
pub mod register;
-pub mod change_password;
#[derive(Args, Debug)]
pub struct Cmd {
@@ -29,7 +29,7 @@ pub enum Commands {
// Delete your account, and all synced data
Delete,
- ChangePassword(change_password::Cmd)
+ ChangePassword(change_password::Cmd),
}
impl Cmd {
diff --git a/atuin/src/command/client/account/change_password.rs b/atuin/src/command/client/account/change_password.rs
index e3db454d..3b5ad6f5 100644
--- a/atuin/src/command/client/account/change_password.rs
+++ b/atuin/src/command/client/account/change_password.rs
@@ -31,24 +31,26 @@ pub async fn run(
settings.network_timeout,
)?;
- let current_password = current_password
- .clone()
- .unwrap_or_else(|| prompt_password("Please enter the current password: ").expect("Failed to read from input"));
+ let current_password = current_password.clone().unwrap_or_else(|| {
+ prompt_password("Please enter the current password: ").expect("Failed to read from input")
+ });
if current_password.is_empty() {
bail!("please provide the current password");
}
- let new_password = new_password
- .clone()
- .unwrap_or_else(|| prompt_password("Please enter the new password: ").expect("Failed to read from input"));
+ let new_password = new_password.clone().unwrap_or_else(|| {
+ prompt_password("Please enter the new password: ").expect("Failed to read from input")
+ });
if new_password.is_empty() {
bail!("please provide a new password");
}
- client.change_password(current_password, new_password).await?;
-
+ client
+ .change_password(current_password, new_password)
+ .await?;
+
println!("Account password successfully changed!");
Ok(())
diff --git a/atuin/tests/sync.rs b/atuin/tests/sync.rs
index ac85be12..6d7413c5 100644
--- a/atuin/tests/sync.rs
+++ b/atuin/tests/sync.rs
@@ -145,7 +145,9 @@ async fn change_password() {
let current_password = password;
let new_password = uuid_v7().as_simple().to_string();
- let result = client.change_password(current_password, new_password.clone()).await;
+ let result = client
+ .change_password(current_password, new_password.clone())
+ .await;
// the password change request succeeded
assert!(result.is_ok());