BasicOIDC/src/controllers/admin_controller.rs

69 lines
1.9 KiB
Rust
Raw Normal View History

2022-04-07 15:04:05 +00:00
use std::ops::Deref;
2022-04-06 16:03:00 +00:00
use actix::Addr;
2022-04-06 15:18:06 +00:00
use actix_web::{HttpResponse, Responder, web};
use askama::Template;
2022-04-06 16:03:00 +00:00
use crate::actors::users_actor;
use crate::actors::users_actor::UsersActor;
2022-04-06 15:18:06 +00:00
use crate::controllers::settings_controller::BaseSettingsPage;
use crate::data::client::{Client, ClientManager};
use crate::data::current_user::CurrentUser;
2022-04-06 16:03:00 +00:00
use crate::data::user::User;
2022-04-06 15:18:06 +00:00
#[derive(Template)]
#[template(path = "settings/clients_list.html")]
struct ClientsListTemplate {
_parent: BaseSettingsPage,
clients: Vec<Client>,
}
2022-04-06 16:03:00 +00:00
#[derive(Template)]
#[template(path = "settings/users_list.html")]
struct UsersListTemplate {
_parent: BaseSettingsPage,
users: Vec<User>,
}
2022-04-07 15:04:05 +00:00
#[derive(Template)]
#[template(path = "settings/edit_user.html")]
struct EditUserTemplate {
_parent: BaseSettingsPage,
u: User,
clients: Vec<Client>,
}
2022-04-06 16:03:00 +00:00
2022-04-06 15:18:06 +00:00
pub async fn clients_route(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
HttpResponse::Ok().body(ClientsListTemplate {
_parent: BaseSettingsPage::get(
"Clients list",
&user,
None,
None,
),
clients: clients.cloned(),
}.render().unwrap())
2022-04-06 16:03:00 +00:00
}
pub async fn users_route(user: CurrentUser, users: web::Data<Addr<UsersActor>>) -> impl Responder {
let users = users.send(users_actor::GetAllUsersRequest).await.unwrap().0;
HttpResponse::Ok().body(UsersListTemplate {
_parent: BaseSettingsPage::get(
"Users list",
&user,
None,
None,
),
users,
}.render().unwrap())
2022-04-07 15:04:05 +00:00
}
pub async fn create_user(user: CurrentUser, clients: web::Data<ClientManager>) -> impl Responder {
HttpResponse::Ok().body(EditUserTemplate {
_parent: BaseSettingsPage::get("Create a new user", user.deref(), None, None),
u: Default::default(),
clients: clients.cloned(),
}.render().unwrap())
2022-04-06 15:18:06 +00:00
}