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
|
|
|
|
|
|
|
use App\Models\User;
|
2016-08-28 10:05:21 +08:00
|
|
|
use Session;
|
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
|
|
|
|
|
|
|
if ($_COOKIE['token'] == $user->getToken() && $user->getPermission() != "-1") {
|
2016-08-28 10:05:21 +08:00
|
|
|
Session::put('uid' , $_COOKIE['uid']);
|
|
|
|
Session::put('token', $_COOKIE['token']);
|
2016-07-27 22:31:49 +08:00
|
|
|
} else {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
}
|