Split templates for logged out and logged in state. Added Logout option.
Added rewriting to allow cleaner URLs.
This commit is contained in:
parent
3792738ba9
commit
a583351ac4
@ -1,3 +1,6 @@
|
|||||||
<Files ~ "\.json$">
|
<Files ~ "\.json$">
|
||||||
Require all denied
|
Require all denied
|
||||||
</Files>
|
</Files>
|
||||||
|
|
||||||
|
RewriteEngine on
|
||||||
|
RewriteRule ^([^.]+)/?$ index.php?action=$1 [L,NC]
|
||||||
|
@ -64,3 +64,8 @@
|
|||||||
display: block;
|
display: block;
|
||||||
background: url(../img/btn_google_signin_dark_focus_web.png);
|
background: url(../img/btn_google_signin_dark_focus_web.png);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mdl-layout a {
|
||||||
|
color: inherit !important;
|
||||||
|
text-decoration: inherit !important;
|
||||||
|
}
|
25
index.php
25
index.php
@ -17,8 +17,22 @@ $client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
|
|||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
|
if (isset($_GET['action']) && $_GET['action'] == 'logout') {
|
||||||
|
// Delete session and redirect to self
|
||||||
|
#$client->setAccessToken($_SESSION['access_token']);
|
||||||
|
#$client->revokeToken(); // removed granted permissions from account
|
||||||
|
$_SESSION = array();
|
||||||
|
if (ini_get('session.use_cookies')) {
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time()-42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||||
|
}
|
||||||
|
session_destroy();
|
||||||
|
header('Location: ' . $client->getRedirectUri());
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($_GET['code']) && $_GET['code']) {
|
if (isset($_GET['code']) && $_GET['code']) {
|
||||||
// OAuth2 result
|
// Validate OAuth2 result, set access token and redirect to self
|
||||||
$client->authenticate($_GET['code']);
|
$client->authenticate($_GET['code']);
|
||||||
$_SESSION['access_token'] = $client->getAccessToken();
|
$_SESSION['access_token'] = $client->getAccessToken();
|
||||||
header('Location: ' . $client->getRedirectUri());
|
header('Location: ' . $client->getRedirectUri());
|
||||||
@ -33,12 +47,19 @@ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
|
|||||||
|
|
||||||
$oauth = new Google_Service_Oauth2($client);
|
$oauth = new Google_Service_Oauth2($client);
|
||||||
$userdata = $oauth->userinfo->get();
|
$userdata = $oauth->userinfo->get();
|
||||||
|
$data['user']['name_first'] = $userdata->givenName;
|
||||||
$data['userdata'] = print_r($userdata, true);
|
$data['userdata'] = print_r($userdata, true);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Check $userdata->verifiedEmail and deny if not verified.
|
||||||
|
|
||||||
|
$tpl = $m->loadTemplate('loggedin_html');
|
||||||
} else {
|
} else {
|
||||||
// Not authenticated
|
// Not authenticated
|
||||||
$data['auth_needed'] = true;
|
$data['auth_needed'] = true;
|
||||||
$data['auth_url'] = $client->createAuthUrl();
|
$data['auth_url'] = $client->createAuthUrl();
|
||||||
|
$tpl = $m->loadTemplate('index_html');
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = $m->loadTemplate('index_html');
|
$data['action'] = $_GET['action'];
|
||||||
echo $tpl->render($data);
|
echo $tpl->render($data);
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
{{/ userdata}}
|
{{/ userdata}}
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Hello, world!
|
Hello, world! ({{action}})
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Hello, world!
|
Hello, world!
|
||||||
@ -215,5 +215,5 @@
|
|||||||
|
|
||||||
{{> mdl_content_foot}}
|
{{> mdl_content_foot}}
|
||||||
{{> mdl_foot}}
|
{{> mdl_foot}}
|
||||||
<a href="https://github.com/google/material-design-lite/blob/master/templates/article/" target="_blank" id="view-source" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-color--accent mdl-color-text--accent-contrast">View Source</a>
|
<a href="https://github.com/mbirth/php-frs/" target="_blank" id="view-source" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-color--accent mdl-color-text--accent-contrast">View Source</a>
|
||||||
{{> html_foot}}
|
{{> html_foot}}
|
||||||
|
23
templates/loggedin_html.mustache
Normal file
23
templates/loggedin_html.mustache
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{{> html_head}}
|
||||||
|
{{> mdl_head}}
|
||||||
|
{{> mdl_content_head}}
|
||||||
|
|
||||||
|
<div class="frs-crumbs mdl-color-text--grey-500">
|
||||||
|
Not Google > Not Google Now > Fake Reservation System
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3>What is this?</h3>
|
||||||
|
|
||||||
|
{{# userdata}}
|
||||||
|
<p>
|
||||||
|
<pre>{{userdata}}</pre>
|
||||||
|
</p>
|
||||||
|
{{/ userdata}}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Welcome, to the <strong>Fake Reservation System</strong>. Where you can book travels you'll never attend.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{> mdl_content_foot}}
|
||||||
|
{{> mdl_foot}}
|
||||||
|
{{> html_foot}}
|
@ -2,6 +2,19 @@
|
|||||||
<header class="frs-header mdl-layout__header mdl-layout__header--scroll mdl-color--grey-100 mdl-color-text--grey-800">
|
<header class="frs-header mdl-layout__header mdl-layout__header--scroll mdl-color--grey-100 mdl-color-text--grey-800">
|
||||||
<div class="mdl-layout__header-row">
|
<div class="mdl-layout__header-row">
|
||||||
<span class="mdl-layout-title">Fake Reservation System</span>
|
<span class="mdl-layout-title">Fake Reservation System</span>
|
||||||
|
<div class="mdl-layout-spacer"></div>
|
||||||
|
<!-- Navigation -->
|
||||||
|
<nav class="mdl-navigation">
|
||||||
|
{{# user.name_first}}
|
||||||
|
<span class="mdl-navigation__link mdl-color-text--grey-800">Hello, {{user.name_first}}!</span>
|
||||||
|
{{/ user.name_first}}
|
||||||
|
<button id="frs-menu-top" class="mdl-button mdl-js-button mdl-button--icon">
|
||||||
|
<span class="material-icons">more_vert</span>
|
||||||
|
</button>
|
||||||
|
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="frs-menu-top">
|
||||||
|
<li id="frs-menuitem-logout" class="mdl-menu__item" onclick="location.href='?action=logout';">Logout</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<div class="frs-ribbon"></div>
|
<div class="frs-ribbon"></div>
|
||||||
|
Reference in New Issue
Block a user