Skip to content

Commit

Permalink
Merge pull request #9 from sebadob/i18n-index-register-logout
Browse files Browse the repository at this point in the history
i18n for index + register + logout
  • Loading branch information
sebadob authored Aug 10, 2023
2 parents 4208fdb + f3f3274 commit 7b401f6
Show file tree
Hide file tree
Showing 14 changed files with 314 additions and 104 deletions.
3 changes: 1 addition & 2 deletions frontend/src/routes/account/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import WithI18n from "$lib/WithI18n.svelte";
let t;
let sessionInfo;
let user;
let isReady = false;
Expand All @@ -32,7 +31,7 @@
</script>

<svelte:head>
<title>Account {user?.email}</title>
<title>{t?.account || 'Account'} {user?.email}</title>
</svelte:head>

<BrowserCheck>
Expand Down
20 changes: 13 additions & 7 deletions frontend/src/routes/index/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
import {onMount} from "svelte";
import Button from "$lib/Button.svelte";
import BrowserCheck from "../../components/BrowserCheck.svelte";
import WithI18n from "$lib/WithI18n.svelte";
import LangSelector from "$lib/LangSelector.svelte";
const btnWidth = "9rem";
let t;
let renderReg = false;
onMount(() => {
Expand Down Expand Up @@ -32,13 +35,16 @@
</svelte:head>

<BrowserCheck>
<div class="btn">
{#if renderReg}
<Button on:click={redirectToReg} width={btnWidth}>REGISTER</Button>
{/if}
<Button on:click={redirectToAccount} width={btnWidth}>ACCOUNT LOGIN</Button>
<Button on:click={redirectToAdmin} width={btnWidth}>ADMIN LOGIN</Button>
</div>
<WithI18n bind:t content="index">
<div class="btn">
{#if renderReg}
<Button on:click={redirectToReg} width={btnWidth}>{t.register.toUpperCase()}</Button>
{/if}
<Button on:click={redirectToAccount} width={btnWidth}>{t.accountLogin.toUpperCase()}</Button>
<Button on:click={redirectToAdmin} width={btnWidth}>{t.adminLogin.toUpperCase()}</Button>
</div>
<LangSelector absolute />
</WithI18n>
</BrowserCheck>

<style>
Expand Down
36 changes: 20 additions & 16 deletions frontend/src/routes/oidc/logout/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import {logout} from "../../../utils/dataFetching.js";
import Button from "$lib/Button.svelte";
import Loading from "$lib/Loading.svelte";
import WithI18n from "$lib/WithI18n.svelte";
let t;
let err = '';
let postLogoutUri = '';
let isLoading = false;
Expand Down Expand Up @@ -55,27 +57,29 @@
</script>

<svelte:head>
<title>Logout</title>
<title>{t?.logout || 'Logout'}</title>
</svelte:head>

<div class="container">
<h1>Logout</h1>
<WithI18n bind:t content="logout">
<div class="container">
<h1>{t.logout}</h1>

<div>
Do you really want to logout and end your session?
</div>

<div class="btn">
<Button on:click={handleLogout} level={2} bind:isLoading>LOGOUT</Button>
<Button on:click={handleCancel} level={4}>CANCEL</Button>
</div>
<p>
{t.confirmMsg}
</p>

{#if err}
<div class:err>
{err}
<div class="btn">
<Button on:click={handleLogout} level={2} bind:isLoading>{t.logout.toUpperCase()}</Button>
<Button on:click={handleCancel} level={4}>{t.cancel.toUpperCase()}</Button>
</div>
{/if}
</div>

{#if err}
<div class:err>
{err}
</div>
{/if}
</div>
</WithI18n>

<style>
.btn {
Expand Down
134 changes: 72 additions & 62 deletions frontend/src/routes/users/register/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import {onMount, tick} from "svelte";
import Input from "$lib/inputs/Input.svelte";
import BrowserCheck from "../../../components/BrowserCheck.svelte";
import WithI18n from "$lib/WithI18n.svelte";
import LangSelector from "$lib/LangSelector.svelte";
let t;
let restrictedDomain;
let isLoading = false;
let err = '';
Expand All @@ -16,15 +19,18 @@
let formValues = { email: '', givenName: '', familyName: '' };
let formErrors = {};
const schema = yup.object().shape({
email: yup.string().required('E-Mail is required').email("Bad E-Mail format"),
givenName: yup.string()
.required('Given Name is required')
.matches(REGEX_NAME, "Your given name with 2 - 32 non-special characters"),
familyName: yup.string()
.required('Family Name is required')
.matches(REGEX_NAME, "Your family name with 2 - 32 non-special characters"),
});
let schema = {};
$: if (t) {
schema = yup.object().shape({
email: yup.string().required(t.required).email(t.emailBadFormat),
givenName: yup.string()
.required(t.required)
.matches(REGEX_NAME, t.regexName),
familyName: yup.string()
.required(t.required)
.matches(REGEX_NAME, t.regexName),
});
}
onMount(() => {
restrictedDomain = window.document.getElementsByName('rauthy-data')[0].id;
Expand All @@ -50,7 +56,7 @@
}
if (!formValues.email.endsWith(restrictedDomain)) {
err = 'E-Mail domain not allowed';
err = t.domainErr;
return;
}
Expand Down Expand Up @@ -88,61 +94,65 @@
</script>

<svelte:head>
<title>Register</title>
<title>{t?.register || 'Register'}</title>
</svelte:head>

<BrowserCheck>
<div class="container">
{#if restrictedDomain}
<div class="domainTxt">
<h1>User Registration</h1>
E-Mail domains are restricted.<br>
Allowed domain: <code>@{restrictedDomain}</code>
</div>
{/if}

<Input
type="email"
bind:value={formValues.email}
bind:error={formErrors.email}
autocomplete="email"
placeholder="E-Mail"
on:keypress={handleKeyPress}
>
E-MAIL
</Input>
<Input
bind:value={formValues.givenName}
bind:error={formErrors.givenName}
autocomplete="given-name"
placeholder="Given NAme"
on:keypress={handleKeyPress}
>
GIVEN NAME
</Input>
<Input
bind:value={formValues.familyName}
bind:error={formErrors.familyName}
autocomplete="family-name"
placeholder="Family Name"
on:keypress={handleKeyPress}
>
FAMILY NAME
</Input>

<Button on:click={onSubmit} bind:isLoading>REGISTER</Button>

{#if success}
<div class="success">
Registration successful.<br/>
Please check your E-Mail inbox.
</div>
{:else if err}
<div class="err">
{err}
</div>
{/if}
</div>
<WithI18n bind:t content="register">
<div class="container">
{#if restrictedDomain}
<div class="domainTxt">
<h1>{t.userReg}</h1>
{t.domainRestricted}<br>
{t.domainAllowed} <code>@{restrictedDomain}</code>
</div>
{/if}

<Input
type="email"
bind:value={formValues.email}
bind:error={formErrors.email}
autocomplete="email"
placeholder={t.email}
on:keypress={handleKeyPress}
>
{t.email.toUpperCase()}
</Input>
<Input
bind:value={formValues.givenName}
bind:error={formErrors.givenName}
autocomplete="given-name"
placeholder={t.givenName}
on:keypress={handleKeyPress}
>
{t.givenName.toUpperCase()}
</Input>
<Input
bind:value={formValues.familyName}
bind:error={formErrors.familyName}
autocomplete="family-name"
placeholder={t.familyName}
on:keypress={handleKeyPress}
>
{t.familyName.toUpperCase()}
</Input>

<Button on:click={onSubmit} bind:isLoading>{t.register.toUpperCase()}</Button>

{#if success}
<div class="success">
{t.success}<br/>
{t.emailCheck}
</div>
{:else if err}
<div class="err">
{err}
</div>
{/if}
</div>

<LangSelector absolute />
</WithI18n>
</BrowserCheck>

<style>
Expand Down
17 changes: 14 additions & 3 deletions rauthy-handlers/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ use rauthy_models::entity::principal::Principal;
use rauthy_models::entity::sessions::Session;
use rauthy_models::i18n::account::I18nAccount;
use rauthy_models::i18n::authorize::I18nAuthorize;
use rauthy_models::i18n::index::I18nIndex;
use rauthy_models::i18n::logout::I18nLogout;
use rauthy_models::i18n::register::I18nRegister;
use rauthy_models::i18n::SsrJson;
use rauthy_models::language::Language;
use rauthy_models::request::{
Expand All @@ -33,12 +36,17 @@ use rauthy_models::templates::{
use rauthy_service::encryption;
use redhac::{cache_get, cache_get_from, cache_get_value};
use std::borrow::Cow;
use tracing::debug;

#[get("/")]
#[has_permissions("all")]
pub async fn get_index(data: web::Data<AppState>) -> Result<HttpResponse, ErrorResponse> {
pub async fn get_index(
data: web::Data<AppState>,
req: HttpRequest,
) -> Result<HttpResponse, ErrorResponse> {
let colors = ColorEntity::find_rauthy(&data).await?;
let (body, nonce) = IndexHtml::build(&colors);
let lang = Language::try_from(&req).unwrap_or_default();
let (body, nonce) = IndexHtml::build(&colors, &lang);

Ok(HttpResponse::Ok()
.insert_header(HEADER_HTML)
Expand Down Expand Up @@ -81,11 +89,14 @@ pub async fn post_i18n(
req_data: Json<I18nRequest>,
) -> Result<HttpResponse, ErrorResponse> {
let lang = Language::try_from(&req).unwrap_or_default();
tracing::debug!("post_i18n lang: {:?} req: {:?}", lang, req_data);
debug!("post_i18n lang: {:?} req: {:?}", lang, req_data);

let body = match req_data.content {
I18nContent::Authorize => I18nAuthorize::build(&lang).as_json(),
I18nContent::Account => I18nAccount::build(&lang).as_json(),
I18nContent::Index => I18nIndex::build(&lang).as_json(),
I18nContent::Logout => I18nLogout::build(&lang).as_json(),
I18nContent::Register => I18nRegister::build(&lang).as_json(),
};

Ok(HttpResponse::Ok()
Expand Down
7 changes: 3 additions & 4 deletions rauthy-handlers/src/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ pub async fn get_authorize(
)
.await?;

// TODO use for testing i18n
let lang = Language::try_from(&req).unwrap_or_default();
tracing::info!("lang: {:?}", lang);

let colors = ColorEntity::find(&data, &req_data.client_id).await?;

if session.is_some() && session.as_ref().unwrap().state == SessionState::Auth {
Expand Down Expand Up @@ -275,6 +272,7 @@ pub async fn get_cert_by_kid(
#[has_permissions("all")]
pub async fn get_logout(
data: web::Data<AppState>,
req: HttpRequest,
req_data: web::Query<LogoutRequest>,
session_req: web::ReqData<Option<Session>>,
) -> HttpResponse {
Expand All @@ -289,7 +287,8 @@ pub async fn get_logout(
}
};

let (body, nonce) = match auth::logout(req_data.into_inner(), session, &data).await {
let lang = Language::try_from(&req).unwrap_or_default();
let (body, nonce) = match auth::logout(req_data.into_inner(), session, &data, &lang).await {
Ok(t) => t,
Err(_) => {
return HttpResponse::build(StatusCode::from_u16(302).unwrap())
Expand Down
9 changes: 7 additions & 2 deletions rauthy-handlers/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rauthy_models::entity::sessions::{Session, SessionState};
use rauthy_models::entity::user_attr::{UserAttrConfigEntity, UserAttrValueEntity};
use rauthy_models::entity::users::User;
use rauthy_models::entity::webauthn;
use rauthy_models::language::Language;
use rauthy_models::request::{
MfaPurpose, NewUserRegistrationRequest, NewUserRequest, PasswordResetRequest,
RequestResetRequest, UpdateUserRequest, UpdateUserSelfRequest, UserAttrConfigRequest,
Expand Down Expand Up @@ -225,16 +226,20 @@ pub async fn delete_cust_attr(
)]
#[get("/users/register")]
#[has_permissions("all")]
pub async fn get_users_register(data: web::Data<AppState>) -> Result<HttpResponse, ErrorResponse> {
pub async fn get_users_register(
data: web::Data<AppState>,
req: HttpRequest,
) -> Result<HttpResponse, ErrorResponse> {
if !*OPEN_USER_REG {
return Err(ErrorResponse::new(
ErrorResponseType::Forbidden,
"Open User Registration is not allowed".to_string(),
));
}

let lang = Language::try_from(&req).unwrap_or_default();
let colors = ColorEntity::find_rauthy(&data).await?;
let (body, nonce) = UserRegisterHtml::build(&colors);
let (body, nonce) = UserRegisterHtml::build(&colors, &lang);
Ok(HttpResponse::Ok()
.insert_header(HEADER_HTML)
.insert_header(build_csp_header(&nonce))
Expand Down
Loading

0 comments on commit 7b401f6

Please sign in to comment.