use actix::Addr; use actix_identity::Identity; use actix_web::{HttpResponse, Responder, web}; use askama::Template; use crate::actors::users_actor; use crate::actors::users_actor::UsersActor; use crate::constants::APP_NAME; use crate::data::session_identity::SessionIdentity; use crate::data::user::User; #[derive(Template)] #[template(path = "settings/base_settings_page.html")] struct BaseSettingsPage { danger_message: Option, success_message: Option, page_title: &'static str, app_name: &'static str, is_admin: bool, user_name: String, } impl BaseSettingsPage { async fn get(user: &User) -> BaseSettingsPage { Self { danger_message: None, success_message: None, page_title: "Account details", app_name: APP_NAME, is_admin: user.admin, user_name: user.username.to_string(), } } } #[derive(Template)] #[template(path = "settings/account_details.html")] struct AccountDetailsPage { _parent: BaseSettingsPage, user_id: String, first_name: String, last_name: String, username: String, email: String, } /// Account details page pub async fn account_settings_details_route(id: Identity, user_actor: web::Data>) -> impl Responder { let user: User = user_actor.send( users_actor::GetUserRequest(SessionIdentity(&id).user_id()) ).await.unwrap().0.unwrap(); HttpResponse::Ok() .body(AccountDetailsPage { _parent: BaseSettingsPage::get(&user).await, user_id: user.uid, first_name: user.first_name, last_name: user.last_last, username: user.username, email: user.email, }.render().unwrap()) }