mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 13:29:21 +00:00
Can remove a key from the list of keys of an admin
This commit is contained in:
parent
22b3a73db3
commit
5abd4979a3
@ -153,6 +153,26 @@ pub fn register_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
r.ok()
|
||||
}
|
||||
|
||||
/// Delete an admin auth key
|
||||
pub fn delete_auth_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let admin_id = r.post_admin_id("adminID")?;
|
||||
let key_id = r.post_u64("keyID")?;
|
||||
|
||||
if admin_id != r.admin_id()? {
|
||||
unimplemented!(); // TODO
|
||||
}
|
||||
|
||||
for key in admin_account_key_helper::get_admin_keys(admin_id)? {
|
||||
if key.id == key_id {
|
||||
admin_account_key_helper::delete_key(key)?;
|
||||
|
||||
return r.ok();
|
||||
}
|
||||
}
|
||||
|
||||
r.not_found("Requested key was not found!".to_string())
|
||||
}
|
||||
|
||||
/// Generate a challenge to authenticate with a security key
|
||||
pub fn challenge_auth_with_key(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let key = r.post_admin_auth_key("mail", "key_id")?;
|
||||
|
@ -27,6 +27,13 @@ pub fn get_admin_keys(id: AdminID) -> Res<Vec<AdminKey>> {
|
||||
.exec(db_to_admin_key)
|
||||
}
|
||||
|
||||
/// Remove a key from the database
|
||||
pub fn delete_key(key: AdminKey) -> Res {
|
||||
database::DeleteQuery::new(ADMIN_KEYS_TABLE)
|
||||
.cond_u64("id", key.id)
|
||||
.exec()
|
||||
}
|
||||
|
||||
/// Turn database entry into an AdminKey structure
|
||||
fn db_to_admin_key(row: &database::RowResult) -> Res<AdminKey> {
|
||||
Ok(AdminKey {
|
||||
|
@ -356,6 +356,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
Route::admin_post("/admin/accounts/update_general_settings", Box::new(admin_account_controller::update_general_settings)),
|
||||
Route::admin_post("/admin/accounts/challenge_register_key", Box::new(admin_account_controller::challenge_register_key)),
|
||||
Route::admin_post("/admin/accounts/register_key", Box::new(admin_account_controller::register_key)),
|
||||
Route::admin_post("/admin/accounts/delete_auth_key", Box::new(admin_account_controller::delete_auth_key)),
|
||||
Route::limited_admin_post_without_login("/admin/accounts/challenge_auth_with_key", Box::new(admin_account_controller::challenge_auth_with_key), LimitPolicy::ANY(10)),
|
||||
Route::limited_admin_post_without_login("/admin/accounts/auth_with_key", Box::new(admin_account_controller::auth_with_key), LimitPolicy::ANY(10)),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user