mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 08:52:16 +00:00
frontend: Only show logout button when logged in
This commit is contained in:
@@ -14,9 +14,11 @@
|
||||
<header>
|
||||
<a class="logo" href="/frontend/user">RustiCal</a>
|
||||
{% block header_center %}{% endblock %}
|
||||
<form method="POST" action="/frontend/logout" class="logout_form">
|
||||
<button type="submit">Log out</button>
|
||||
</form>
|
||||
{% if self.get_user().is_some() %}
|
||||
<form method="POST" action="/frontend/logout" class="logout_form">
|
||||
<button type="submit">Log out</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</header>
|
||||
{% endblock %}
|
||||
<div id="app">
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{
|
||||
NextcloudFlow, NextcloudFlows, NextcloudLoginPoll, NextcloudLoginResponse,
|
||||
NextcloudSuccessResponse,
|
||||
};
|
||||
use crate::routes::app_token::generate_app_token;
|
||||
use crate::{pages::DefaultLayoutData, routes::app_token::generate_app_token};
|
||||
use askama::Template;
|
||||
use axum::{
|
||||
Extension, Form, Json,
|
||||
@@ -100,6 +100,12 @@ struct NextcloudLoginPage {
|
||||
app_name: String,
|
||||
}
|
||||
|
||||
impl DefaultLayoutData for NextcloudLoginPage {
|
||||
fn get_user(&self) -> Option<&Principal> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(state))]
|
||||
pub async fn get_nextcloud_flow(
|
||||
Extension(state): Extension<Arc<NextcloudFlows>>,
|
||||
@@ -130,6 +136,13 @@ pub struct NextcloudAuthorizeForm {
|
||||
#[template(path = "pages/nextcloud_login/success.html")]
|
||||
struct NextcloudLoginSuccessPage {
|
||||
app_name: String,
|
||||
user: Principal,
|
||||
}
|
||||
|
||||
impl DefaultLayoutData for NextcloudLoginSuccessPage {
|
||||
fn get_user(&self) -> Option<&Principal> {
|
||||
Some(&self.user)
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(state))]
|
||||
@@ -150,6 +163,7 @@ pub async fn post_nextcloud_flow(
|
||||
Ok(Html(
|
||||
NextcloudLoginSuccessPage {
|
||||
app_name: flow.app_name.clone(),
|
||||
user,
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
|
||||
@@ -1 +1,8 @@
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
pub mod user;
|
||||
|
||||
/// Required by the base layout
|
||||
pub trait DefaultLayoutData {
|
||||
fn get_user(&self) -> Option<&Principal>;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
use rustical_store::auth::Principal;
|
||||
|
||||
use crate::pages::DefaultLayoutData;
|
||||
|
||||
pub trait Section: Template {
|
||||
fn name() -> &'static str;
|
||||
}
|
||||
@@ -12,3 +14,9 @@ pub struct UserPage<S: Section> {
|
||||
pub user: Principal,
|
||||
pub section: S,
|
||||
}
|
||||
|
||||
impl<S: Section> DefaultLayoutData for UserPage<S> {
|
||||
fn get_user(&self) -> Option<&Principal> {
|
||||
Some(&self.user)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,19 @@ use headers::Referer;
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Addressbook, AddressbookStore, auth::Principal};
|
||||
|
||||
use crate::pages::DefaultLayoutData;
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/addressbook.html")]
|
||||
struct AddressbookPage {
|
||||
addressbook: Addressbook,
|
||||
user: Principal,
|
||||
}
|
||||
|
||||
impl DefaultLayoutData for AddressbookPage {
|
||||
fn get_user(&self) -> Option<&Principal> {
|
||||
Some(&self.user)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn route_addressbook<AS: AddressbookStore>(
|
||||
@@ -28,6 +37,7 @@ pub async fn route_addressbook<AS: AddressbookStore>(
|
||||
}
|
||||
Ok(AddressbookPage {
|
||||
addressbook: store.get_addressbook(&owner, &addrbook_id, true).await?,
|
||||
user,
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::pages::DefaultLayoutData;
|
||||
use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
use axum::{
|
||||
@@ -11,11 +10,19 @@ use axum_extra::TypedHeader;
|
||||
use headers::Referer;
|
||||
use http::StatusCode;
|
||||
use rustical_store::{Calendar, CalendarStore, auth::Principal};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Template, WebTemplate)]
|
||||
#[template(path = "pages/calendar.html")]
|
||||
struct CalendarPage {
|
||||
calendar: Calendar,
|
||||
user: Principal,
|
||||
}
|
||||
|
||||
impl DefaultLayoutData for CalendarPage {
|
||||
fn get_user(&self) -> Option<&Principal> {
|
||||
Some(&self.user)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn route_calendar<C: CalendarStore>(
|
||||
@@ -28,6 +35,7 @@ pub async fn route_calendar<C: CalendarStore>(
|
||||
}
|
||||
Ok(CalendarPage {
|
||||
calendar: store.get_calendar(&owner, &cal_id, true).await?,
|
||||
user,
|
||||
}
|
||||
.into_response())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::{FrontendConfig, OidcConfig};
|
||||
use crate::{FrontendConfig, OidcConfig, pages::DefaultLayoutData};
|
||||
use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
use axum::{
|
||||
@@ -24,6 +24,12 @@ struct LoginPage<'a> {
|
||||
allow_password_login: bool,
|
||||
}
|
||||
|
||||
impl DefaultLayoutData for LoginPage<'_> {
|
||||
fn get_user(&self) -> Option<&rustical_store::auth::Principal> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
struct OidcProviderData<'a> {
|
||||
pub name: &'a str,
|
||||
pub redirect_url: String,
|
||||
|
||||
Reference in New Issue
Block a user