mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
Add a API endpoint to create a user
This commit is contained in:
parent
e3ff3b7b0a
commit
ca48de542b
@ -28,6 +28,20 @@ where
|
||||
.unwrap_or_else(error_to_api_response)
|
||||
}
|
||||
|
||||
async fn create_user_handler<Backend>(
|
||||
data: web::Data<AppState<Backend>>,
|
||||
info: web::Json<CreateUserRequest>,
|
||||
) -> ApiResult<()>
|
||||
where
|
||||
Backend: TcpBackendHandler + BackendHandler + 'static,
|
||||
{
|
||||
data.backend_handler
|
||||
.create_user(info.clone())
|
||||
.await
|
||||
.map(|res| ApiResult::Left(web::Json(res)))
|
||||
.unwrap_or_else(error_to_api_response)
|
||||
}
|
||||
|
||||
pub fn api_config<Backend>(cfg: &mut web::ServiceConfig)
|
||||
where
|
||||
Backend: TcpBackendHandler + BackendHandler + 'static,
|
||||
@ -44,10 +58,10 @@ where
|
||||
)
|
||||
.into()
|
||||
});
|
||||
cfg.app_data(json_config);
|
||||
cfg.service(web::resource("/users").route(web::post().to(user_list_handler::<Backend>)));
|
||||
cfg.service(
|
||||
web::resource("/users")
|
||||
.app_data(json_config)
|
||||
.route(web::post().to(user_list_handler::<Backend>)),
|
||||
web::resource("/users/create").route(web::post().to(create_user_handler::<Backend>)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ fn http_config<Backend>(
|
||||
auth_service::token_validator::<Backend>,
|
||||
))
|
||||
.wrap(auth_service::CookieToHeaderTranslatorFactory)
|
||||
.guard(actix_web::guard::Header("content-type", "application/json"))
|
||||
.configure(tcp_api::api_config::<Backend>),
|
||||
)
|
||||
// Serve the /pkg path with the compiled WASM app.
|
||||
|
Loading…
Reference in New Issue
Block a user