mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-22 00:03:49 +01:00
review: run format
This commit is contained in:
parent
49ad411c6b
commit
c750510f24
@ -10,8 +10,9 @@ use reqwest::{
|
|||||||
|
|
||||||
use atuin_common::{
|
use atuin_common::{
|
||||||
api::{
|
api::{
|
||||||
AddHistoryRequest, CountResponse, DeleteHistoryRequest, ErrorResponse, LoginRequest,
|
AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest,
|
||||||
LoginResponse, RegisterResponse, StatusResponse, SyncHistoryResponse, ChangePasswordRequest
|
ErrorResponse, LoginRequest, LoginResponse, RegisterResponse, StatusResponse,
|
||||||
|
SyncHistoryResponse,
|
||||||
},
|
},
|
||||||
record::RecordStatus,
|
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 = format!("{}/account/password", self.sync_addr);
|
||||||
let url = Url::parse(url.as_str())?;
|
let url = Url::parse(url.as_str())?;
|
||||||
|
|
||||||
let resp = self.client.patch(url).json(&ChangePasswordRequest {
|
let resp = self
|
||||||
current_password,
|
.client
|
||||||
new_password
|
.patch(url)
|
||||||
}).send().await?;
|
.json(&ChangePasswordRequest {
|
||||||
|
current_password,
|
||||||
|
new_password,
|
||||||
|
})
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
|
||||||
dbg!(&resp);
|
dbg!(&resp);
|
||||||
|
|
||||||
if resp.status() == 401 {
|
if resp.status() == 401 {
|
||||||
bail!("current password is incorrect")
|
bail!("current password is incorrect")
|
||||||
} else if resp.status() == 403 {
|
} else if resp.status() == 403 {
|
||||||
|
@ -183,7 +183,10 @@ pub async fn change_password<DB: Database>(
|
|||||||
) -> Result<Json<ChangePasswordResponse>, ErrorResponseStatus<'static>> {
|
) -> Result<Json<ChangePasswordResponse>, ErrorResponseStatus<'static>> {
|
||||||
let db = &state.0.database;
|
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 {
|
if !verified {
|
||||||
return Err(
|
return Err(
|
||||||
ErrorResponse::reply("password is not correct").with_status(StatusCode::UNAUTHORIZED)
|
ErrorResponse::reply("password is not correct").with_status(StatusCode::UNAUTHORIZED)
|
||||||
|
@ -5,7 +5,7 @@ use axum::{
|
|||||||
http::Request,
|
http::Request,
|
||||||
middleware::Next,
|
middleware::Next,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
routing::{delete, get, post, patch},
|
routing::{delete, get, patch, post},
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use eyre::Result;
|
use eyre::Result;
|
||||||
|
@ -3,11 +3,11 @@ use eyre::Result;
|
|||||||
|
|
||||||
use atuin_client::settings::Settings;
|
use atuin_client::settings::Settings;
|
||||||
|
|
||||||
|
pub mod change_password;
|
||||||
pub mod delete;
|
pub mod delete;
|
||||||
pub mod login;
|
pub mod login;
|
||||||
pub mod logout;
|
pub mod logout;
|
||||||
pub mod register;
|
pub mod register;
|
||||||
pub mod change_password;
|
|
||||||
|
|
||||||
#[derive(Args, Debug)]
|
#[derive(Args, Debug)]
|
||||||
pub struct Cmd {
|
pub struct Cmd {
|
||||||
@ -29,7 +29,7 @@ pub enum Commands {
|
|||||||
// Delete your account, and all synced data
|
// Delete your account, and all synced data
|
||||||
Delete,
|
Delete,
|
||||||
|
|
||||||
ChangePassword(change_password::Cmd)
|
ChangePassword(change_password::Cmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
|
@ -31,24 +31,26 @@ pub async fn run(
|
|||||||
settings.network_timeout,
|
settings.network_timeout,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let current_password = current_password
|
let current_password = current_password.clone().unwrap_or_else(|| {
|
||||||
.clone()
|
prompt_password("Please enter the current password: ").expect("Failed to read from input")
|
||||||
.unwrap_or_else(|| prompt_password("Please enter the current password: ").expect("Failed to read from input"));
|
});
|
||||||
|
|
||||||
if current_password.is_empty() {
|
if current_password.is_empty() {
|
||||||
bail!("please provide the current password");
|
bail!("please provide the current password");
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_password = new_password
|
let new_password = new_password.clone().unwrap_or_else(|| {
|
||||||
.clone()
|
prompt_password("Please enter the new password: ").expect("Failed to read from input")
|
||||||
.unwrap_or_else(|| prompt_password("Please enter the new password: ").expect("Failed to read from input"));
|
});
|
||||||
|
|
||||||
if new_password.is_empty() {
|
if new_password.is_empty() {
|
||||||
bail!("please provide a new password");
|
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!");
|
println!("Account password successfully changed!");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -145,7 +145,9 @@ async fn change_password() {
|
|||||||
|
|
||||||
let current_password = password;
|
let current_password = password;
|
||||||
let new_password = uuid_v7().as_simple().to_string();
|
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
|
// the password change request succeeded
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
Loading…
Reference in New Issue
Block a user