Add the lang prefix to all links
This commit is contained in:
parent
b39cb1c067
commit
3089ede6eb
7 changed files with 40 additions and 11 deletions
|
|
@ -21,7 +21,12 @@ pub async fn create(
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
if let Some(user) = user {
|
if let Some(user) = user {
|
||||||
let recipe_id = connection.create_recipe(user.id).await?;
|
let recipe_id = connection.create_recipe(user.id).await?;
|
||||||
Ok(Redirect::to(&format!("/recipe/edit/{}", recipe_id)).into_response())
|
Ok(Redirect::to(&format!(
|
||||||
|
"/{}/recipe/edit/{}",
|
||||||
|
tr.current_lang_code(),
|
||||||
|
recipe_id
|
||||||
|
))
|
||||||
|
.into_response())
|
||||||
} else {
|
} else {
|
||||||
Ok(Html(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).render()?).into_response())
|
Ok(Html(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).render()?).into_response())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -343,7 +343,10 @@ pub async fn sign_in_post(
|
||||||
)),
|
)),
|
||||||
db::user::SignInResult::Ok(token, _user_id) => {
|
db::user::SignInResult::Ok(token, _user_id) => {
|
||||||
let cookie = Cookie::new(consts::COOKIE_AUTH_TOKEN_NAME, token);
|
let cookie = Cookie::new(consts::COOKIE_AUTH_TOKEN_NAME, token);
|
||||||
Ok((jar.add(cookie), Redirect::to("/").into_response()))
|
Ok((
|
||||||
|
jar.add(cookie),
|
||||||
|
Redirect::to(&format!("/{}/", tr.current_lang_code())).into_response(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -353,6 +356,7 @@ pub async fn sign_in_post(
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn sign_out(
|
pub async fn sign_out(
|
||||||
State(connection): State<db::Connection>,
|
State(connection): State<db::Connection>,
|
||||||
|
Extension(tr): Extension<translation::Tr>,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> Result<(CookieJar, Redirect)> {
|
) -> Result<(CookieJar, Redirect)> {
|
||||||
let mut jar = CookieJar::from_headers(req.headers());
|
let mut jar = CookieJar::from_headers(req.headers());
|
||||||
|
|
@ -361,7 +365,7 @@ pub async fn sign_out(
|
||||||
jar = jar.remove(consts::COOKIE_AUTH_TOKEN_NAME);
|
jar = jar.remove(consts::COOKIE_AUTH_TOKEN_NAME);
|
||||||
connection.sign_out(&token).await?;
|
connection.sign_out(&token).await?;
|
||||||
}
|
}
|
||||||
Ok((jar, Redirect::to("/")))
|
Ok((jar, Redirect::to(&format!("/{}/", tr.current_lang_code()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RESET PASSWORD ///
|
/// RESET PASSWORD ///
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
{% match user %}
|
{% match user %}
|
||||||
{% when Some with (user) %}
|
{% when Some with (user) %}
|
||||||
<a class="create-recipe" href="/recipe/new" >{{ tr.t(Sentence::CreateNewRecipe) }}</a>
|
<a class="create-recipe" href="/recipe/new" >{{ tr.t(Sentence::CreateNewRecipe) }}</a>
|
||||||
<a href="/user/edit">
|
<a href="/{{ tr.current_lang_code() }}/user/edit">
|
||||||
{% if user.name == "" %}
|
{% if user.name == "" %}
|
||||||
{{ user.email }}
|
{{ user.email }}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a> / <a href="/signout">{{ tr.t(Sentence::SignOut) }}</a>
|
</a> / <a href="/signout">{{ tr.t(Sentence::SignOut) }}</a>
|
||||||
{% when None %}
|
{% when None %}
|
||||||
<a href="/signin" >{{ tr.t(Sentence::SignInMenu) }}</a>/<a href="/signup">{{ tr.t(Sentence::SignUpMenu) }}</a>/<a href="/ask_reset_password">{{ tr.t(Sentence::LostPassword) }}</a>
|
<a href="/{{ tr.current_lang_code() }}/signin" >{{ tr.t(Sentence::SignInMenu) }}</a>/<a href="/{{ tr.current_lang_code() }}/signup">{{ tr.t(Sentence::SignUpMenu) }}</a>/<a href="/{{ tr.current_lang_code() }}/ask_reset_password">{{ tr.t(Sentence::LostPassword) }}</a>
|
||||||
{% endmatch %}
|
{% endmatch %}
|
||||||
|
|
||||||
<select id="select-website-language">
|
<select id="select-website-language">
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
<div class="content" id="user-edit">
|
<div class="content" id="user-edit">
|
||||||
<h1>{{ tr.t(Sentence::ProfileTitle) }}</h1>
|
<h1>{{ tr.t(Sentence::ProfileTitle) }}</h1>
|
||||||
|
|
||||||
<form action="/user/edit" method="post">
|
<form action="/{{ tr.current_lang_code() }}/user/edit" method="post">
|
||||||
|
|
||||||
<label for="input-name">{{ tr.t(Sentence::Name) }}</label>
|
<label for="input-name">{{ tr.t(Sentence::Name) }}</label>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
{% if let Some(user) = user %}
|
{% if let Some(user) = user %}
|
||||||
{% if crate::data::model::can_user_edit_recipe(user, recipe) %}
|
{% if crate::data::model::can_user_edit_recipe(user, recipe) %}
|
||||||
<a class="edit-recipe" href="/recipe/edit/{{ recipe.id }}" >Edit</a>
|
<a class="edit-recipe" href="/{{ tr.current_lang_code() }}/recipe/edit/{{ recipe.id }}" >Edit</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,19 @@ pub fn main() -> Result<(), JsValue> {
|
||||||
let lang = utils::get_current_lang();
|
let lang = utils::get_current_lang();
|
||||||
|
|
||||||
let location = window().location().pathname()?;
|
let location = window().location().pathname()?;
|
||||||
|
|
||||||
let path: Vec<&str> = location
|
let path: Vec<&str> = location
|
||||||
.split('/')
|
.split('/')
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.skip_while(|part| *part == lang)
|
.skip_while(|part| *part == lang)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
let mut location_without_lang = String::new();
|
||||||
|
for part in &path {
|
||||||
|
location_without_lang.push('/');
|
||||||
|
location_without_lang.push_str(part);
|
||||||
|
}
|
||||||
|
|
||||||
let is_user_logged = selector::<HtmlElement>("html")
|
let is_user_logged = selector::<HtmlElement>("html")
|
||||||
.dataset()
|
.dataset()
|
||||||
.get("userLogged")
|
.get("userLogged")
|
||||||
|
|
@ -54,10 +61,20 @@ pub fn main() -> Result<(), JsValue> {
|
||||||
let select_language: HtmlSelectElement = by_id("select-website-language");
|
let select_language: HtmlSelectElement = by_id("select-website-language");
|
||||||
EventListener::new(&select_language.clone(), "input", move |_event| {
|
EventListener::new(&select_language.clone(), "input", move |_event| {
|
||||||
let lang = select_language.value();
|
let lang = select_language.value();
|
||||||
let body = ron_api::SetLang { lang };
|
let body = ron_api::SetLang { lang: lang.clone() };
|
||||||
|
let location_without_lang = location_without_lang.clone();
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
let _ = request::put::<(), _>("set_lang", body).await;
|
let _ = request::put::<(), _>("set_lang", body).await;
|
||||||
let _ = window().location().reload();
|
|
||||||
|
window()
|
||||||
|
.location()
|
||||||
|
.set_href(&format!(
|
||||||
|
"/{}{}{}",
|
||||||
|
lang,
|
||||||
|
location_without_lang,
|
||||||
|
window().location().search().unwrap().as_str()
|
||||||
|
))
|
||||||
|
.unwrap();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.forget();
|
.forget();
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ use web_sys::{
|
||||||
use crate::{
|
use crate::{
|
||||||
modal_dialog, request,
|
modal_dialog, request,
|
||||||
toast::{self, Level},
|
toast::{self, Level},
|
||||||
utils::{SelectorExt, by_id, selector, selector_and_clone},
|
utils::{SelectorExt, by_id, get_current_lang, selector, selector_and_clone},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn setup_page(recipe_id: i64) {
|
pub fn setup_page(recipe_id: i64) {
|
||||||
|
|
@ -262,7 +262,10 @@ pub fn setup_page(recipe_id: i64) {
|
||||||
{
|
{
|
||||||
let body = ron_api::Id { id: recipe_id };
|
let body = ron_api::Id { id: recipe_id };
|
||||||
let _ = request::delete::<(), _>("recipe/remove", body).await;
|
let _ = request::delete::<(), _>("recipe/remove", body).await;
|
||||||
window().location().set_href("/").unwrap();
|
window()
|
||||||
|
.location()
|
||||||
|
.set_href(&format!("/{}/", get_current_lang()))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue