review: run format

This commit is contained in:
Ellie Huxtable 2024-01-29 11:04:05 +00:00
parent 49ad411c6b
commit c750510f24
6 changed files with 38 additions and 21 deletions

View File

@ -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,14 +361,23 @@ 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);

View File

@ -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)

View File

@ -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;

View File

@ -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 {

View File

@ -31,23 +31,25 @@ 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!");

View File

@ -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());