mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
frontend: Minor work to make it a little less terrible
This commit is contained in:
@@ -1,7 +1,39 @@
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
#app {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
header {
|
||||
background: #EEE;
|
||||
height: 80px;
|
||||
font-weight: bold;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
font-size: 2em;
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
|
||||
|
||||
.logout_form {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.login_window {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,15 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="app" hx-boost="true">
|
||||
{% block header %}
|
||||
<header>
|
||||
<a href="/frontend/user">RustiCal</a>
|
||||
<form method="POST" action="/frontend/logout" class="logout_form">
|
||||
<button type="submit">Log out</button>
|
||||
</form>
|
||||
</header>
|
||||
{% endblock %}
|
||||
<div id="app">
|
||||
{% block content %}<p>Placeholder</p>{% endblock %}
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -10,5 +10,4 @@
|
||||
|
||||
<pre>{{ addressbook|json }}</pre>
|
||||
|
||||
<a href="/frontend/user/{{ addressbook.principal }}">Back</a>
|
||||
{% endblock %}
|
||||
|
||||
@@ -9,6 +9,4 @@
|
||||
{% if let Some(description) = calendar.description %}<p>{{ description }}</p>{% endif%}
|
||||
|
||||
<pre>{{ calendar|json }}</pre>
|
||||
|
||||
<a href="/frontend/user/{{ calendar.principal }}">Back</a>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
{% extends "layouts/default.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Login</h1>
|
||||
<form action="login" method="post">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" name="username" placeholder="username">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" name="password" placeholder="password">
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
||||
{% if let Some(OidcProviderData {name, redirect_url}) = oidc_data %}
|
||||
<a href="{{ redirect_url }}">Login with {{ name }}</a>
|
||||
{% endif %}
|
||||
<div class="login_window">
|
||||
<h1>Login</h1>
|
||||
<form action="login" method="post" id="form_login">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" placeholder="username">
|
||||
<br>
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" placeholder="password">
|
||||
<br>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
{% if let Some(OidcProviderData {name, redirect_url}) = oidc_data %}
|
||||
<a href="{{ redirect_url }}">Login with {{ name }}</a>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
@@ -54,12 +54,22 @@ li.collection-list-item {
|
||||
}
|
||||
</style>
|
||||
<h1>Welcome {{ user.id }}!</h1>
|
||||
<form method="POST" action="/frontend/logout">
|
||||
<button type="submit">Log out</button>
|
||||
</form>
|
||||
|
||||
<h2>Profile</h2>
|
||||
|
||||
<form>
|
||||
<label for="user_displayname">Displayname</label>
|
||||
<input type="text" value="{{ user.displayname.clone().unwrap_or(String::new()) }}" id="user_displayname" />
|
||||
</form>
|
||||
|
||||
<h3>Groups</h3>
|
||||
|
||||
<ul>
|
||||
{% for group in user.memberships %}
|
||||
<li>{{ group }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<h3>App tokens</h3>
|
||||
|
||||
<ul>
|
||||
|
||||
@@ -7,7 +7,7 @@ use actix_web::{
|
||||
dev::ServiceResponse,
|
||||
http::{Method, StatusCode},
|
||||
middleware::{ErrorHandlerResponse, ErrorHandlers},
|
||||
web::{self, Data, Path},
|
||||
web::{self, Data, Path, Redirect},
|
||||
};
|
||||
use askama::Template;
|
||||
use askama_web::WebTemplate;
|
||||
@@ -41,7 +41,16 @@ struct UserPage {
|
||||
pub deleted_addressbooks: Vec<Addressbook>,
|
||||
}
|
||||
|
||||
async fn route_user<CS: CalendarStore, AS: AddressbookStore>(
|
||||
async fn route_user(user: User, req: HttpRequest) -> Redirect {
|
||||
Redirect::to(
|
||||
req.url_for("frontend_user_named", &[&user.id])
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
)
|
||||
.see_other()
|
||||
}
|
||||
|
||||
async fn route_user_named<CS: CalendarStore, AS: AddressbookStore>(
|
||||
path: Path<String>,
|
||||
cal_store: Data<CS>,
|
||||
addr_store: Data<AS>,
|
||||
@@ -79,17 +88,14 @@ async fn route_user<CS: CalendarStore, AS: AddressbookStore>(
|
||||
deleted_calendars,
|
||||
addressbooks,
|
||||
deleted_addressbooks,
|
||||
user: user,
|
||||
user,
|
||||
}
|
||||
.respond_to(&req)
|
||||
}
|
||||
|
||||
async fn route_root(user: Option<User>, req: HttpRequest) -> impl Responder {
|
||||
let redirect_url = match user {
|
||||
Some(user) => req
|
||||
.resource_map()
|
||||
.url_for(&req, "frontend_user", &[user.id])
|
||||
.unwrap(),
|
||||
Some(_) => req.url_for_static("frontend_user").unwrap(),
|
||||
None => req
|
||||
.resource_map()
|
||||
.url_for::<[_; 0], String>(&req, "frontend_login", [])
|
||||
@@ -150,10 +156,15 @@ pub fn configure_frontend<AP: AuthenticationProvider, CS: CalendarStore, AS: Add
|
||||
.service(EmbedService::<Assets>::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::<CS, AS>))
|
||||
web::resource("/user")
|
||||
.route(web::method(Method::GET).to(route_user))
|
||||
.name("frontend_user"),
|
||||
)
|
||||
.service(
|
||||
web::resource("/user/{user}")
|
||||
.route(web::method(Method::GET).to(route_user_named::<CS, AS>))
|
||||
.name("frontend_user_named"),
|
||||
)
|
||||
.service(
|
||||
web::resource("/user/{user}/calendar/{calendar}")
|
||||
.route(web::method(Method::GET).to(route_calendar::<CS>)),
|
||||
|
||||
@@ -230,7 +230,7 @@ pub async fn route_get_oidc_callback<AP: AuthenticationProvider>(
|
||||
session.insert("user", user.id.clone())?;
|
||||
|
||||
Ok(
|
||||
Redirect::to(req.url_for("frontend_user", &[user.id])?.to_string())
|
||||
Redirect::to(req.url_for_static("frontend_user")?.to_string())
|
||||
.temporary()
|
||||
.respond_to(&req)
|
||||
.map_into_boxed_body(),
|
||||
|
||||
Reference in New Issue
Block a user