-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refa: architecture of data api (#161)
* refa: moved mfa_info to features/queries architecture * refa: applied changed to hypermedia as well * refa(noop): rename Pool<Postgres> to PgPool * fix: querie wasn't using conn from transaction on query * refa: remove data/router abstraction * refa(noop): rename pluggy to openfinance in code * sqlx: cargo sqlx prepared for offline eval in CI
- Loading branch information
1 parent
ed0e34d
commit 09c4c38
Showing
16 changed files
with
124 additions
and
127 deletions.
There are no files selected for viewing
23 changes: 0 additions & 23 deletions
23
.sqlx/query-13f75e061ccc4ac07d596168f716a4d3127d81cdaf1cfa6b4e716d2db7172e82.json
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
.sqlx/query-f2dc772be994698db840e3913c76066e0d4eff5c8d5d2f4dc1b5c7985c19259c.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::sync::Arc; | ||
|
||
use askama_axum::IntoResponse; | ||
use axum::{extract::State, http::StatusCode, routing::get, Json, Router}; | ||
use serde::Serialize; | ||
|
||
use crate::{auth::AuthSession, hypermedia::schema::auth::MfaTokenForm, AppState}; | ||
|
||
pub fn private_router() -> Router<Arc<AppState>> { | ||
Router::new().route("/api/auth/mfa", get(mfa_info).post(mfa_verify)) | ||
} | ||
|
||
#[derive(Serialize)] | ||
struct MfaInfo { | ||
otp_url: String, | ||
} | ||
|
||
async fn mfa_info( | ||
auth_session: AuthSession, | ||
State(shared_state): State<Arc<AppState>>, | ||
) -> Result<Json<MfaInfo>, StatusCode> { | ||
let Some(user) = auth_session.user else { | ||
return Err(StatusCode::UNAUTHORIZED); | ||
}; | ||
|
||
// TODO: create logic for changing MFA method | ||
if user.otp_enabled { | ||
todo!("Create logic for changing MFA method"); | ||
} | ||
|
||
match crate::features::totp::set_otp_secret(shared_state.pool.clone(), user.id, user.email) | ||
.await | ||
{ | ||
Ok(otp_data) => Ok(Json(MfaInfo { | ||
otp_url: otp_data.otp_url, | ||
})), | ||
Err(e) => { | ||
tracing::error!(?user.id, "Error setting OTP secret: {e}"); | ||
Err(StatusCode::INTERNAL_SERVER_ERROR) | ||
} | ||
} | ||
} | ||
|
||
async fn mfa_verify( | ||
auth_session: AuthSession, | ||
State(shared_state): State<Arc<AppState>>, | ||
Json(mfa_token): Json<MfaTokenForm>, | ||
) -> impl IntoResponse { | ||
crate::hypermedia::service::auth::mfa_verify( | ||
auth_session, | ||
&shared_state.pool, | ||
&shared_state.env, | ||
mfa_token.token, | ||
) | ||
.await | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod router; | ||
pub mod service; | ||
pub mod auth; | ||
pub mod expenses; | ||
pub mod openfinance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters