2016-07-21 22:01:57 +08:00
|
|
|
<?php
|
|
|
|
|
2016-08-28 10:05:21 +08:00
|
|
|
namespace App\Http\Controllers;
|
2016-07-21 22:01:57 +08:00
|
|
|
|
2016-08-28 10:05:21 +08:00
|
|
|
use Session;
|
2016-09-24 22:45:54 +08:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Support\Arr;
|
2016-07-21 22:01:57 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
class HomeController extends Controller
|
2016-07-21 22:01:57 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
2016-08-16 22:52:00 +08:00
|
|
|
if (isset($_COOKIE['uid']) && isset($_COOKIE['token'])) {
|
|
|
|
$user = new User($_COOKIE['uid']);
|
2016-07-27 22:31:49 +08:00
|
|
|
|
2016-09-24 22:45:54 +08:00
|
|
|
if ($_COOKIE['token'] != $user->getToken() || $user->getPermission() == "-1") {
|
2016-07-27 22:31:49 +08:00
|
|
|
// delete cookies
|
2016-08-16 22:52:00 +08:00
|
|
|
setcookie("uid", "", time() - 3600, '/');
|
2016-07-27 22:31:49 +08:00
|
|
|
setcookie("token", "", time() - 3600, '/');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
$user = Session::has('uid') ? new User(session('uid')) : null;
|
2016-07-27 22:31:49 +08:00
|
|
|
|
2016-09-04 15:35:12 +08:00
|
|
|
return view('index')->with('user', $user);
|
2016-07-21 22:01:57 +08:00
|
|
|
}
|
|
|
|
|
2016-09-24 22:45:54 +08:00
|
|
|
public function locale($lang)
|
|
|
|
{
|
|
|
|
if (Arr::exists(config('locales'), $lang)) {
|
|
|
|
Session::set('locale', $lang);
|
|
|
|
}
|
|
|
|
return redirect('/')->withCookie('locale', $lang);
|
|
|
|
}
|
|
|
|
|
2016-07-21 22:01:57 +08:00
|
|
|
}
|