Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,14 @@ pub struct Claims {
pub iat: i64, // issued at
pub token_type: String, // "access" or "refresh"
}

#[derive(Debug, Deserialize)]
pub struct VerifyOtpRequest {
pub email: String,
pub otp_code: String,
}

#[derive(Debug, Deserialize)]
pub struct ResendOtpRequest {
pub email: String,
}
15 changes: 15 additions & 0 deletions src/services/auth_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ impl AuthService {
.ok_or(AuthError::UserNotFound)
}

/// Get user by email
pub async fn get_user_by_email(
pool: &PgPool,
email: &str,
) -> Result<User, AuthError> {
sqlx::query_as::<_, User>(
"SELECT id, email, password_hash, first_name, last_name, role, is_active, created_at, updated_at FROM users WHERE email = $1"
)
.bind(email)
.fetch_optional(pool)
.await
.map_err(|e| AuthError::DatabaseError(e.to_string()))?
.ok_or(AuthError::UserNotFound)
}

/// Verify refresh token and generate new access token
pub async fn refresh_access_token(
pool: &PgPool,
Expand Down
Loading