diff --git a/crates/frontend/public/templates/pages/addressbook.html b/crates/frontend/public/templates/pages/addressbook.html
new file mode 100644
index 0000000..d743b6f
--- /dev/null
+++ b/crates/frontend/public/templates/pages/addressbook.html
@@ -0,0 +1,9 @@
+{% extends "layouts/default.html" %}
+
+{% block imports %}
+{% endblock %}
+
+{% block content %}
+
Test
+Back
+{% endblock %}
diff --git a/crates/frontend/public/templates/pages/user.html b/crates/frontend/public/templates/pages/user.html
index bd0a7bf..2d809f1 100644
--- a/crates/frontend/public/templates/pages/user.html
+++ b/crates/frontend/public/templates/pages/user.html
@@ -5,7 +5,7 @@
{% block content %}
-Welcome {{ user_id }}!
+Welcome {{ user_id }}!
+
+Calendars
+
+Addressbooks
+
{% endblock %}
diff --git a/crates/frontend/src/lib.rs b/crates/frontend/src/lib.rs
index ac6670d..00fca69 100644
--- a/crates/frontend/src/lib.rs
+++ b/crates/frontend/src/lib.rs
@@ -10,11 +10,12 @@ use actix_web::{
HttpRequest, HttpResponse, Responder,
};
use askama::Template;
+use askama_actix::TemplateToResponse;
use assets::{Assets, EmbedService};
use routes::login::{route_get_login, route_post_login};
use rustical_store::{
auth::{AuthenticationMiddleware, AuthenticationProvider, User},
- Calendar, CalendarStore,
+ Addressbook, AddressbookStore, Calendar, CalendarStore,
};
use std::sync::Arc;
@@ -29,18 +30,27 @@ pub use config::FrontendConfig;
struct UserPage {
pub user_id: String,
pub calendars: Vec,
+ pub addressbooks: Vec,
}
-async fn route_user(
+async fn route_user(
path: Path,
- store: Data,
+ cal_store: Data,
+ addr_store: Data,
user: User,
) -> impl Responder {
+ // TODO: Check for authorization
let user_id = path.into_inner();
+ if user_id != user.id {
+ return actix_web::HttpResponse::Unauthorized().body("Unauthorized");
+ }
+
UserPage {
- calendars: store.get_calendars(&user.id).await.unwrap(),
+ calendars: cal_store.get_calendars(&user.id).await.unwrap(),
+ addressbooks: addr_store.get_addressbooks(&user.id).await.unwrap(),
user_id: user.id,
}
+ .to_response()
}
#[derive(Template)]
@@ -62,6 +72,25 @@ async fn route_calendar(
}
}
+#[derive(Template)]
+#[template(path = "pages/addressbook.html")]
+struct AddressbookPage {
+ owner: String,
+ addressbook: Addressbook,
+}
+
+async fn route_addressbook(
+ path: Path<(String, String)>,
+ store: Data,
+ _user: User,
+) -> impl Responder {
+ let (owner, addrbook_id) = path.into_inner();
+ AddressbookPage {
+ owner: owner.to_owned(),
+ addressbook: store.get_addressbook(&owner, &addrbook_id).await.unwrap(),
+ }
+}
+
async fn route_root(user: Option, req: HttpRequest) -> impl Responder {
let redirect_url = match user {
Some(user) => req
@@ -101,10 +130,15 @@ fn unauthorized_handler(res: ServiceResponse) -> actix_web::Result(
+pub fn configure_frontend<
+ AP: AuthenticationProvider,
+ CS: CalendarStore + ?Sized,
+ AS: AddressbookStore + ?Sized,
+>(
cfg: &mut web::ServiceConfig,
auth_provider: Arc,
- store: Arc,
+ cal_store: Arc,
+ addr_store: Arc,
frontend_config: FrontendConfig,
) {
cfg.service(
@@ -122,17 +156,22 @@ pub fn configure_frontend
.build(),
)
.app_data(Data::from(auth_provider))
- .app_data(Data::from(store.clone()))
+ .app_data(Data::from(cal_store.clone()))
+ .app_data(Data::from(addr_store.clone()))
.service(EmbedService::::new("/assets".to_owned()))
.service(web::resource("").route(web::method(Method::GET).to(route_root)))
.service(
web::resource("/user/{user}")
- .route(web::method(Method::GET).to(route_user::))
+ .route(web::method(Method::GET).to(route_user::))
.name("frontend_user"),
)
.service(
- web::resource("/user/{user}/{calendar}")
- .route(web::method(Method::GET).to(route_calendar::)),
+ web::resource("/user/{user}/calendar/{calendar}")
+ .route(web::method(Method::GET).to(route_calendar::)),
+ )
+ .service(
+ web::resource("/user/{user}/addressbook/{calendar}")
+ .route(web::method(Method::GET).to(route_addressbook::)),
)
.service(
web::resource("/login")
diff --git a/src/app.rs b/src/app.rs
index 4a7f159..ce14db2 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -44,6 +44,7 @@ pub fn make_app(
cfg,
auth_provider.clone(),
cal_store.clone(),
+ addr_store.clone(),
frontend_config,
)
}))