Saving changes
Rust Build / Rustfmt (pull_request) Successful in 51s
Rust Build / Check (pull_request) Successful in 1m29s
Rust Build / Test Suite (pull_request) Successful in 1m38s
Rust Build / Clippy (pull_request) Successful in 1m41s
Rust Build / build (pull_request) Successful in 1m35s
Rust Build / Rustfmt (pull_request) Successful in 51s
Rust Build / Check (pull_request) Successful in 1m29s
Rust Build / Test Suite (pull_request) Successful in 1m38s
Rust Build / Clippy (pull_request) Successful in 1m41s
Rust Build / build (pull_request) Successful in 1m35s
This commit is contained in:
+91
-71
@@ -48,7 +48,11 @@ pub mod request {
|
|||||||
|
|
||||||
impl UpdatePasswordRequest {
|
impl UpdatePasswordRequest {
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
if self.user_id.is_nil() || !self.current_password.is_empty() || !self.updated_password.is_empty() || !self.confirmed_password.is_empty() {
|
if self.user_id.is_nil()
|
||||||
|
|| !self.current_password.is_empty()
|
||||||
|
|| !self.updated_password.is_empty()
|
||||||
|
|| !self.confirmed_password.is_empty()
|
||||||
|
{
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
self.updated_password == self.confirmed_password
|
self.updated_password == self.confirmed_password
|
||||||
@@ -90,7 +94,7 @@ pub mod response {
|
|||||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||||
pub struct UpdatePasswordResponse {
|
pub struct UpdatePasswordResponse {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub data: Vec<uuid::Uuid>
|
pub data: Vec<uuid::Uuid>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,7 +538,6 @@ pub async fn refresh_token(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Endpoint for a updating password
|
/// Endpoint for a updating password
|
||||||
#[utoipa::path(
|
#[utoipa::path(
|
||||||
post,
|
post,
|
||||||
@@ -553,7 +556,10 @@ pub async fn refresh_token(
|
|||||||
pub async fn update_password(
|
pub async fn update_password(
|
||||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||||
axum::Json(payload): axum::Json<request::UpdatePasswordRequest>,
|
axum::Json(payload): axum::Json<request::UpdatePasswordRequest>,
|
||||||
) -> (axum::http::StatusCode, axum::Json<response::UpdatePasswordResponse>) {
|
) -> (
|
||||||
|
axum::http::StatusCode,
|
||||||
|
axum::Json<response::UpdatePasswordResponse>,
|
||||||
|
) {
|
||||||
if !payload.is_valid() {
|
if !payload.is_valid() {
|
||||||
(
|
(
|
||||||
axum::http::StatusCode::BAD_REQUEST,
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
@@ -563,14 +569,11 @@ pub async fn update_password(
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
let verify_password = |current_password, hashed_password| -> Result<bool, std::io::Error> {
|
let verify_password = |current_password, hashed_password| -> Result<bool, std::io::Error> {
|
||||||
match hashing::verify_password(current_password, hashed_password) {
|
match hashing::verify_password(current_password, hashed_password) {
|
||||||
Ok(matches) => {
|
Ok(matches) => Ok(matches),
|
||||||
Ok(matches)
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo::user::get_with_id(&pool, &payload.user_id).await {
|
match repo::user::get_with_id(&pool, &payload.user_id).await {
|
||||||
@@ -581,49 +584,56 @@ pub async fn update_password(
|
|||||||
if matches {
|
if matches {
|
||||||
let (generate_salt, mut salt) = super::register::generate_the_salt();
|
let (generate_salt, mut salt) = super::register::generate_the_salt();
|
||||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||||
let updated_hashed_password = match hashing::hash_password(&payload.updated_password, &generate_salt) {
|
let updated_hashed_password = match hashing::hash_password(
|
||||||
Ok(hashed) => {
|
&payload.updated_password,
|
||||||
hashed
|
&generate_salt,
|
||||||
}
|
) {
|
||||||
|
Ok(hashed) => hashed,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo::user::update_password(&pool, &user, &updated_hashed_password).await {
|
match repo::user::update_password(
|
||||||
Ok(()) => {
|
&pool,
|
||||||
(axum::http::StatusCode::OK,
|
&user,
|
||||||
|
&updated_hashed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => (
|
||||||
|
axum::http::StatusCode::OK,
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
||||||
data: vec![user.id],
|
data: vec![user.id],
|
||||||
}))
|
}),
|
||||||
}
|
),
|
||||||
Err(err) => {
|
Err(err) => (
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
message: err.to_string(),
|
message: err.to_string(),
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
}))
|
}),
|
||||||
}
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
(
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
message: String::from("Issue updating password"),
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
data: Vec::new(),
|
message: String::from("Issue updating password"),
|
||||||
}))
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => (
|
||||||
(
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
message: err.to_string(),
|
||||||
message: err.to_string(),
|
data: Vec::new(),
|
||||||
data: Vec::new(),
|
}),
|
||||||
}),
|
),
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -636,60 +646,70 @@ pub async fn update_password(
|
|||||||
match verify_password(&payload.current_password, hashed_password) {
|
match verify_password(&payload.current_password, hashed_password) {
|
||||||
Ok(matches) => {
|
Ok(matches) => {
|
||||||
if matches {
|
if matches {
|
||||||
let (generate_salt, mut salt) = super::register::generate_the_salt();
|
let (generate_salt, mut salt) =
|
||||||
|
super::register::generate_the_salt();
|
||||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||||
let updated_hashed_password = match hashing::hash_password(&payload.updated_password, &generate_salt) {
|
let updated_hashed_password = match hashing::hash_password(
|
||||||
Ok(hashed) => {
|
&payload.updated_password,
|
||||||
hashed
|
&generate_salt,
|
||||||
}
|
) {
|
||||||
|
Ok(hashed) => hashed,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
match repo::service::update_passphrase(&pool, &service_user, &updated_hashed_password).await {
|
match repo::service::update_passphrase(
|
||||||
Ok(()) => {
|
&pool,
|
||||||
(axum::http::StatusCode::OK,
|
&service_user,
|
||||||
|
&updated_hashed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(()) => (
|
||||||
|
axum::http::StatusCode::OK,
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
message: String::from(
|
||||||
|
super::messages::SUCCESSFUL_MESSAGE,
|
||||||
|
),
|
||||||
data: vec![service_user.id],
|
data: vec![service_user.id],
|
||||||
}))
|
}),
|
||||||
}
|
),
|
||||||
Err(err) => {
|
Err(err) => (
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
message: err.to_string(),
|
message: err.to_string(),
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
}))
|
}),
|
||||||
}
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
(
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
message: String::from("Issue updating password"),
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
data: Vec::new(),
|
message: String::from("Issue updating password"),
|
||||||
}))
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => (
|
||||||
(
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
|
message: err.to_string(),
|
||||||
|
data: Vec::new(),
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => (
|
||||||
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
axum::Json(response::UpdatePasswordResponse {
|
||||||
message: err.to_string(),
|
message: err.to_string(),
|
||||||
data: Vec::new(),
|
data: Vec::new(),
|
||||||
}),
|
}),
|
||||||
)
|
),
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR,
|
|
||||||
axum::Json(response::UpdatePasswordResponse {
|
|
||||||
message: err.to_string(),
|
|
||||||
data: Vec::new(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -117,7 +117,8 @@ pub mod user {
|
|||||||
.bind(updated_hashed_password)
|
.bind(updated_hashed_password)
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await {
|
.await
|
||||||
|
{
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
if row.rows_affected() > 0 {
|
if row.rows_affected() > 0 {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
+2
-1
@@ -167,7 +167,8 @@ pub async fn update_passphrase(
|
|||||||
.bind(updated_hashed_passphrase)
|
.bind(updated_hashed_passphrase)
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
.await {
|
.await
|
||||||
|
{
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
if row.rows_affected() > 0 {
|
if row.rows_affected() > 0 {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user