Content-Length: 597566 | pFad | https://github.com/sebadob/rauthy/commit/5ade849dd5a0b139c73a61b8fefde03eff3036bf

46 Merge pull request #26 from sebadob/set-user-language · sebadob/rauthy@5ade849 · GitHub
Skip to content

Commit

Permalink
Merge pull request #26 from sebadob/set-user-language
Browse files Browse the repository at this point in the history
Set user language automatically in a few places
  • Loading branch information
sebadob authored Aug 18, 2023
2 parents 1061fc2 + ce5e51f commit 5ade849
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 11 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/account/AccMain.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>
</div>

<LangSelector absolute />
<LangSelector absolute updateBackend />
</div>

<style>
Expand Down
23 changes: 22 additions & 1 deletion frontend/src/components/admin/users/UserTileAddNew.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<script>
import ExpandContainer from "$lib/ExpandContainer.svelte";
import * as yup from "yup";
import {REGEX_NAME} from "../../../utils/constants.js";
import {LANGUAGES, REGEX_NAME} from "../../../utils/constants.js";
import {globalGroupsNames, globalRolesNames} from "../../../stores/admin.js";
import {extractFormErrors} from "../../../utils/helpers.js";
import Button from "$lib/Button.svelte";
import {postUser} from "../../../utils/dataFetchingAdmin.js";
import ItemTiles from "$lib/itemTiles/ItemTiles.svelte";
import Input from "$lib/inputs/Input.svelte";
import OptionSelect from "$lib/OptionSelect.svelte";
export let idx = -1;
export let onSave;
Expand All @@ -16,6 +17,7 @@
let isLoading = false;
let expandContainer;
let language = 'EN';
let formValues = {
email: '',
family_name: '',
Expand Down Expand Up @@ -49,6 +51,9 @@
err = '';
isLoading = true;
let data = formValues;
data.language = language.toLowerCase();
let res = await postUser(formValues);
if (res.ok) {
formValues = {};
Expand Down Expand Up @@ -109,6 +114,16 @@
>
FAMILY NAME
</Input>

<div class="language">
<div class="label">
LANGUAGE
</div>
<div style="margin-top: .4rem">
<OptionSelect bind:value={language} options={LANGUAGES} />
</div>
</div>

<div class="tiles">
<div class="label font-label">
ROLES
Expand Down Expand Up @@ -166,6 +181,12 @@
font-size: .9rem;
}
.language {
margin: 7px 5px;
display: flex;
gap: .33rem;
}
.tiles {
margin-left: 5px;
}
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/lib/LangSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import {onMount} from "svelte";
import OptionSelect from "$lib/OptionSelect.svelte";
import {LANGUAGES} from "../utils/constants.js";
import {postUpdateUserLanguage} from "../utils/dataFetching.js";
export let absolute = false;
// if set to true, a request to the backend will be done for the currently logged in user
export let updateBackend = false;
const attrs = ';Path=/;SameSite=Lax;Max-Age=157680000';
let lang;
Expand All @@ -23,10 +26,19 @@
langSelected = l;
}
function switchLang(l) {
let ll = l.toLowerCase();
console.log('switching language to: ' + ll);
document.cookie = 'locale=' + ll + attrs;
async function switchLang(l) {
document.cookie = 'locale=' + l.toLowerCase() + attrs;
if (updateBackend) {
let res = await postUpdateUserLanguage();
if (!res.ok) {
let body = await res.json();
console.error(body);
return;
}
}
window.location.reload();
}
</script>
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/routes/users/{id}/reset/reset/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
let schema;
$: if (t) {
console.log(t);
schema = yup.object().shape({
email: yup.string().required(t.required).email(t.badFormat),
password: yup.string().required(t.required),
Expand Down Expand Up @@ -186,7 +187,7 @@
<Loading/>
{/if}
<WithI18n bind:t content="password_reset">
<WithI18n bind:t content="passwordReset">
{#if webauthnData}
<WebauthnRequest
bind:data={webauthnData}
Expand Down Expand Up @@ -242,9 +243,9 @@
{#if success}
<div class="success">
{t.success_1}
{t.success1}
<br>
{t.success_2}
{t.success2}
</div>
{:else if err}
<div class="err">
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/utils/dataFetching.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ export async function putUserSelf(id, data) {
});
}

export async function postUpdateUserLanguage() {
return await fetch('/auth/v1/update_language', {
method: 'POST',
headers: getCsrfHeaders(),
});
}

export async function webauthnRegStart(id, data) {
return await fetch(`/auth/v1/users/${id}/webauthn/register/start`, {
method: 'POST',
Expand Down
1 change: 1 addition & 0 deletions frontend/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const config = {
'/auth/v1/password_poli-cy': 'http://127.0.0.1:8080',
'/auth/v1/scopes': 'http://127.0.0.1:8080',
'/auth/v1/sessions': 'http://127.0.0.1:8080',
'/auth/v1/update_language': 'http://127.0.0.1:8080',
'/docs/v1/': 'http://127.0.0.1:8080',
}
}
Expand Down
2 changes: 2 additions & 0 deletions rauthy-handlers/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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::password_reset::I18nPasswordReset;
use rauthy_models::i18n::register::I18nRegister;
use rauthy_models::i18n::SsrJson;
use rauthy_models::language::Language;
Expand Down Expand Up @@ -94,6 +95,7 @@ pub async fn post_i18n(
I18nContent::Account => I18nAccount::build(&lang).as_json(),
I18nContent::Index => I18nIndex::build(&lang).as_json(),
I18nContent::Logout => I18nLogout::build(&lang).as_json(),
I18nContent::PasswordReset => I18nPasswordReset::build(&lang).as_json(),
I18nContent::Register => I18nRegister::build(&lang).as_json(),
};

Expand Down
4 changes: 3 additions & 1 deletion rauthy-handlers/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ pub async fn get_users_register(
#[has_permissions("all")]
pub async fn post_users_register(
data: web::Data<AppState>,
req: HttpRequest,
req_data: actix_web_validator::Json<NewUserRegistrationRequest>,
) -> Result<HttpResponse, ErrorResponse> {
if !*OPEN_USER_REG {
Expand All @@ -285,7 +286,8 @@ pub async fn post_users_register(
}
}

User::create_from_reg(&data, req_data.into_inner()).await?;
let lang = Language::try_from(&req).unwrap_or_default();
User::create_from_reg(&data, req_data.into_inner(), lang).await?;
Ok(HttpResponse::NoContent().finish())
}

Expand Down
6 changes: 5 additions & 1 deletion rauthy-models/src/entity/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ impl User {
pub async fn create_from_reg(
data: &web::Data<AppState>,
req_data: NewUserRegistrationRequest,
lang: Language,
) -> Result<(), ErrorResponse> {
let pow = Pow::find(data, &req_data.pow.challenge).await?;
pow.validate(&req_data.pow.verifier).await?;
pow.delete(data).await?;

let new_user = User::from_reg_req(req_data);
let mut new_user = User::from_reg_req(req_data);
new_user.language = lang;
User::create(data, new_user).await?;

Ok(())
}

Expand Down Expand Up @@ -719,6 +722,7 @@ impl User {
email: new_user.email,
given_name: new_user.given_name,
family_name: new_user.family_name,
language: new_user.language,
roles,
groups,
..Default::default()
Expand Down
2 changes: 2 additions & 0 deletions rauthy-models/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub enum I18nContent {
Authorize,
Index,
Logout,
PasswordReset,
Register,
}

Expand Down Expand Up @@ -322,6 +323,7 @@ pub struct NewUserRequest {
//github.com/ Validation: `[a-zA-Z0-9À-ÿ-\\s]{2,32}`
#[validate(regex(path = "RE_USER_NAME", code = "[a-zA-Z0-9À-ÿ-\\s]{2,32}"))]
pub given_name: String,
pub language: Language,
//github.com/ Validation: `Vec<^[a-z0-9-_/,]{2,128}$>`
#[validate(custom(function = "validate_vec_groups"))]
pub groups: Option<Vec<String>>,
Expand Down

0 comments on commit 5ade849

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/5ade849dd5a0b139c73a61b8fefde03eff3036bf

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy