style: apply rustfmt to backend codebase
- Apply rustfmt to all Rust source files in backend/ - Fix trailing whitespace inconsistencies - Standardize formatting across handlers, models, and services - Improve code readability with consistent formatting These changes are purely stylistic and do not affect functionality. All CI checks now pass with proper formatting.
This commit is contained in:
parent
6b7e4d4016
commit
ee0feb77ef
41 changed files with 1266 additions and 819 deletions
|
|
@ -2,18 +2,18 @@ use mongodb::bson::{doc, oid::ObjectId};
|
|||
use mongodb::Collection;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use mongodb::bson::DateTime;
|
||||
use crate::auth::password::verify_password;
|
||||
use mongodb::bson::DateTime;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<ObjectId>,
|
||||
|
||||
|
||||
pub email: String,
|
||||
|
||||
|
||||
pub username: String,
|
||||
|
||||
|
||||
pub password_hash: String,
|
||||
|
||||
/// Password recovery phrase hash (zero-knowledge)
|
||||
|
|
@ -54,10 +54,10 @@ impl User {
|
|||
) -> Result<Self, anyhow::Error> {
|
||||
// Import PasswordService
|
||||
use crate::auth::password::PasswordService;
|
||||
|
||||
|
||||
// Hash the password
|
||||
let password_hash = PasswordService::hash_password(&password)?;
|
||||
|
||||
|
||||
// Hash the recovery phrase if provided
|
||||
let recovery_phrase_hash = if let Some(phrase) = recovery_phrase {
|
||||
Some(PasswordService::hash_password(&phrase)?)
|
||||
|
|
@ -94,7 +94,7 @@ impl User {
|
|||
if !self.recovery_enabled || self.recovery_phrase_hash.is_none() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
|
||||
let hash = self.recovery_phrase_hash.as_ref().unwrap();
|
||||
verify_password(phrase, hash)
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ impl User {
|
|||
/// Update the password hash (increments token_version to invalidate all tokens)
|
||||
pub fn update_password(&mut self, new_password: String) -> Result<(), anyhow::Error> {
|
||||
use crate::auth::password::PasswordService;
|
||||
|
||||
|
||||
self.password_hash = PasswordService::hash_password(&new_password)?;
|
||||
self.token_version += 1;
|
||||
Ok(())
|
||||
|
|
@ -111,7 +111,7 @@ impl User {
|
|||
/// Set or update the recovery phrase
|
||||
pub fn set_recovery_phrase(&mut self, phrase: String) -> Result<(), anyhow::Error> {
|
||||
use crate::auth::password::PasswordService;
|
||||
|
||||
|
||||
self.recovery_phrase_hash = Some(PasswordService::hash_password(&phrase)?);
|
||||
self.recovery_enabled = true;
|
||||
Ok(())
|
||||
|
|
@ -156,13 +156,14 @@ impl UserRepository {
|
|||
|
||||
/// Find a user by ID
|
||||
pub async fn find_by_id(&self, id: &ObjectId) -> mongodb::error::Result<Option<User>> {
|
||||
self.collection
|
||||
.find_one(doc! { "_id": id }, None)
|
||||
.await
|
||||
self.collection.find_one(doc! { "_id": id }, None).await
|
||||
}
|
||||
|
||||
/// Find a user by verification token
|
||||
pub async fn find_by_verification_token(&self, token: &str) -> mongodb::error::Result<Option<User>> {
|
||||
pub async fn find_by_verification_token(
|
||||
&self,
|
||||
token: &str,
|
||||
) -> mongodb::error::Result<Option<User>> {
|
||||
self.collection
|
||||
.find_one(doc! { "verification_token": token }, None)
|
||||
.await
|
||||
|
|
@ -177,12 +178,16 @@ impl UserRepository {
|
|||
}
|
||||
|
||||
/// Update the token version - silently fails if ObjectId is invalid
|
||||
pub async fn update_token_version(&self, user_id: &str, version: i32) -> mongodb::error::Result<()> {
|
||||
pub async fn update_token_version(
|
||||
&self,
|
||||
user_id: &str,
|
||||
version: i32,
|
||||
) -> mongodb::error::Result<()> {
|
||||
let oid = match ObjectId::parse_str(user_id) {
|
||||
Ok(id) => id,
|
||||
Err(_) => return Ok(()), // Silently fail if invalid ObjectId
|
||||
};
|
||||
|
||||
|
||||
self.collection
|
||||
.update_one(
|
||||
doc! { "_id": oid },
|
||||
|
|
@ -204,7 +209,7 @@ impl UserRepository {
|
|||
/// Update last active timestamp
|
||||
pub async fn update_last_active(&self, user_id: &ObjectId) -> mongodb::error::Result<()> {
|
||||
use mongodb::bson::DateTime;
|
||||
|
||||
|
||||
let now = DateTime::now();
|
||||
self.collection
|
||||
.update_one(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue