enhance performance at homepage

This commit is contained in:
printempw 2016-07-27 22:31:49 +08:00
parent acfc7c4478
commit e3dccf23d6

View File

@ -9,7 +9,22 @@ class HomeController extends BaseController
public function index()
{
echo \View::make('index')->with('user', (isset($_SESSION['email']) ? new User($_SESSION['email']) : null));
if (isset($_COOKIE['email']) && isset($_COOKIE['token'])) {
$user = new User($_COOKIE['email']);
if ($_COOKIE['token'] == $user->getToken() && $user->getPermission() != "-1") {
$_SESSION['email'] = $_COOKIE['email'];
$_SESSION['token'] = $_COOKIE['token'];
} else {
// delete cookies
setcookie("email", "", time() - 3600, '/');
setcookie("token", "", time() - 3600, '/');
}
}
$user = isset($_SESSION['email']) ? new User($_SESSION['email']) : null;
echo \View::make('index')->with('user', $user);
}
}