Basic login working.

This commit is contained in:
Markus Birth 2016-05-20 16:30:02 +02:00
parent a25f531292
commit 3792738ba9
3 changed files with 40 additions and 2 deletions

8
README.md Normal file
View File

@ -0,0 +1,8 @@
Fake Reservation System
=======================
Allows you to send mails to your Google Inbox that trigger Google Now cards.
To set up a server for yourself, you have to get an API key from
https://console.developers.google.com/apis/, download the `client_secret.json`
and put it into the root directory.

View File

@ -13,10 +13,32 @@ $data = array();
$client = new Google_Client();
$client->setAuthConfigFile('client_secret.json');
$client->setRedirectUri('https://raspi.mbirth.de/dev/FRS/');
$client->addScope(Google_Service_Oauth2::USERINFO_EMAIL);
$data['auth_url'] = $client->createAuthUrl();
session_start();
if (isset($_GET['code']) && $_GET['code']) {
// OAuth2 result
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: ' . $client->getRedirectUri());
exit(0);
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
// Authenticated
$client->setAccessToken($_SESSION['access_token']);
$data['auth_needed'] = false;
$oauth = new Google_Service_Oauth2($client);
$userdata = $oauth->userinfo->get();
$data['userdata'] = print_r($userdata, true);
} else {
// Not authenticated
$data['auth_needed'] = true;
$data['auth_url'] = $client->createAuthUrl();
}
$tpl = $m->loadTemplate('index_html');
echo $tpl->render($data);

View File

@ -8,9 +8,17 @@
<h3>What is this?</h3>
{{# auth_needed}}
<p>
<a href="{{auth_url}}"><img id="signin-button" src="img/btn_google_signin_dark_normal_web.png"/></a>
</p>
{{/ auth_needed}}
{{# userdata}}
<p>
<pre>{{userdata}}</pre>
</p>
{{/ userdata}}
<p>
Hello, world!