fixes
This commit is contained in:
+36
-18
@@ -537,7 +537,7 @@ pub async fn confirm_account(
|
||||
let now_time = Utc::now();
|
||||
let now = now_time.to_rfc3339();
|
||||
let token_hash = hash_token(req.token.trim());
|
||||
let row: Option<(i64, String, Option<String>)> = sqlx::query_as(queries::get(
|
||||
let row = sqlx::query(queries::get(
|
||||
state.db.kind(),
|
||||
queries::AUTH_FIND_CONFIRMATION_TOKEN,
|
||||
))
|
||||
@@ -545,9 +545,12 @@ pub async fn confirm_account(
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let (user_id, expires_at, used_at) = row.ok_or_else(|| {
|
||||
let row = row.ok_or_else(|| {
|
||||
AuthError::bad_request("The confirmation link is invalid or has expired.")
|
||||
})?;
|
||||
let user_id: i64 = row.try_get(0).map_err(AuthError::database)?;
|
||||
let expires_at = crate::row_decode::text(&row, 1).map_err(AuthError::database)?;
|
||||
let used_at = crate::row_decode::optional_text(&row, 2).map_err(AuthError::database)?;
|
||||
let expires_at = chrono::DateTime::parse_from_rfc3339(&expires_at)
|
||||
.map_err(|_| AuthError::bad_request("The confirmation link is invalid or has expired."))?
|
||||
.with_timezone(&Utc);
|
||||
@@ -601,7 +604,7 @@ async fn directory_profile_metadata(
|
||||
state: &SharedState,
|
||||
user: &User,
|
||||
) -> Result<(bool, Option<String>, Option<String>, Option<String>), AuthError> {
|
||||
let row: Option<(String, Option<String>)> = sqlx::query_as(queries::get(
|
||||
let row = sqlx::query(queries::get(
|
||||
state.db.kind(),
|
||||
queries::AUTH_DIRECTORY_PROFILE_BY_USER,
|
||||
))
|
||||
@@ -609,9 +612,11 @@ async fn directory_profile_metadata(
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let Some((provider, display_name)) = row else {
|
||||
let Some(row) = row else {
|
||||
return Ok((false, None, None, None));
|
||||
};
|
||||
let provider = crate::row_decode::text(&row, 0).map_err(AuthError::database)?;
|
||||
let display_name = crate::row_decode::optional_text(&row, 1).map_err(AuthError::database)?;
|
||||
if provider == "local" {
|
||||
return Ok((false, None, None, None));
|
||||
}
|
||||
@@ -842,16 +847,19 @@ pub async fn confirm_account_action(
|
||||
) -> Result<Json<serde_json::Value>, AuthError> {
|
||||
let now = Utc::now();
|
||||
let hash = hash_token(req.token.trim());
|
||||
let row: Option<(i64, String, Option<String>, String, Option<String>)> = sqlx::query_as(
|
||||
queries::get(state.db.kind(), queries::AUTH_ACCOUNT_ACTION_BY_TOKEN),
|
||||
)
|
||||
.bind(&hash)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let (user_id, action, payload, expires_at, used_at) = row.ok_or_else(|| {
|
||||
let row = sqlx::query(queries::get(state.db.kind(), queries::AUTH_ACCOUNT_ACTION_BY_TOKEN))
|
||||
.bind(&hash)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let row = row.ok_or_else(|| {
|
||||
AuthError::bad_request("The confirmation link is invalid or has expired.")
|
||||
})?;
|
||||
let user_id: i64 = row.try_get(0).map_err(AuthError::database)?;
|
||||
let action = crate::row_decode::text(&row, 1).map_err(AuthError::database)?;
|
||||
let payload = crate::row_decode::optional_text(&row, 2).map_err(AuthError::database)?;
|
||||
let expires_at = crate::row_decode::text(&row, 3).map_err(AuthError::database)?;
|
||||
let used_at = crate::row_decode::optional_text(&row, 4).map_err(AuthError::database)?;
|
||||
let expires = chrono::DateTime::parse_from_rfc3339(&expires_at)
|
||||
.map_err(|_| AuthError::bad_request("The confirmation link is invalid or has expired."))?
|
||||
.with_timezone(&Utc);
|
||||
@@ -1364,16 +1372,23 @@ pub async fn accept_share_invitation(
|
||||
AxumPath(token): AxumPath<String>,
|
||||
) -> Result<Json<serde_json::Value>, AuthError> {
|
||||
let token_hash = hash_token(token.trim());
|
||||
let row: Option<(String, String, i64, String, String, Option<String>)> = sqlx::query_as(
|
||||
queries::get(state.db.kind(), queries::SHARE_INVITATION_FIND_TOKEN),
|
||||
)
|
||||
let row = sqlx::query(queries::get(
|
||||
state.db.kind(),
|
||||
queries::SHARE_INVITATION_FIND_TOKEN,
|
||||
))
|
||||
.bind(&token_hash)
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let (kind, slug, user_id, permission, expires_at, accepted_at) = row.ok_or_else(|| {
|
||||
let row = row.ok_or_else(|| {
|
||||
AuthError::bad_request("The sharing invitation is invalid or has expired.")
|
||||
})?;
|
||||
let kind = crate::row_decode::text(&row, 0).map_err(AuthError::database)?;
|
||||
let slug = crate::row_decode::text(&row, 1).map_err(AuthError::database)?;
|
||||
let user_id: i64 = row.try_get(2).map_err(AuthError::database)?;
|
||||
let permission = crate::row_decode::text(&row, 3).map_err(AuthError::database)?;
|
||||
let expires_at = crate::row_decode::text(&row, 4).map_err(AuthError::database)?;
|
||||
let accepted_at = crate::row_decode::optional_text(&row, 5).map_err(AuthError::database)?;
|
||||
let expires = chrono::DateTime::parse_from_rfc3339(&expires_at)
|
||||
.map_err(|_| AuthError::bad_request("The sharing invitation is invalid or has expired."))?
|
||||
.with_timezone(&Utc);
|
||||
@@ -1727,7 +1742,7 @@ pub async fn confirm_reset(
|
||||
let now_time = Utc::now();
|
||||
let now = now_time.to_rfc3339();
|
||||
let token_hash = hash_token(req.token.trim());
|
||||
let token_row: Option<(i64, String, Option<String>)> = sqlx::query_as(queries::get(
|
||||
let token_row = sqlx::query(queries::get(
|
||||
state.db.kind(),
|
||||
queries::AUTH_FIND_RESET_TOKEN,
|
||||
))
|
||||
@@ -1735,8 +1750,11 @@ pub async fn confirm_reset(
|
||||
.fetch_optional(state.db.pool())
|
||||
.await
|
||||
.map_err(AuthError::database)?;
|
||||
let (user_id, expires_at, used_at) = token_row
|
||||
let token_row = token_row
|
||||
.ok_or_else(|| AuthError::bad_request("The reset link is invalid or has expired."))?;
|
||||
let user_id: i64 = token_row.try_get(0).map_err(AuthError::database)?;
|
||||
let expires_at = crate::row_decode::text(&token_row, 1).map_err(AuthError::database)?;
|
||||
let used_at = crate::row_decode::optional_text(&token_row, 2).map_err(AuthError::database)?;
|
||||
let expires_at = chrono::DateTime::parse_from_rfc3339(&expires_at)
|
||||
.map_err(|_| AuthError::bad_request("The reset link is invalid or has expired."))?
|
||||
.with_timezone(&Utc);
|
||||
|
||||
Reference in New Issue
Block a user