move language switcher to HomeController
This commit is contained in:
parent
85645a0e6a
commit
1cdfb139c1
|
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use Session;
|
use Session;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
class HomeController extends Controller
|
class HomeController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -13,10 +14,7 @@ class HomeController extends Controller
|
||||||
if (isset($_COOKIE['uid']) && isset($_COOKIE['token'])) {
|
if (isset($_COOKIE['uid']) && isset($_COOKIE['token'])) {
|
||||||
$user = new User($_COOKIE['uid']);
|
$user = new User($_COOKIE['uid']);
|
||||||
|
|
||||||
if ($_COOKIE['token'] == $user->getToken() && $user->getPermission() != "-1") {
|
if ($_COOKIE['token'] != $user->getToken() || $user->getPermission() == "-1") {
|
||||||
Session::put('uid' , $_COOKIE['uid']);
|
|
||||||
Session::put('token', $_COOKIE['token']);
|
|
||||||
} else {
|
|
||||||
// delete cookies
|
// delete cookies
|
||||||
setcookie("uid", "", time() - 3600, '/');
|
setcookie("uid", "", time() - 3600, '/');
|
||||||
setcookie("token", "", time() - 3600, '/');
|
setcookie("token", "", time() - 3600, '/');
|
||||||
|
|
@ -28,4 +26,12 @@ class HomeController extends Controller
|
||||||
return view('index')->with('user', $user);
|
return view('index')->with('user', $user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function locale($lang)
|
||||||
|
{
|
||||||
|
if (Arr::exists(config('locales'), $lang)) {
|
||||||
|
Session::set('locale', $lang);
|
||||||
|
}
|
||||||
|
return redirect('/')->withCookie('locale', $lang);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use App;
|
use App;
|
||||||
|
use Cookie;
|
||||||
use Session;
|
use Session;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
|
@ -10,8 +11,14 @@ class Internationalization
|
||||||
{
|
{
|
||||||
public function handle($request, \Closure $next)
|
public function handle($request, \Closure $next)
|
||||||
{
|
{
|
||||||
|
// Load from cookie
|
||||||
|
if (Cookie::has('locale')) {
|
||||||
|
session(['locale' => Cookie::get('locale')]);
|
||||||
|
}
|
||||||
|
|
||||||
if (Session::has('locale') && Arr::exists(config('locales'), session('locale'))) {
|
if (Session::has('locale') && Arr::exists(config('locales'), session('locale'))) {
|
||||||
App::setLocale(Session::get('locale'));
|
// Set app locale dynamically
|
||||||
|
App::setLocale(session('locale'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $next($request);
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,7 @@
|
||||||
Route::get('/', 'HomeController@index');
|
Route::get('/', 'HomeController@index');
|
||||||
Route::get('/index.php', 'HomeController@index');
|
Route::get('/index.php', 'HomeController@index');
|
||||||
|
|
||||||
Route::get('/locale/{lang}', function($lang) {
|
Route::get('/locale/{lang}', 'HomeController@locale');
|
||||||
if (Illuminate\Support\Arr::exists(config('locales'), $lang)) {
|
|
||||||
Session::set('locale', $lang);
|
|
||||||
}
|
|
||||||
return redirect('/');
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth
|
* Auth
|
||||||
|
|
@ -50,7 +45,7 @@ Route::group(['prefix' => 'auth'], function()
|
||||||
Route::group(['middleware' => 'App\Http\Middleware\CheckAuthenticated', 'prefix' => 'user'], function()
|
Route::group(['middleware' => 'App\Http\Middleware\CheckAuthenticated', 'prefix' => 'user'], function()
|
||||||
{
|
{
|
||||||
Route::any ('', 'UserController@index');
|
Route::any ('', 'UserController@index');
|
||||||
Route::any ('/sign', 'UserController@sign');
|
Route::any ('/checkin', 'UserController@checkIn');
|
||||||
|
|
||||||
// Profile
|
// Profile
|
||||||
Route::get ('/profile', 'UserController@profile');
|
Route::get ('/profile', 'UserController@profile');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user