mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 11:42:25 +00:00
use askama_web to make template responses more ergonomic
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use actix_web::{
|
||||
http::{header, StatusCode},
|
||||
web::{self, Data, Html, Path},
|
||||
HttpRequest, HttpResponse, Responder,
|
||||
http::{StatusCode, header},
|
||||
web::{self, Data, Path},
|
||||
};
|
||||
use askama::Template;
|
||||
use rustical_store::{auth::User, Addressbook, AddressbookStore};
|
||||
use askama_web::WebTemplate;
|
||||
use rustical_store::{Addressbook, AddressbookStore, auth::User};
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/addressbook.html")]
|
||||
struct AddressbookPage {
|
||||
addressbook: Addressbook,
|
||||
@@ -22,15 +23,10 @@ pub async fn route_addressbook<AS: AddressbookStore>(
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(HttpResponse::Unauthorized().body("Unauthorized"));
|
||||
}
|
||||
Ok(Html::new(
|
||||
AddressbookPage {
|
||||
addressbook: store.get_addressbook(&owner, &addrbook_id).await?,
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
)
|
||||
.respond_to(&req)
|
||||
.map_into_boxed_body())
|
||||
Ok(AddressbookPage {
|
||||
addressbook: store.get_addressbook(&owner, &addrbook_id).await?,
|
||||
}
|
||||
.respond_to(&req))
|
||||
}
|
||||
|
||||
pub async fn route_addressbook_restore<AS: AddressbookStore>(
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use actix_web::{
|
||||
http::{header, StatusCode},
|
||||
web::{self, Data, Html, Path},
|
||||
HttpRequest, HttpResponse, Responder,
|
||||
http::{StatusCode, header},
|
||||
web::{self, Data, Path},
|
||||
};
|
||||
use askama::Template;
|
||||
use rustical_store::{auth::User, Calendar, CalendarStore};
|
||||
use askama_web::WebTemplate;
|
||||
use rustical_store::{Calendar, CalendarStore, auth::User};
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/calendar.html")]
|
||||
struct CalendarPage {
|
||||
calendar: Calendar,
|
||||
@@ -22,15 +23,10 @@ pub async fn route_calendar<C: CalendarStore>(
|
||||
if !user.is_principal(&owner) {
|
||||
return Ok(HttpResponse::Unauthorized().body("Unauthorized"));
|
||||
}
|
||||
Ok(Html::new(
|
||||
CalendarPage {
|
||||
calendar: store.get_calendar(&owner, &cal_id).await?,
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
)
|
||||
.respond_to(&req)
|
||||
.map_into_boxed_body())
|
||||
Ok(CalendarPage {
|
||||
calendar: store.get_calendar(&owner, &cal_id).await?,
|
||||
}
|
||||
.respond_to(&req))
|
||||
}
|
||||
|
||||
pub async fn route_calendar_restore<CS: CalendarStore>(
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
use actix_session::Session;
|
||||
use actix_web::{
|
||||
error::ErrorUnauthorized,
|
||||
web::{Data, Form, Html, Redirect},
|
||||
HttpRequest, HttpResponse, Responder,
|
||||
error::ErrorUnauthorized,
|
||||
web::{Data, Form, Redirect},
|
||||
};
|
||||
use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
use rustical_store::auth::AuthenticationProvider;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Template)]
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/login.html")]
|
||||
struct LoginPage;
|
||||
|
||||
pub async fn route_get_login(req: HttpRequest) -> impl Responder {
|
||||
Html::new(LoginPage.render().unwrap())
|
||||
.respond_to(&req)
|
||||
.map_into_boxed_body()
|
||||
pub async fn route_get_login() -> impl Responder {
|
||||
LoginPage
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user