Compare commits
3
Commits
53ed0060c8
...
476b25fecf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
476b25fecf
|
||
|
|
4cc42697cb
|
||
|
|
1a885274a8
|
Generated
+1
-1
@@ -1580,7 +1580,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "soaricarus_auth"
|
name = "soaricarus_auth"
|
||||||
version = "0.8.2"
|
version = "0.8.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"argon2",
|
"argon2",
|
||||||
"axum",
|
"axum",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "soaricarus_auth"
|
name = "soaricarus_auth"
|
||||||
version = "0.8.2"
|
version = "0.8.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.95"
|
rust-version = "1.95"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
+36
-10
@@ -35,7 +35,11 @@ pub mod request {
|
|||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
pub fn is_valid(&self) -> bool {
|
pub fn is_valid(&self) -> bool {
|
||||||
!self.user_id.is_nil() || !self.username.is_empty() || !self.current_password.is_empty() || !self.updated_password.is_empty() || !self.confirmed_password.is_empty()
|
!self.user_id.is_nil()
|
||||||
|
|| !self.username.is_empty()
|
||||||
|
|| !self.current_password.is_empty()
|
||||||
|
|| !self.updated_password.is_empty()
|
||||||
|
|| !self.confirmed_password.is_empty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -320,21 +324,43 @@ pub mod endpoint {
|
|||||||
|
|
||||||
match repo::user::get(&pool, &payload.username).await {
|
match repo::user::get(&pool, &payload.username).await {
|
||||||
Ok(user) => {
|
Ok(user) => {
|
||||||
if hashing::verify_password(&payload.current_password, user.password.clone()).unwrap() {
|
if hashing::verify_password(&payload.current_password, user.password.clone())
|
||||||
|
.unwrap()
|
||||||
|
{
|
||||||
match repo::salt::get(&pool, &user.salt_id).await {
|
match repo::salt::get(&pool, &user.salt_id).await {
|
||||||
Ok(salt) => {
|
Ok(salt) => {
|
||||||
// Left off here
|
|
||||||
let updated_salt_string = hashing::generate_salt().unwrap();
|
let updated_salt_string = hashing::generate_salt().unwrap();
|
||||||
let mut updated_salt = simodels::user::salt::Salt::default();
|
let mut updated_salt = simodels::user::salt::Salt::default();
|
||||||
updated_salt.salt = updated_salt_string.to_string();
|
updated_salt.salt = updated_salt_string.to_string();
|
||||||
updated_salt.id = salt.id.clone();
|
updated_salt.id = salt.id.clone();
|
||||||
let updated_hashed_password = hashing::hash_password(&payload.updated_password, &updated_salt_string).unwrap();
|
let updated_hashed_password = hashing::hash_password(
|
||||||
|
&payload.updated_password,
|
||||||
|
&updated_salt_string,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
match repo::user::update_password(&pool, &user, &updated_hashed_password).await {
|
match repo::salt::update_salt(&pool, &salt, &updated_salt.salt).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
response.message = "Successful".to_string();
|
match repo::user::update_password(
|
||||||
response.data.push(user.id);
|
&pool,
|
||||||
(axum::http::StatusCode::OK, axum::Json(response))
|
&user,
|
||||||
|
&updated_hashed_password,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
response.message = "Successful".to_string();
|
||||||
|
response.data.push(user.id);
|
||||||
|
(axum::http::StatusCode::OK, axum::Json(response))
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
|
(
|
||||||
|
axum::http::StatusCode::BAD_REQUEST,
|
||||||
|
axum::Json(response),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
response.message = err.to_string();
|
response.message = err.to_string();
|
||||||
@@ -343,12 +369,12 @@ pub mod endpoint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
response.message = err.to_string();
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// invalid
|
response.message = "Invalid".to_string();
|
||||||
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
(axum::http::StatusCode::BAD_REQUEST, axum::Json(response))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-5
@@ -44,25 +44,30 @@ pub mod user {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_password(pool: &sqlx::PgPool, user: &simodels::user::User, password: &str) -> Result<bool, sqlx::Error> {
|
pub async fn update_password(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
user: &simodels::user::User,
|
||||||
|
password: &str,
|
||||||
|
) -> Result<bool, sqlx::Error> {
|
||||||
match sqlx::query(
|
match sqlx::query(
|
||||||
r#"
|
r#"
|
||||||
UPDATE "user" SET password = $1 WHERE id = $2
|
UPDATE "user" SET password = $1 WHERE id = $2
|
||||||
"#
|
"#,
|
||||||
)
|
)
|
||||||
.bind(password)
|
.bind(password)
|
||||||
.bind(user.id)
|
.bind(user.id)
|
||||||
.execute(pool)
|
.execute(pool)
|
||||||
// .fetch_optional(pool)
|
// .fetch_optional(pool)
|
||||||
.await {
|
.await
|
||||||
|
{
|
||||||
Ok(r) => {
|
Ok(r) => {
|
||||||
return if r.rows_affected() > 0 {
|
return if r.rows_affected() > 0 {
|
||||||
Ok(true)
|
Ok(true)
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
Err(err) => Err(err)
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,4 +223,28 @@ pub mod salt {
|
|||||||
Err(sqlx::Error::RowNotFound)
|
Err(sqlx::Error::RowNotFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_salt(
|
||||||
|
pool: &sqlx::PgPool,
|
||||||
|
salt: &simodels::user::salt::Salt,
|
||||||
|
updated_salt: &str,
|
||||||
|
) -> Result<bool, sqlx::Error> {
|
||||||
|
match sqlx::query(
|
||||||
|
r#"
|
||||||
|
UPDATE "salt" SET salt = $1 WHERE id = $2
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.bind(updated_salt)
|
||||||
|
.bind(salt.id)
|
||||||
|
.execute(pool)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(row) => {
|
||||||
|
let result = if row.rows_affected() > 0 { true } else { false };
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user