add: user settings ui
This commit is contained in:
parent
e7e9b49195
commit
f3c2157dfc
24 changed files with 1015 additions and 187 deletions
|
@ -80,15 +80,6 @@ pub fn community_context(
|
|||
context.insert("community", &community);
|
||||
context.insert("is_owner", &is_owner);
|
||||
context.insert("is_joined", &is_joined);
|
||||
|
||||
if is_owner {
|
||||
context.insert(
|
||||
"community_context_serde",
|
||||
&serde_json::to_string(&community.context)
|
||||
.unwrap()
|
||||
.replace("\"", "\\\""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// `/community/{title}`
|
||||
|
@ -152,6 +143,53 @@ pub async fn feed_request(
|
|||
))
|
||||
}
|
||||
|
||||
/// `/community/{title}/manage`
|
||||
pub async fn settings_request(
|
||||
jar: CookieJar,
|
||||
Path(title): Path<String>,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let community = match data.0.get_community_by_title(&title.to_lowercase()).await {
|
||||
Ok(ua) => ua,
|
||||
Err(e) => return Err(Html(render_error(e, &jar, &data, &Some(user)).await)),
|
||||
};
|
||||
|
||||
if user.id != community.owner {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
|
||||
// init context
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert("community", &community);
|
||||
context.insert(
|
||||
"community_context_serde",
|
||||
&serde_json::to_string(&community.context)
|
||||
.unwrap()
|
||||
.replace("\"", "\\\""),
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("communities/settings.html", &mut context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
/// `/post/{id}`
|
||||
pub async fn post_request(
|
||||
jar: CookieJar,
|
||||
|
|
|
@ -7,6 +7,20 @@ use axum::{
|
|||
use axum_extra::extract::CookieJar;
|
||||
use tetratto_core::model::Error;
|
||||
|
||||
pub async fn not_found(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = get_user_from_token!(jar, data.0);
|
||||
Html(
|
||||
render_error(
|
||||
Error::GeneralNotFound("page".to_string()),
|
||||
&jar,
|
||||
&data,
|
||||
&user,
|
||||
)
|
||||
.await,
|
||||
)
|
||||
}
|
||||
|
||||
/// `/`
|
||||
pub async fn index_request(jar: CookieJar, Extension(data): Extension<State>) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
|
|
|
@ -18,14 +18,20 @@ pub fn routes() -> Router {
|
|||
// misc
|
||||
.route("/", get(misc::index_request))
|
||||
.route("/notifs", get(misc::notifications_request))
|
||||
.fallback_service(get(misc::not_found))
|
||||
// auth
|
||||
.route("/auth/register", get(auth::register_request))
|
||||
.route("/auth/login", get(auth::login_request))
|
||||
// profile
|
||||
.route("/settings", get(profile::settings_request))
|
||||
.route("/user/{username}", get(profile::posts_request))
|
||||
// communities
|
||||
.route("/communities", get(communities::list_request))
|
||||
.route("/community/{title}", get(communities::feed_request))
|
||||
.route(
|
||||
"/community/{title}/manage",
|
||||
get(communities::settings_request),
|
||||
)
|
||||
.route("/post/{id}", get(communities::post_request))
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,48 @@ use axum_extra::extract::CookieJar;
|
|||
use tera::Context;
|
||||
use tetratto_core::model::{Error, auth::User, communities::Community};
|
||||
|
||||
/// `/settings`
|
||||
pub async fn settings_request(
|
||||
jar: CookieJar,
|
||||
Extension(data): Extension<State>,
|
||||
) -> impl IntoResponse {
|
||||
let data = data.read().await;
|
||||
let user = match get_user_from_token!(jar, data.0) {
|
||||
Some(ua) => ua,
|
||||
None => {
|
||||
return Err(Html(
|
||||
render_error(Error::NotAllowed, &jar, &data, &None).await,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let settings = user.settings.clone();
|
||||
let tokens = user.tokens.clone();
|
||||
|
||||
let lang = get_lang!(jar, data.0);
|
||||
let mut context = initial_context(&data.0.0, lang, &Some(user)).await;
|
||||
|
||||
context.insert(
|
||||
"user_settings_serde",
|
||||
&serde_json::to_string(&settings)
|
||||
.unwrap()
|
||||
.replace("\"", "\\\""),
|
||||
);
|
||||
context.insert(
|
||||
"user_tokens_serde",
|
||||
&serde_json::to_string(&tokens)
|
||||
.unwrap()
|
||||
.replace("\"", "\\\""),
|
||||
);
|
||||
|
||||
// return
|
||||
Ok(Html(
|
||||
data.1
|
||||
.render("profile/settings.html", &mut context)
|
||||
.unwrap(),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn profile_context(
|
||||
context: &mut Context,
|
||||
profile: &User,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue