mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-09 16:24:51 +00:00
Store user preferred language in database
This commit is contained in:
parent
c87d8c160b
commit
18bc9c3024
4 changed files with 35 additions and 9 deletions
|
@ -38,12 +38,14 @@ trait HomeSettings
|
|||
'name' => 'required|string|max:'.config('pixelfed.max_name_length'),
|
||||
'bio' => 'nullable|string|max:'.config('pixelfed.max_bio_length'),
|
||||
'website' => 'nullable|url',
|
||||
'language' => 'nullable|string|min:2|max:5'
|
||||
]);
|
||||
|
||||
$changes = false;
|
||||
$name = strip_tags(Purify::clean($request->input('name')));
|
||||
$bio = $request->filled('bio') ? strip_tags(Purify::clean($request->input('bio'))) : null;
|
||||
$website = $request->input('website');
|
||||
$language = $request->input('language');
|
||||
$user = Auth::user();
|
||||
$profile = $user->profile;
|
||||
$layout = $request->input('profile_layout');
|
||||
|
@ -51,10 +53,10 @@ trait HomeSettings
|
|||
$layout = !in_array($layout, ['metro', 'moment']) ? 'metro' : $layout;
|
||||
}
|
||||
|
||||
$validate = config('pixelfed.enforce_email_verification');
|
||||
$enforceEmailVerification = config('pixelfed.enforce_email_verification');
|
||||
|
||||
// Only allow email to be updated if not yet verified
|
||||
if (!$validate || !$changes && $user->email_verified_at) {
|
||||
if (!$enforceEmailVerification || !$changes && $user->email_verified_at) {
|
||||
if ($profile->name != $name) {
|
||||
$changes = true;
|
||||
$user->name = $name;
|
||||
|
@ -71,9 +73,12 @@ trait HomeSettings
|
|||
$profile->bio = $bio;
|
||||
}
|
||||
|
||||
if ($profile->profile_layout != $layout) {
|
||||
if($user->language != $language &&
|
||||
in_array($language, \App\Util\Localization\Localization::languages())
|
||||
) {
|
||||
$changes = true;
|
||||
$profile->profile_layout = $layout;
|
||||
$user->language = $language;
|
||||
session()->put('locale', $language);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,11 @@ class SiteController extends Controller
|
|||
// todo: add other locales after pushing new l10n strings
|
||||
$locales = Localization::languages();
|
||||
if(in_array($locale, $locales)) {
|
||||
if($request->user()) {
|
||||
$user = $request->user();
|
||||
$user->language = $locale;
|
||||
$user->save();
|
||||
}
|
||||
session()->put('locale', $locale);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class AuthLogin
|
|||
$this->userState($user);
|
||||
$this->userDevice($user);
|
||||
$this->userProfileId($user);
|
||||
$this->userLanguage($user);
|
||||
}
|
||||
|
||||
protected function userProfile($user)
|
||||
|
@ -132,4 +133,9 @@ class AuthLogin
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
protected function userLanguage($user)
|
||||
{
|
||||
session()->put('locale', $user->language ?? 'en');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,25 +37,25 @@
|
|||
<form method="post">
|
||||
@csrf
|
||||
<div class="form-group row">
|
||||
<label for="name" class="col-sm-3 col-form-label font-weight-bold text-right">Name</label>
|
||||
<label for="name" class="col-sm-3 col-form-label font-weight-bold">Name</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" id="name" name="name" placeholder="Your Name" value="{{Auth::user()->profile->name}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="username" class="col-sm-3 col-form-label font-weight-bold text-right">Username</label>
|
||||
<label for="username" class="col-sm-3 col-form-label font-weight-bold">Username</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="{{Auth::user()->profile->username}}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="website" class="col-sm-3 col-form-label font-weight-bold text-right">Website</label>
|
||||
<label for="website" class="col-sm-3 col-form-label font-weight-bold">Website</label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" class="form-control" id="website" name="website" placeholder="Website" value="{{Auth::user()->profile->website}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="bio" class="col-sm-3 col-form-label font-weight-bold text-right">Bio</label>
|
||||
<label for="bio" class="col-sm-3 col-form-label font-weight-bold">Bio</label>
|
||||
<div class="col-sm-9">
|
||||
<textarea class="form-control" id="bio" name="bio" placeholder="Add a bio here" rows="2" data-max-length="{{config('pixelfed.max_bio_length')}}">{{Auth::user()->profile->bio}}</textarea>
|
||||
<p class="form-text">
|
||||
|
@ -63,11 +63,21 @@
|
|||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="bio" class="col-sm-3 col-form-label font-weight-bold">Language</label>
|
||||
<div class="col-sm-9">
|
||||
<select class="form-control" name="language">
|
||||
@foreach(App\Util\Localization\Localization::languages() as $lang)
|
||||
<option value="{{$lang}}" {{Auth::user()->language == $lang ? 'selected':''}}>{{locale_get_display_language($lang, 'en')}} - {{locale_get_display_language($lang, $lang)}}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pt-3">
|
||||
<p class="font-weight-bold text-muted text-center">Storage Usage</p>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="email" class="col-sm-3 col-form-label font-weight-bold text-right">Storage Used</label>
|
||||
<label class="col-sm-3 col-form-label font-weight-bold">Storage Used</label>
|
||||
<div class="col-sm-9">
|
||||
<div class="progress mt-2">
|
||||
<div class="progress-bar" role="progressbar" style="width: {{$storage['percentUsed']}}%" aria-valuenow="{{$storage['percentUsed']}}" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
|
|
Loading…
Reference in a new issue