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

32 lines
804 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
use App\Models\User;
2016-08-28 10:05:21 +08:00
use Session;
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-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
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
}
}