Skip to content

Instantly share code, notes, and snippets.

@alpacaaa
Created March 13, 2011 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alpacaaa/868021 to your computer and use it in GitHub Desktop.
Save alpacaaa/868021 to your computer and use it in GitHub Desktop.
<?php
// put inside extensions/members_openid
class Extension_Members_Openid extends Extension{
public function about(){
return array('name' => 'Members with OpenID',
'version' => '0.1',
'release-date' => '2011-03-13',
'author' => array('name' => 'Marco Sampellegrini',
'email' => 'm@rcosa.mp')
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/frontend/',
'delegate' => 'openidAuthComplete',
'callback' => 'authenticationComplete'
)
);
}
public function authenticationComplete($context)
{
if (!class_exists('extension_Members')) return;
$openid_data = $context['openid-data'];
$email = $openid_data->sreg_data['email'];
$em = new ExtensionManager(Frontend::instance());
$ex = $em->create('members');
$id = extension_Members::findMemberIDFromEmail($email);
if (is_array($id))
$id = current($id);
$entry = $ex->fetchMemberFromID($id);
if (!($entry instanceof Entry))
return; // no member with that mail
$field = extension_Members::usernameAndPasswordField();
$credentials = $entry->getData($field);
if (!$credentials) return;
$ex->login($credentials['username'], $credentials['password'], $isHash = true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment