mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +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'),
|
'name' => 'required|string|max:'.config('pixelfed.max_name_length'),
|
||||||
'bio' => 'nullable|string|max:'.config('pixelfed.max_bio_length'),
|
'bio' => 'nullable|string|max:'.config('pixelfed.max_bio_length'),
|
||||||
'website' => 'nullable|url',
|
'website' => 'nullable|url',
|
||||||
|
'language' => 'nullable|string|min:2|max:5'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$changes = false;
|
$changes = false;
|
||||||
$name = strip_tags(Purify::clean($request->input('name')));
|
$name = strip_tags(Purify::clean($request->input('name')));
|
||||||
$bio = $request->filled('bio') ? strip_tags(Purify::clean($request->input('bio'))) : null;
|
$bio = $request->filled('bio') ? strip_tags(Purify::clean($request->input('bio'))) : null;
|
||||||
$website = $request->input('website');
|
$website = $request->input('website');
|
||||||
|
$language = $request->input('language');
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
$profile = $user->profile;
|
$profile = $user->profile;
|
||||||
$layout = $request->input('profile_layout');
|
$layout = $request->input('profile_layout');
|
||||||
|
@ -51,10 +53,10 @@ trait HomeSettings
|
||||||
$layout = !in_array($layout, ['metro', 'moment']) ? 'metro' : $layout;
|
$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
|
// 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) {
|
if ($profile->name != $name) {
|
||||||
$changes = true;
|
$changes = true;
|
||||||
$user->name = $name;
|
$user->name = $name;
|
||||||
|
@ -71,9 +73,12 @@ trait HomeSettings
|
||||||
$profile->bio = $bio;
|
$profile->bio = $bio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($profile->profile_layout != $layout) {
|
if($user->language != $language &&
|
||||||
|
in_array($language, \App\Util\Localization\Localization::languages())
|
||||||
|
) {
|
||||||
$changes = true;
|
$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
|
// todo: add other locales after pushing new l10n strings
|
||||||
$locales = Localization::languages();
|
$locales = Localization::languages();
|
||||||
if(in_array($locale, $locales)) {
|
if(in_array($locale, $locales)) {
|
||||||
|
if($request->user()) {
|
||||||
|
$user = $request->user();
|
||||||
|
$user->language = $locale;
|
||||||
|
$user->save();
|
||||||
|
}
|
||||||
session()->put('locale', $locale);
|
session()->put('locale', $locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ class AuthLogin
|
||||||
$this->userState($user);
|
$this->userState($user);
|
||||||
$this->userDevice($user);
|
$this->userDevice($user);
|
||||||
$this->userProfileId($user);
|
$this->userProfileId($user);
|
||||||
|
$this->userLanguage($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function userProfile($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">
|
<form method="post">
|
||||||
@csrf
|
@csrf
|
||||||
<div class="form-group row">
|
<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">
|
<div class="col-sm-9">
|
||||||
<input type="text" class="form-control" id="name" name="name" placeholder="Your Name" value="{{Auth::user()->profile->name}}">
|
<input type="text" class="form-control" id="name" name="name" placeholder="Your Name" value="{{Auth::user()->profile->name}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<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">
|
<div class="col-sm-9">
|
||||||
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="{{Auth::user()->profile->username}}" readonly>
|
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="{{Auth::user()->profile->username}}" readonly>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<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">
|
<div class="col-sm-9">
|
||||||
<input type="text" class="form-control" id="website" name="website" placeholder="Website" value="{{Auth::user()->profile->website}}">
|
<input type="text" class="form-control" id="website" name="website" placeholder="Website" value="{{Auth::user()->profile->website}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<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">
|
<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>
|
<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">
|
<p class="form-text">
|
||||||
|
@ -63,11 +63,21 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="pt-3">
|
||||||
<p class="font-weight-bold text-muted text-center">Storage Usage</p>
|
<p class="font-weight-bold text-muted text-center">Storage Usage</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group row">
|
<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="col-sm-9">
|
||||||
<div class="progress mt-2">
|
<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>
|
<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