diff --git a/app/Http/Controllers/KeyController.php b/app/Http/Controllers/KeyController.php index be13bc9f4b4b0550137081ebfff6beaae8bfc869..eb9f37a04720da71f692ff88cb5e1167ae557bcb 100644 --- a/app/Http/Controllers/KeyController.php +++ b/app/Http/Controllers/KeyController.php @@ -5,15 +5,15 @@ namespace App\Http\Controllers; use Cookie; use Illuminate\Http\Request; use LaravelLocalization; +use \App\Models\Key; class KeyController extends Controller { public function index(Request $request) { $redirUrl = $request->input('redirUrl', ""); - $cookie = Cookie::get('key'); - $key = $request->input('key', ''); + $key = $request->input('keyToSet', ''); if(empty($key) && empty($cookie)){ $key = 'enter_key_here'; @@ -23,42 +23,40 @@ class KeyController extends Controller $key = $request->input('key'); } + $cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', Cookie::get())); return view('key') ->with('title', trans('titles.key')) - ->with('cookie', $key); + ->with('cookie', $key) + ->with('cookieLink', $cookieLink); } public function setKey(Request $request) { $redirUrl = $request->input('redirUrl', ""); - $key = $request->input('key', ''); + $keyToSet = $request->input('keyToSet'); + $key = new Key ($request->input('keyToSet', '')); - if (app('App\Models\Key')->getStatus()) { + if ($key->getStatus()) { # Valid Key $host = $request->header("X_Forwarded_Host", ""); if (empty($host)) { $host = $request->header("Host", ""); } - - $cookie = Cookie::get('key'); - - if(empty($key) && empty($cookie)){ - $key = 'enter_key_here'; - }elseif(empty($key) && !empty($cookie)){ - $key = $cookie; - }elseif(!empty($key)){ - $key = $request->input('key'); - Cookie::queue('key', $key, 0, '/', null, false, false); - } - + Cookie::queue('key', $keyToSet, 0, '/', null, false, false); + $settings = Cookie::get(); + $settings['key'] = $keyToSet; + $cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', $settings)); return view('key') - ->with('title', trans('titles.key')) - ->with('cookie', $key); + ->with('title', trans('titles.key')) + ->with('cookie', $keyToSet) + ->with('cookieLink', $cookieLink); } else { + $cookieLink = LaravelLocalization::getLocalizedURL(LaravelLocalization::getCurrentLocale(), route('loadSettings', Cookie::get())); return view('key') ->with('title', trans('titles.key')) ->with('keyValid', false) - ->with('cookie', 'enter_key_here'); + ->with('cookie', 'enter_key_here') + ->with('cookieLink', $cookieLink); } } diff --git a/resources/views/key.blade.php b/resources/views/key.blade.php index 55fc2e80d371aa9b0ffc2bbcb643cec0ff992a40..eec467c0a73225d9dbf3054474f0059f1f8ec135 100644 --- a/resources/views/key.blade.php +++ b/resources/views/key.blade.php @@ -24,7 +24,7 @@ <li> @lang ('key.li1') <div class="copyLink"> - <input id="loadSettings" class="loadSettings" type="text" value="{{route('loadSettings', ["key" => $cookie])}}"> + <input id="loadSettings" class="loadSettings" type="text" value="{{$cookieLink}}"> <button class="js-only btn btn-default" onclick="var copyText = document.getElementById('loadSettings');copyText.select();copyText.setSelectionRange(0, 99999);document.execCommand('copy');">@lang('settings.copy')</button> </div> </li> @@ -42,7 +42,7 @@ <div id="form-wrapper"> <form method="post"> <input type="hidden" name="redirUrl" value="{{ Request::input('redirUrl', '') }}" /> - <input type="text" name="key" value="{{$cookie === 'enter_key_here' ? '' : $cookie}}" placeholder="@lang('key.placeholder1')" autofocus> + <input type="text" name="keyToSet" value="{{$cookie === 'enter_key_here' ? '' : $cookie}}" placeholder="@lang('key.placeholder1')" autofocus> <button type="submit" class="btn btn-success">OK</button> </form> @if($cookie !== 'enter_key_here')