Update SpaController, persist web language changes

This commit is contained in:
Daniel Supernault 2021-12-23 17:37:08 -07:00
parent aed570b3f6
commit 7bc684e5d1
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 21 additions and 0 deletions

View file

@ -9,6 +9,7 @@ use League\CommonMark\CommonMarkConverter;
use App\Services\AccountService; use App\Services\AccountService;
use App\Services\StatusService; use App\Services\StatusService;
use App\Services\SnowflakeService; use App\Services\SnowflakeService;
use App\Util\Localization\Localization;
class SpaController extends Controller class SpaController extends Controller
{ {
@ -68,6 +69,25 @@ class SpaController extends Controller
return redirect('404'); return redirect('404');
} }
public function updateLanguage(Request $request)
{
$this->validate($request, [
'v' => 'required|in:0.1,0.2',
'l' => 'required|alpha_dash|max:5'
]);
$lang = $request->input('l');
$user = $request->user();
abort_if(!in_array($lang, Localization::languages()), 400);
$user->language = $lang;
$user->save();
session()->put('locale', $lang);
return ['language' => $lang];
}
public function getPrivacy() public function getPrivacy()
{ {
$body = $this->markdownToHtml('views/page/privacy.md'); $body = $this->markdownToHtml('views/page/privacy.md');

View file

@ -210,6 +210,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
}); });
Route::get('discover/accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular'); Route::get('discover/accounts/popular', 'Api\ApiV1Controller@discoverAccountsPopular');
Route::post('web/change-language.json', 'SpaController@updateLanguage');
}); });
Route::group(['prefix' => 'local'], function () { Route::group(['prefix' => 'local'], function () {