add: profile is_verified
add: better profile not found page TODO: use error page for fallback service
This commit is contained in:
parent
7d96a3d20f
commit
5cfca49793
13 changed files with 234 additions and 20 deletions
|
@ -31,6 +31,7 @@ pub const ROOT: &str = include_str!("./public/html/root.html");
|
|||
pub const MACROS: &str = include_str!("./public/html/macros.html");
|
||||
|
||||
pub const MISC_INDEX: &str = include_str!("./public/html/misc/index.html");
|
||||
pub const MISC_ERROR: &str = include_str!("./public/html/misc/error.html");
|
||||
|
||||
pub const AUTH_BASE: &str = include_str!("./public/html/auth/base.html");
|
||||
pub const AUTH_LOGIN: &str = include_str!("./public/html/auth/login.html");
|
||||
|
@ -135,6 +136,7 @@ pub(crate) async fn write_assets(config: &Config) -> PathBufD {
|
|||
write_template!(html_path->"macros.html"(crate::assets::MACROS) --config=config);
|
||||
|
||||
write_template!(html_path->"misc/index.html"(crate::assets::MISC_INDEX) -d "misc" --config=config);
|
||||
write_template!(html_path->"misc/error.html"(crate::assets::MISC_ERROR) --config=config);
|
||||
|
||||
write_template!(html_path->"auth/base.html"(crate::assets::AUTH_BASE) -d "auth" --config=config);
|
||||
write_template!(html_path->"auth/login.html"(crate::assets::AUTH_LOGIN) --config=config);
|
||||
|
|
|
@ -324,6 +324,10 @@ table ol {
|
|||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.card.small {
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
.card.secondary {
|
||||
background: var(--color-surface);
|
||||
}
|
||||
|
|
21
crates/app/src/public/html/misc/error.html
Normal file
21
crates/app/src/public/html/misc/error.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
{% import "macros.html" as macros %} {% extends "root.html" %} {% block head %}
|
||||
<title>{{ error_text }} - Tetratto</title>
|
||||
{% endblock %} {% block body %} {{ macros::nav(selected="home") }}
|
||||
<main class="flex flex-col gap-2">
|
||||
<div class="card-nest">
|
||||
<div class="card">
|
||||
<b>Error! 😦</b>
|
||||
</div>
|
||||
|
||||
<div class="card flex flex-col gap-4">
|
||||
<p>{{ error_text }}</p>
|
||||
<div class="w-full flex gap-2">
|
||||
<a class="button primary" href="/">Home</a>
|
||||
<a class="button secondary" href="javascript:history.back()"
|
||||
>Back</a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
{% endblock %}
|
|
@ -13,10 +13,19 @@
|
|||
{{ macros::avatar(username=profile.username,size="72px")
|
||||
}}
|
||||
<div class="flex flex-col">
|
||||
<h3 id="username">
|
||||
{% if profile.settings.display_name %} {{
|
||||
profile.settings.display_name }} {% else %} {{
|
||||
profile.username }} {% endif %}
|
||||
<!-- prettier-ignore -->
|
||||
<h3 id="username" class="username">
|
||||
{% if profile.settings.display_name %}
|
||||
{{ profile.settings.display_name }}
|
||||
{% else %}
|
||||
{{ profile.username }}
|
||||
{% endif %}
|
||||
|
||||
{% if profile.is_verified %}
|
||||
<span title="Verified">
|
||||
{{ icon "badge-check" }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</h3>
|
||||
|
||||
<span class="fade">{{ profile.username }}</span>
|
||||
|
@ -24,23 +33,25 @@
|
|||
</div>
|
||||
|
||||
<div class="card flex" id="social">
|
||||
<div
|
||||
<a
|
||||
href="/user/{{ profile.username }}/followers"
|
||||
class="w-full flex justify-center items-center gap-2"
|
||||
>
|
||||
<h4>{{ profile.follower_count }}</h4>
|
||||
<span>{{ text "auth:label.followers" }}</span>
|
||||
</div>
|
||||
<div
|
||||
</a>
|
||||
<a
|
||||
href="/user/{{ profile.username }}/following"
|
||||
class="w-full flex justify-center items-center gap-2"
|
||||
>
|
||||
<h4>{{ profile.following_count }}</h4>
|
||||
<span>{{ text "auth:label.following" }}</span>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-nest flex flex-col">
|
||||
<div id="bio" class="card">
|
||||
<div id="bio" class="card small">
|
||||
{{ profile.settings.biography }}
|
||||
</div>
|
||||
|
||||
|
@ -64,7 +75,7 @@
|
|||
</div>
|
||||
|
||||
<div class="card-nest">
|
||||
<div class="card flex gap-2 items-center">
|
||||
<div class="card small flex gap-2 items-center">
|
||||
{{ icon "users-round" }}
|
||||
<span>{{ text "auth:label.joined_journals" }}</span>
|
||||
</div>
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
use crate::{
|
||||
State, get_user_from_token,
|
||||
model::{ApiReturn, Error},
|
||||
routes::api::v1::UpdateUserIsVerified,
|
||||
};
|
||||
use axum::{Extension, Json, extract::Path, response::IntoResponse};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::{auth::UserSettings, permissions::FinePermission};
|
||||
use tetratto_core::model::{
|
||||
auth::{Token, UserSettings},
|
||||
permissions::FinePermission,
|
||||
};
|
||||
|
||||
/// Update the settings of the given user.
|
||||
pub async fn update_profile_settings_request(
|
||||
|
@ -28,7 +32,62 @@ pub async fn update_profile_settings_request(
|
|||
match data.update_user_settings(id, req).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "User unfollowed".to_string(),
|
||||
message: "Settings updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the tokens of the given user.
|
||||
pub async fn update_profile_tokens_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<Vec<Token>>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
if user.id != id {
|
||||
if !user.permissions.check(FinePermission::MANAGE_USERS) {
|
||||
return Json(Error::NotAllowed.into());
|
||||
}
|
||||
}
|
||||
|
||||
match data.update_user_tokens(id, req).await {
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Tokens updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Update the verification status of the given user.
|
||||
pub async fn update_profile_is_verified_request(
|
||||
jar: CookieJar,
|
||||
Path(id): Path<usize>,
|
||||
Extension(data): Extension<State>,
|
||||
Json(req): Json<UpdateUserIsVerified>,
|
||||
) -> impl IntoResponse {
|
||||
let data = &(data.read().await).0;
|
||||
let user = match get_user_from_token!(jar, data) {
|
||||
Some(ua) => ua,
|
||||
None => return Json(Error::NotAllowed.into()),
|
||||
};
|
||||
|
||||
match data
|
||||
.update_user_verified_status(id, req.is_verified, user)
|
||||
.await
|
||||
{
|
||||
Ok(_) => Json(ApiReturn {
|
||||
ok: true,
|
||||
message: "Verified status updated".to_string(),
|
||||
payload: (),
|
||||
}),
|
||||
Err(e) => Json(e.into()),
|
||||
|
|
|
@ -82,6 +82,14 @@ pub fn routes() -> Router {
|
|||
"/auth/profile/{id}/settings",
|
||||
post(auth::profile::update_profile_settings_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/profile/{id}/tokens",
|
||||
post(auth::profile::update_profile_tokens_request),
|
||||
)
|
||||
.route(
|
||||
"/auth/profile/{id}/verified",
|
||||
post(auth::profile::update_profile_is_verified_request),
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
@ -140,3 +148,8 @@ pub struct CreateReaction {
|
|||
pub asset_type: AssetType,
|
||||
pub is_like: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateUserIsVerified {
|
||||
pub is_verified: bool,
|
||||
}
|
||||
|
|
|
@ -3,6 +3,14 @@ pub mod misc;
|
|||
pub mod profile;
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use axum_extra::extract::CookieJar;
|
||||
use serde::Deserialize;
|
||||
use tetratto_core::{
|
||||
DataManager,
|
||||
model::{Error, auth::User},
|
||||
};
|
||||
|
||||
use crate::{assets::initial_context, get_lang};
|
||||
|
||||
pub fn routes() -> Router {
|
||||
Router::new()
|
||||
|
@ -14,3 +22,21 @@ pub fn routes() -> Router {
|
|||
// profile
|
||||
.route("/user/{username}", get(profile::posts_request))
|
||||
}
|
||||
|
||||
pub fn render_error(
|
||||
e: Error,
|
||||
jar: &CookieJar,
|
||||
data: &(DataManager, tera::Tera),
|
||||
user: &Option<User>,
|
||||
) -> String {
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user);
|
||||
context.insert("error_text", &e.to_string());
|
||||
data.1.render("misc/error.html", &mut context).unwrap()
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct PaginatedQuery {
|
||||
#[serde(default)]
|
||||
pub page: usize,
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use super::{PaginatedQuery, render_error};
|
||||
use crate::{State, assets::initial_context, get_lang, get_user_from_token};
|
||||
use axum::{
|
||||
Extension,
|
||||
extract::Path,
|
||||
extract::{Path, Query},
|
||||
response::{Html, IntoResponse},
|
||||
};
|
||||
use axum_extra::extract::CookieJar;
|
||||
|
@ -10,6 +11,7 @@ use axum_extra::extract::CookieJar;
|
|||
pub async fn posts_request(
|
||||
jar: CookieJar,
|
||||
Path(username): Path<String>,
|
||||
Query(props): Query<PaginatedQuery>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
|
@ -17,12 +19,23 @@ pub async fn posts_request(
|
|||
|
||||
let other_user = match data.0.get_user_by_username(&username).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(e.to_string())),
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user))),
|
||||
};
|
||||
|
||||
let posts = match data
|
||||
.0
|
||||
.get_posts_by_user(other_user.id, 12, props.page)
|
||||
.await
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &user))),
|
||||
};
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &user);
|
||||
|
||||
context.insert("profile", &other_user);
|
||||
context.insert("posts", &posts);
|
||||
|
||||
Ok(Html(
|
||||
data.1.render("profile/posts.html", &mut context).unwrap(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue