Beginning of permissions system

This commit is contained in:
2025-02-07 12:04:51 +01:00
parent f7b7ebbb1c
commit cf379a1288
4 changed files with 90 additions and 3 deletions

View File

@@ -4,8 +4,13 @@ use argon2::{
password_hash::{rand_core::OsRng, PasswordHasher, SaltString},
Argon2, PasswordHash, PasswordVerifier,
};
use axum::{extract::FromRequestParts, http::request::Parts, RequestPartsExt};
use axum::{
extract::FromRequestParts,
http::{request::Parts, StatusCode},
RequestPartsExt,
};
use axum_extra::{
extract::cookie::{Cookie, CookieJar},
headers::{authorization::Bearer, Authorization},
typed_header::TypedHeaderRejectionReason,
TypedHeader,
@@ -51,6 +56,16 @@ where
},
};
match parts.extract::<CookieJar>().await {
Ok(jar) => {
if let Some(session_token) = jar.get("session_token") {
// TODO: Implement function to retrieve user permissions
tracing::info!("{session_token:?}")
}
}
Err(_) => (),
}
Err(AuthError::Unauthorized.into())
}
}

View File

@@ -1,5 +1,5 @@
use chrono::{DateTime, Utc};
use sqlx::Postgres;
use sqlx::{PgPool, Postgres};
pub struct Session {
pub session_id: uuid::Uuid,
@@ -34,4 +34,12 @@ impl Session {
Ok(())
}
pub async fn from_token(transaction: &PgPool, token: &str) -> Result<Self, sqlx::Error> {
let session = sqlx::query_as!(Self, "SELECT * FROM sessions WHERE token = $1;", token)
.fetch_one(transaction)
.await?;
Ok(session)
}
}