authorization_codes: crate, database, insert one
This commit is contained in:
parent
0b4aeb89cb
commit
471e2fc740
11 changed files with 159 additions and 0 deletions
42
crates/authorization_codes/src/database.rs
Normal file
42
crates/authorization_codes/src/database.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use crate::error::Error;
|
||||
use crate::AuthorizationCodes;
|
||||
use chrono::{Duration, Utc};
|
||||
use database::sqlx::SqliteExecutor;
|
||||
use database::AuthorizationCodes as DatabaseAuthorizationCodes;
|
||||
use id::{AppID, UserID};
|
||||
|
||||
impl From<DatabaseAuthorizationCodes> for AuthorizationCodes {
|
||||
fn from(db: DatabaseAuthorizationCodes) -> Self {
|
||||
Self {
|
||||
// Info
|
||||
code: db.code,
|
||||
app: AppID(db.app),
|
||||
user: UserID(db.user),
|
||||
|
||||
// Timings
|
||||
created_at: db.created_at,
|
||||
expires_at: db.expires_at,
|
||||
used_at: db.used_at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthorizationCodes {
|
||||
pub async fn insert(
|
||||
conn: impl SqliteExecutor<'_>,
|
||||
code: &str,
|
||||
app: &AppID,
|
||||
user: &UserID,
|
||||
) -> Result<Option<()>, Error> {
|
||||
let expires_at = Utc::now() + Duration::minutes(10);
|
||||
|
||||
Ok(DatabaseAuthorizationCodes::insert(
|
||||
conn,
|
||||
code,
|
||||
app.as_ref(),
|
||||
user.as_ref(),
|
||||
expires_at.timestamp(),
|
||||
)
|
||||
.await?)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue