blessing-skin-server/app/Http/Controllers/HomeController.php

38 lines
909 B
PHP
Raw Normal View History

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;
use App\Models\User;
use Illuminate\Support\Arr;
2016-07-21 22:01:57 +08:00
class HomeController extends Controller
2016-07-21 22:01:57 +08:00
{
public function index()
{
if (isset($_COOKIE['uid']) && isset($_COOKIE['token'])) {
$user = new User($_COOKIE['uid']);
2016-07-27 22:31:49 +08:00
if ($_COOKIE['token'] != $user->getToken() || $user->getPermission() == "-1") {
2016-07-27 22:31:49 +08:00
// delete cookies
setcookie("uid", "", time() - 3600, '/');
2016-07-27 22:31:49 +08:00
setcookie("token", "", time() - 3600, '/');
}
}
$user = Session::has('uid') ? new User(session('uid')) : null;
2016-07-27 22:31:49 +08:00
return view('index')->with('user', $user);
2016-07-21 22:01:57 +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
}