feat: use custom middleware for authorization
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
This commit is contained in:
parent
dada230e08
commit
1ad88725bd
24 changed files with 157 additions and 365 deletions
|
@ -3,15 +3,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
Json, Router,
|
||||
extract::{Multipart, Path, State},
|
||||
http::StatusCode,
|
||||
response::IntoResponse,
|
||||
routing::{get, patch, post},
|
||||
};
|
||||
use axum_extra::{
|
||||
TypedHeader,
|
||||
headers::{Authorization, authorization::Bearer},
|
||||
extract::{Multipart, Path, State}, http::StatusCode, response::IntoResponse, routing::{get, patch, post}, Extension, Json, Router
|
||||
};
|
||||
use bytes::Bytes;
|
||||
use uuid::Uuid;
|
||||
|
@ -23,7 +15,7 @@ mod roles;
|
|||
|
||||
use crate::{
|
||||
AppState,
|
||||
api::v1::auth::check_access_token,
|
||||
api::v1::auth::CurrentUser,
|
||||
error::Error,
|
||||
objects::{Guild, Member, Permissions},
|
||||
utils::global_checks,
|
||||
|
@ -84,14 +76,12 @@ pub fn router() -> Router<Arc<AppState>> {
|
|||
pub async fn get_guild(
|
||||
State(app_state): State<Arc<AppState>>,
|
||||
Path(guild_uuid): Path<Uuid>,
|
||||
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
|
||||
Extension(CurrentUser(uuid)): Extension<CurrentUser<Uuid>>,
|
||||
) -> Result<impl IntoResponse, Error> {
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
let uuid = check_access_token(auth.token(), &mut conn).await?;
|
||||
|
||||
global_checks(&app_state, uuid).await?;
|
||||
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||
|
||||
let guild = Guild::fetch_one(&mut conn, guild_uuid).await?;
|
||||
|
@ -105,15 +95,13 @@ pub async fn get_guild(
|
|||
pub async fn edit(
|
||||
State(app_state): State<Arc<AppState>>,
|
||||
Path(guild_uuid): Path<Uuid>,
|
||||
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
|
||||
Extension(CurrentUser(uuid)): Extension<CurrentUser<Uuid>>,
|
||||
mut multipart: Multipart,
|
||||
) -> Result<impl IntoResponse, Error> {
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
let uuid = check_access_token(auth.token(), &mut conn).await?;
|
||||
|
||||
global_checks(&app_state, uuid).await?;
|
||||
|
||||
let mut conn = app_state.pool.get().await?;
|
||||
|
||||
let member = Member::check_membership(&mut conn, uuid, guild_uuid).await?;
|
||||
|
||||
member
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue