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
|
|
@ -23,7 +23,7 @@ impl Claims {
|
|||
pub fn new(user_id: String, email: String, token_version: i32) -> Self {
|
||||
let now = Utc::now();
|
||||
let exp = now + Duration::minutes(15); // Access token expires in 15 minutes
|
||||
|
||||
|
||||
Self {
|
||||
sub: user_id.clone(),
|
||||
exp: exp.timestamp() as usize,
|
||||
|
|
@ -49,7 +49,7 @@ impl RefreshClaims {
|
|||
pub fn new(user_id: String, token_version: i32) -> Self {
|
||||
let now = Utc::now();
|
||||
let exp = now + Duration::days(30); // Refresh token expires in 30 days
|
||||
|
||||
|
||||
Self {
|
||||
sub: user_id.clone(),
|
||||
exp: exp.timestamp() as usize,
|
||||
|
|
@ -74,7 +74,7 @@ impl JwtService {
|
|||
pub fn new(config: JwtConfig) -> Self {
|
||||
let encoding_key = EncodingKey::from_secret(config.secret.as_ref());
|
||||
let decoding_key = DecodingKey::from_secret(config.secret.as_ref());
|
||||
|
||||
|
||||
Self {
|
||||
config,
|
||||
refresh_tokens: Arc::new(RwLock::new(HashMap::new())),
|
||||
|
|
@ -99,24 +99,16 @@ impl JwtService {
|
|||
|
||||
/// Validate access token
|
||||
pub fn validate_token(&self, token: &str) -> Result<Claims> {
|
||||
let token_data = decode::<Claims>(
|
||||
token,
|
||||
&self.decoding_key,
|
||||
&Validation::default()
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!("Invalid token: {}", e))?;
|
||||
let token_data = decode::<Claims>(token, &self.decoding_key, &Validation::default())
|
||||
.map_err(|e| anyhow::anyhow!("Invalid token: {}", e))?;
|
||||
|
||||
Ok(token_data.claims)
|
||||
}
|
||||
|
||||
/// Validate refresh token
|
||||
pub fn validate_refresh_token(&self, token: &str) -> Result<RefreshClaims> {
|
||||
let token_data = decode::<RefreshClaims>(
|
||||
token,
|
||||
&self.decoding_key,
|
||||
&Validation::default()
|
||||
)
|
||||
.map_err(|e| anyhow::anyhow!("Invalid refresh token: {}", e))?;
|
||||
let token_data = decode::<RefreshClaims>(token, &self.decoding_key, &Validation::default())
|
||||
.map_err(|e| anyhow::anyhow!("Invalid refresh token: {}", e))?;
|
||||
|
||||
Ok(token_data.claims)
|
||||
}
|
||||
|
|
@ -124,10 +116,11 @@ impl JwtService {
|
|||
/// Store refresh token for a user
|
||||
pub async fn store_refresh_token(&self, user_id: &str, token: &str) -> Result<()> {
|
||||
let mut tokens = self.refresh_tokens.write().await;
|
||||
tokens.entry(user_id.to_string())
|
||||
tokens
|
||||
.entry(user_id.to_string())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(token.to_string());
|
||||
|
||||
|
||||
// Keep only last 5 tokens per user
|
||||
if let Some(user_tokens) = tokens.get_mut(user_id) {
|
||||
user_tokens.sort();
|
||||
|
|
@ -136,7 +129,7 @@ impl JwtService {
|
|||
*user_tokens = user_tokens.split_off(user_tokens.len() - 5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -151,13 +144,18 @@ impl JwtService {
|
|||
}
|
||||
|
||||
/// Rotate refresh token (remove old, add new)
|
||||
pub async fn rotate_refresh_token(&self, user_id: &str, old_token: &str, new_token: &str) -> Result<()> {
|
||||
pub async fn rotate_refresh_token(
|
||||
&self,
|
||||
user_id: &str,
|
||||
old_token: &str,
|
||||
new_token: &str,
|
||||
) -> Result<()> {
|
||||
// Remove old token
|
||||
self.revoke_refresh_token(old_token).await?;
|
||||
|
||||
|
||||
// Add new token
|
||||
self.store_refresh_token(user_id, new_token).await?;
|
||||
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue