2013-08-12 09:49:28 +02:00
|
|
|
<?php #
|
2012-03-24 15:59:25 +01:00
|
|
|
|
|
|
|
// Probe for a language include with constants. Still include defines later on, if some constants were missing
|
|
|
|
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
|
|
|
|
if (file_exists($probelang)) {
|
|
|
|
include $probelang;
|
|
|
|
}
|
|
|
|
include_once dirname(__FILE__) . '/lang_en.inc.php';
|
|
|
|
|
|
|
|
class serendipity_event_browserid extends serendipity_event
|
|
|
|
{
|
|
|
|
function introspect(&$propbag)
|
|
|
|
{
|
|
|
|
global $serendipity;
|
|
|
|
|
|
|
|
$propbag->add('name', PLUGIN_BROWSERID_NAME);
|
|
|
|
$propbag->add('description', PLUGIN_BROWSERID_DESC);
|
|
|
|
$propbag->add('stackable', false);
|
2017-02-22 18:33:36 +01:00
|
|
|
$propbag->add('author', 'Grischa Brockhaus, Malte Paskuda');
|
|
|
|
$propbag->add('version', '2.0');
|
2012-03-24 15:59:25 +01:00
|
|
|
$propbag->add('requirements', array(
|
2017-02-22 18:33:36 +01:00
|
|
|
'serendipity' => '2.0',
|
|
|
|
'php' => '7.0'
|
2012-03-24 15:59:25 +01:00
|
|
|
));
|
|
|
|
$propbag->add('groups', array('BACKEND_USERMANAGEMENT'));
|
|
|
|
$propbag->add('event_hooks', array(
|
|
|
|
'backend_login' => true,
|
|
|
|
'backend_login_page' => true,
|
2012-03-24 18:24:45 +01:00
|
|
|
'external_plugin' => true,
|
2012-03-24 15:59:25 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$propbag->add('configuration', array(
|
|
|
|
'plugin_desc',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function introspect_config_item($name, &$propbag)
|
|
|
|
{
|
|
|
|
switch($name) {
|
|
|
|
case 'plugin_desc':
|
|
|
|
$propbag->add('type', 'content');
|
|
|
|
$propbag->add('default', PLUGIN_BROWSERID_DESCRIPTION);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate_content(&$title) {
|
2012-03-25 13:59:23 +02:00
|
|
|
$title = PLUGIN_BROWSERID_NAME;
|
2012-03-24 15:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function event_hook($event, &$bag, &$eventData, $addData = null) {
|
|
|
|
global $serendipity;
|
|
|
|
|
2017-02-22 18:33:36 +01:00
|
|
|
require __DIR__ . '/vendor/autoload.php';
|
|
|
|
require_once 'S9yStore.php';
|
|
|
|
$verify_url = $serendipity['baseURL'] . 'index.php?/plugin/serendipity_event_browserid_verify';
|
|
|
|
|
|
|
|
$this->portier = new \Portier\Client\Client(
|
|
|
|
new \Portier\Client\S9yStore($this),
|
|
|
|
$verify_url
|
|
|
|
);
|
2012-03-24 15:59:25 +01:00
|
|
|
|
|
|
|
$hooks = &$bag->get('event_hooks');
|
|
|
|
|
|
|
|
if (isset($hooks[$event])) {
|
|
|
|
switch($event) {
|
|
|
|
case 'external_plugin':
|
2017-02-22 18:33:36 +01:00
|
|
|
if ($eventData=="serendipity_event_browserid_auth") {
|
|
|
|
$this->auth($serendipity['POST']['persona_email']);
|
2012-03-24 15:59:25 +01:00
|
|
|
}
|
2012-03-24 18:24:45 +01:00
|
|
|
else if ($eventData=="serendipity_event_browserid_verify") {
|
2017-02-22 18:33:36 +01:00
|
|
|
$this->verify($_POST['id_token']);
|
2012-03-24 18:24:45 +01:00
|
|
|
}
|
2012-03-24 15:59:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'backend_login_page':
|
|
|
|
$this->print_loginpage($eventData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'backend_login':
|
|
|
|
if ($eventData) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-25 14:34:38 +02:00
|
|
|
if ($_SESSION['serendipityAuthedUser'] == true) {
|
|
|
|
$eventData = $this->reauth();
|
|
|
|
}
|
|
|
|
|
2012-03-24 15:59:25 +01:00
|
|
|
return;
|
2012-03-24 18:24:45 +01:00
|
|
|
|
2012-03-24 15:59:25 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 18:24:45 +01:00
|
|
|
|
2017-02-22 18:33:36 +01:00
|
|
|
function verify($idToken) {
|
2012-03-24 18:24:45 +01:00
|
|
|
global $serendipity;
|
2017-02-22 18:33:36 +01:00
|
|
|
$email = $this->portier->verify($idToken);
|
|
|
|
$this->login_user($email);
|
|
|
|
header("Location: ${_SESSION['serendipity_event_browserid_loginurl']}", true, 303);
|
2012-03-24 18:24:45 +01:00
|
|
|
}
|
2017-02-22 18:33:36 +01:00
|
|
|
|
|
|
|
function auth($email) {
|
|
|
|
global $serendipity;
|
|
|
|
$authUrl = $this->portier->authenticate($email);
|
|
|
|
header("Location: $authUrl", true, 303);
|
2012-03-25 14:34:38 +02:00
|
|
|
}
|
2017-02-22 18:33:36 +01:00
|
|
|
|
|
|
|
function login_user($email) {
|
|
|
|
global $serendipity;
|
|
|
|
$query = "SELECT DISTINCT a.email, a.authorid, a.userlevel, a.right_publish, a.realname
|
|
|
|
FROM
|
|
|
|
{$serendipity['dbPrefix']}authors AS a
|
|
|
|
WHERE
|
|
|
|
a.email = '{$email}'";
|
|
|
|
$row = serendipity_db_query($query, true, 'assoc');
|
|
|
|
if (is_array($row)) {
|
|
|
|
serendipity_setCookie('old_session', session_id());
|
|
|
|
serendipity_setAuthorToken();
|
|
|
|
$_SESSION['serendipityUser'] = $serendipity['serendipityUser'] = $row['realname'];
|
|
|
|
$_SESSION['serendipityPassword'] = $serendipity['serendipityPassword'] = serendipity_hash($email);
|
|
|
|
$_SESSION['serendipityEmail'] = $serendipity['serendipityEmail'] = $email;
|
|
|
|
$_SESSION['serendipityAuthorid'] = $serendipity['authorid'] = $row['authorid'];
|
|
|
|
$_SESSION['serendipityUserlevel'] = $serendipity['serendipityUserlevel'] = $row['userlevel'];
|
|
|
|
$_SESSION['serendipityAuthedUser'] = $serendipity['serendipityAuthedUser'] = true;
|
|
|
|
$_SESSION['serendipityRightPublish']= $serendipity['serendipityRightPublish'] = $row['right_publish'];
|
|
|
|
serendipity_load_configuration($serendipity['authorid']);
|
|
|
|
} else { // No user found for that email!
|
|
|
|
echo "found no such user";
|
|
|
|
$response->status = 's9yunknown';
|
|
|
|
$response->message= "Sorry, we don't have a user for $email";
|
|
|
|
$_SESSION['serendipityAuthedUser'] = false;
|
|
|
|
@session_destroy();
|
|
|
|
}
|
2012-03-25 14:34:38 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 18:33:36 +01:00
|
|
|
function reauth() {
|
|
|
|
global $serendipity;
|
|
|
|
// Reauth only, if valid session
|
|
|
|
if ($_SESSION['serendipityAuthedUser']) {
|
|
|
|
$serendipity['serendipityUser'] = $_SESSION['serendipityUser'];
|
|
|
|
$serendipity['serendipityPassword'] = $_SESSION['serendipityPassword'];
|
|
|
|
$serendipity['serendipityEmail'] = $_SESSION['serendipityEmail'];
|
|
|
|
$serendipity['authorid'] = $_SESSION['serendipityAuthorid'];
|
|
|
|
$serendipity['serendipityUserlevel'] = $_SESSION['serendipityUserlevel'];
|
|
|
|
$serendipity['serendipityAuthedUser'] = $_SESSION['serendipityAuthedUser'];
|
|
|
|
$serendipity['serendipityRightPublish'] = $_SESSION['serendipityRightPublish'];
|
|
|
|
serendipity_load_configuration($serendipity['authorid']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-03-24 18:24:45 +01:00
|
|
|
}
|
|
|
|
|
2012-03-24 15:59:25 +01:00
|
|
|
function print_loginpage(&$eventData) {
|
|
|
|
global $serendipity;
|
|
|
|
|
2017-02-22 18:33:36 +01:00
|
|
|
$_SESSION['serendipity_event_browserid_loginurl'] = $_SERVER['REDIRECT_SCRIPT_URI'] . '?' . $_SERVER['QUERY_STRING'];
|
|
|
|
$auth_url = $serendipity['baseURL'] . 'index.php?/plugin/serendipity_event_browserid_auth';
|
2012-03-24 18:24:45 +01:00
|
|
|
|
2017-02-22 18:33:36 +01:00
|
|
|
echo '<form method="post" action="' . $auth_url . '" style="margin: auto; max-width: 23em; border: 1px solid #aaa; margin-top: 4em; padding: 1em;">
|
|
|
|
<fieldset>
|
|
|
|
<span class="wrap_legend"><legend>Please enter your email</legend></span>
|
|
|
|
<input name="serendipity[persona_email]" type="email">
|
|
|
|
<button type="submit">Login</button>
|
|
|
|
</fieldset>
|
|
|
|
</form>';
|
2012-03-24 18:24:45 +01:00
|
|
|
}
|
2017-02-22 18:33:36 +01:00
|
|
|
|
2012-03-24 15:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set sts=4 ts=4 expandtab : */
|