-
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.
- Loading branch information
1 parent
ce31a02
commit d889d27
Showing
6 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use crate::{ | ||
certification::{self, str_to_role_opt}, | ||
error_handling::{result_to_handler_with_log, QrError, Result, ReturnData}, | ||
}; | ||
use axum::headers::authorization::Basic; | ||
use sqlx::{pool::Pool, postgres::Postgres}; | ||
use std::sync::Arc; | ||
use tracing::*; | ||
|
||
pub async fn api_gen_passtoken(token_info: Basic, conn: Arc<Pool<Postgres>>) -> ReturnData<String> { | ||
info!("Try gen passtoken"); | ||
let res = gen_passtoken(token_info, conn).await; | ||
result_to_handler_with_log( | ||
|_| Some("Success gen passtoken".to_string()), | ||
|e| Some(format!("Failed gen passtoken: {e}")), | ||
&res, | ||
) | ||
.await | ||
} | ||
|
||
pub async fn gen_passtoken(token_info: Basic, conn: Arc<Pool<Postgres>>) -> Result<String> { | ||
let role_str = token_info.username(); | ||
let key = token_info.password(); | ||
match str_to_role_opt(role_str) { | ||
Some(role) => { | ||
let passtoken = certification::gen_passtoken(role, key)?; | ||
certification::insert_passtoken(&*conn, &passtoken).await?; | ||
Ok(passtoken.token) | ||
} | ||
None => Err(QrError::Authorized), | ||
} | ||
} |
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