) -> Result<Response> {
if let Some(user) = user {
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 {
Ok(Html(MessageTemplate::new(tr.t(Sentence::NotLoggedIn), tr).render()?).into_response())
}
)),
db::user::SignInResult::Ok(token, _user_id) => {
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(),
+ ))
}
}
}
#[debug_handler]
pub async fn sign_out(
State(connection): State<db::Connection>,
+ Extension(tr): Extension<translation::Tr>,
req: Request<Body>,
) -> Result<(CookieJar, Redirect)> {
let mut jar = CookieJar::from_headers(req.headers());
jar = jar.remove(consts::COOKIE_AUTH_TOKEN_NAME);
connection.sign_out(&token).await?;
}
- Ok((jar, Redirect::to("/")))
+ Ok((jar, Redirect::to(&format!("/{}/", tr.current_lang_code()))))
}
/// RESET PASSWORD ///
{% match user %}
{% when Some with (user) %}
<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 == "" %}
{{ user.email }}
{% else %}
{% endif %}
</a> / <a href="/signout">{{ tr.t(Sentence::SignOut) }}</a>
{% 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 %}
<select id="select-website-language">
<div class="content" id="user-edit">
<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>
<input
{% if let Some(user) = user %}
{% 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 %}
let lang = utils::get_current_lang();
let location = window().location().pathname()?;
+
let path: Vec<&str> = location
.split('/')
.skip(1)
.skip_while(|part| *part == lang)
.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")
.dataset()
.get("userLogged")
let select_language: HtmlSelectElement = by_id("select-website-language");
EventListener::new(&select_language.clone(), "input", move |_event| {
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 {
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();
use crate::{
modal_dialog, request,
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) {
{
let body = ron_api::Id { id: recipe_id };
let _ = request::delete::<(), _>("recipe/remove", body).await;
- window().location().set_href("/").unwrap();
+ window()
+ .location()
+ .set_href(&format!("/{}/", get_current_lang()))
+ .unwrap();
}
});
})