Prepare expired session handling. Added stubs for event and hotel.
This commit is contained in:
parent
944ad8ff37
commit
33ba665a0c
@ -87,3 +87,9 @@
|
|||||||
background-color: rgb(238, 238, 238);
|
background-color: rgb(238, 238, 238);
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h3 .material-icons {
|
||||||
|
color: rgb(117, 117, 117);
|
||||||
|
font-size: 0.9em;
|
||||||
|
vertical-align: -0.15em;
|
||||||
|
}
|
||||||
|
41
index.php
41
index.php
@ -53,29 +53,25 @@ if (isset($_GET['action'])) {
|
|||||||
|
|
||||||
if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token']) {
|
if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token']) {
|
||||||
// Authenticated
|
// Authenticated
|
||||||
try {
|
|
||||||
$created = $_SESSION['access_token']['created'];
|
$created = $_SESSION['access_token']['created'];
|
||||||
$expires = $_SESSION['access_token']['expires_in'];
|
$expires = $_SESSION['access_token']['expires_in'];
|
||||||
$expire_stamp = intval($created) + intval($expires);
|
$expire_stamp = intval($created) + intval($expires);
|
||||||
$data['session_created'] = $created;
|
$data['session_created'] = $created;
|
||||||
$data['session_expires'] = $expires;
|
$data['session_expires'] = $expires;
|
||||||
$data['session_time_left'] = ($expire_stamp) - time();
|
$data['session_time_left'] = ($expire_stamp) - time();
|
||||||
|
|
||||||
$client->setAccessToken($_SESSION['access_token']);
|
$client->setAccessToken($_SESSION['access_token']);
|
||||||
} catch (Exception $e) {
|
if ($client->isAccessTokenExpired()) {
|
||||||
print_r($e);
|
// TODO: Save everything in session
|
||||||
$_SESSION['access_token'] = $client->refreshToken(null);
|
// TODO: Redirect to $client->createAuthUrl(); to reauthenticate
|
||||||
print_r($_SESSION['access_token']);
|
echo "Token expired!";
|
||||||
}
|
session_destroy();
|
||||||
|
|
||||||
$data['auth_needed'] = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$oauth = new Google_Service_Oauth2($client);
|
|
||||||
$userdata = $oauth->userinfo->get();
|
|
||||||
} catch (Exception $e) {
|
|
||||||
print_r($e);
|
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$oauth = new Google_Service_Oauth2($client);
|
||||||
|
$userdata = $oauth->userinfo->get();
|
||||||
|
|
||||||
$data['user'] = array(
|
$data['user'] = array(
|
||||||
'name_first' => $userdata->givenName,
|
'name_first' => $userdata->givenName,
|
||||||
'name_last' => $userdata->familyName,
|
'name_last' => $userdata->familyName,
|
||||||
@ -85,15 +81,22 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
|||||||
'gender' => $userdata->gender,
|
'gender' => $userdata->gender,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$data['date_today'] = date('Y-m-d');
|
||||||
|
|
||||||
|
|
||||||
// Check $userdata->verifiedEmail and deny if not verified.
|
// Check $userdata->verifiedEmail and deny if not verified.
|
||||||
if (!$userdata->verifiedEmail) {
|
if (!$userdata->verifiedEmail) {
|
||||||
$tpl = $m->loadTemplate('notverified_html');
|
$tpl = $m->loadTemplate('notverified_html');
|
||||||
$tpl_done = true;
|
$tpl_done = true;
|
||||||
}
|
} else {
|
||||||
|
|
||||||
switch ($_GET['action']) {
|
switch ($_GET['action']) {
|
||||||
case 'faq':
|
case 'event':
|
||||||
$tpl = $m->loadTemplate('faq_html');
|
$tpl = $m->loadTemplate('event_html');
|
||||||
|
$tpl_done = true;
|
||||||
|
break;
|
||||||
|
case 'hotel':
|
||||||
|
$tpl = $m->loadTemplate('hotel_html');
|
||||||
|
$tpl_done = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!$tpl_done) {
|
if (!$tpl_done) {
|
||||||
@ -102,9 +105,9 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} elseif (!$tpl_done) {
|
} elseif (!$tpl_done) {
|
||||||
// Not authenticated
|
// Not authenticated
|
||||||
$data['auth_needed'] = true;
|
|
||||||
$data['auth_url'] = $client->createAuthUrl();
|
$data['auth_url'] = $client->createAuthUrl();
|
||||||
$tpl = $m->loadTemplate('index_html');
|
$tpl = $m->loadTemplate('index_html');
|
||||||
}
|
}
|
||||||
|
30
templates/event_html.mustache
Normal file
30
templates/event_html.mustache
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{{> html_head}}
|
||||||
|
{{> mdl_head}}
|
||||||
|
{{> mdl_content_head}}
|
||||||
|
|
||||||
|
<div class="frs-crumbs mdl-color-text--grey-500">
|
||||||
|
<a href="./">Fake Reservation System</a> > Create Event
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3><i class="material-icons">event</i> Event Reservation</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form action="#">
|
||||||
|
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||||
|
<input class="mdl-textfield__input" type="text" id="reservationFor_name">
|
||||||
|
<label class="mdl-textfield__label" for="reservationFor_name">Name</label>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!-- Numeric Textfield with Floating Label -->
|
||||||
|
<form action="#">
|
||||||
|
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||||
|
<input class="mdl-textfield__input" type="datetime-local" min="{{date_today}}" id="reservationFor_startDate">
|
||||||
|
<label class="mdl-textfield__label" for="reservationFor_startDate">Start Date</label>
|
||||||
|
<span class="mdl-textfield__error">Input is not a date!</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{> mdl_content_foot}}
|
||||||
|
{{> mdl_foot}}
|
||||||
|
{{> html_foot}}
|
30
templates/hotel_html.mustache
Normal file
30
templates/hotel_html.mustache
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
{{> html_head}}
|
||||||
|
{{> mdl_head}}
|
||||||
|
{{> mdl_content_head}}
|
||||||
|
|
||||||
|
<div class="frs-crumbs mdl-color-text--grey-500">
|
||||||
|
<a href="./">Fake Reservation System</a> > Create Hotel Reservation
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3><i class="material-icons">hotel</i> Hotel Reservation</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<form action="#">
|
||||||
|
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||||
|
<input class="mdl-textfield__input" type="text" id="reservationFor_name">
|
||||||
|
<label class="mdl-textfield__label" for="reservationFor_name">Name</label>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<!-- Numeric Textfield with Floating Label -->
|
||||||
|
<form action="#">
|
||||||
|
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
|
||||||
|
<input class="mdl-textfield__input" type="datetime-local" min="{{date_today}}" id="reservationFor_startDate">
|
||||||
|
<label class="mdl-textfield__label" for="reservationFor_startDate">Start Date</label>
|
||||||
|
<span class="mdl-textfield__error">Input is not a date!</span>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{{> mdl_content_foot}}
|
||||||
|
{{> mdl_foot}}
|
||||||
|
{{> html_foot}}
|
Reference in New Issue
Block a user