Can delete API token from UI
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::extractors::auth_extractor::{AuthExtractor, AuthenticatedMethod};
|
||||
use crate::users::{APIToken, BaseAPIToken};
|
||||
use actix_web::HttpResponse;
|
||||
use crate::users::{APIToken, APITokenID, BaseAPIToken};
|
||||
use actix_web::{HttpResponse, web};
|
||||
|
||||
/// Create a new token
|
||||
pub async fn create(auth: AuthExtractor) -> HttpResult {
|
||||
@@ -34,3 +34,15 @@ pub async fn get_list(auth: AuthExtractor) -> HttpResult {
|
||||
.collect::<Vec<_>>(),
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct TokenIDInPath {
|
||||
id: APITokenID,
|
||||
}
|
||||
|
||||
/// Delete an API access token
|
||||
pub async fn delete(auth: AuthExtractor, path: web::Path<TokenIDInPath>) -> HttpResult {
|
||||
let token = APIToken::load(&auth.user.email, &path.id).await?;
|
||||
token.delete(&auth.user.email).await?;
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
@@ -115,6 +115,10 @@ async fn main() -> std::io::Result<()> {
|
||||
// API Tokens controller
|
||||
.route("/api/token", web::post().to(tokens_controller::create))
|
||||
.route("/api/tokens", web::get().to(tokens_controller::get_list))
|
||||
.route(
|
||||
"/api/token/{id}",
|
||||
web::delete().to(tokens_controller::delete),
|
||||
)
|
||||
})
|
||||
.workers(4)
|
||||
.bind(&AppConfig::get().listen_address)?
|
||||
|
||||
Reference in New Issue
Block a user