Verify API auth token
This commit is contained in:
8
src/server/api.rs
Normal file
8
src/server/api.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use crate::extractors::client_auth::APIClientAuth;
|
||||
use crate::server::HttpResult;
|
||||
use actix_web::HttpResponse;
|
||||
|
||||
/// API Home route
|
||||
pub async fn api_home(auth: APIClientAuth) -> HttpResult {
|
||||
Ok(HttpResponse::Ok().body(format!("Welcome user {}!", auth.user.user_id.0)))
|
||||
}
|
@ -2,6 +2,7 @@ use actix_web::http::StatusCode;
|
||||
use actix_web::{HttpResponse, ResponseError};
|
||||
use std::error::Error;
|
||||
|
||||
pub mod api;
|
||||
pub mod web_ui;
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::constants::{STATE_KEY, USER_SESSION_KEY};
|
||||
use crate::server::{HttpFailure, HttpResult};
|
||||
use crate::user::{APIClient, User, UserConfig, UserID};
|
||||
use crate::user::{APIClient, APIClientID, User, UserConfig, UserID};
|
||||
use crate::utils;
|
||||
use actix_session::Session;
|
||||
use actix_web::{web, HttpResponse};
|
||||
@ -33,6 +33,7 @@ pub async fn static_file(path: web::Path<String>) -> HttpResult {
|
||||
#[template(path = "index.html")]
|
||||
struct HomeTemplate {
|
||||
name: String,
|
||||
user_id: UserID,
|
||||
matrix_token: String,
|
||||
clients: Vec<APIClient>,
|
||||
success_message: Option<String>,
|
||||
@ -55,7 +56,7 @@ pub struct FormRequest {
|
||||
readonly_client: Option<String>,
|
||||
|
||||
/// Delete a specified client id
|
||||
delete_client_id: Option<uuid::Uuid>,
|
||||
delete_client_id: Option<APIClientID>,
|
||||
}
|
||||
|
||||
/// Main route
|
||||
@ -82,7 +83,7 @@ pub async fn home(session: Session, form_req: Option<web::Form<FormRequest>>) ->
|
||||
let mut error_message = None;
|
||||
|
||||
// Retrieve user configuration
|
||||
let mut config = UserConfig::load(&user.id)
|
||||
let mut config = UserConfig::load(&user.id, true)
|
||||
.await
|
||||
.map_err(HttpFailure::FetchUserConfig)?;
|
||||
|
||||
@ -137,6 +138,7 @@ pub async fn home(session: Session, form_req: Option<web::Form<FormRequest>>) ->
|
||||
.body(
|
||||
HomeTemplate {
|
||||
name: user.name,
|
||||
user_id: user.id,
|
||||
matrix_token: config.obfuscated_matrix_token(),
|
||||
clients: config.clients,
|
||||
success_message,
|
||||
|
Reference in New Issue
Block a user