1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 03:40:37 +02:00

Work on #34, extensive testing is required. Work in progress.

This commit is contained in:
SecretR
2012-12-20 10:45:22 +02:00
parent cfb76a758a
commit e89a6a5ecf
6 changed files with 61 additions and 39 deletions

View File

@@ -29,58 +29,53 @@ class core_system_xup_controller extends eController
public function actionSignup() public function actionSignup()
{ {
// echo 'Signup controller'; $allow = true;
//$back = 'system/xup/test'; $session = e107::getSession();
if($session->get('HAuthError'))
{
$allow = false;
}
// FIXME - pref for default XUP - e.g. Facebook, use it when GET is empty if($allow && vartrue($_GET['provider']))
if(vartrue($_GET['provider']))
{ {
require_once(e_HANDLER."user_handler.php"); require_once(e_HANDLER."user_handler.php");
$provider = new e_user_provider($_GET['provider']); $provider = new e_user_provider($_GET['provider']);
//$provider->setBackUrl(e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)));
try try
{ {
$provider->signup($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL $provider->signup($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL
} }
catch (Exception $e) catch (Exception $e)
{ {
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage()); e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
// print_a($provider->getUserProfile());
// echo '<br /><br /><a href="'.e107::getUrl()->create($this->backUrl).'">Test page</a>';
return;
} }
// print_a($provider->getUserProfile());
//return;
} }
e107::getRedirect()->redirect(e107::getUrl()->create($this->backUrl)); e107::getRedirect()->redirect(true === $this->backUrl ? SITEURL : e107::getUrl()->create($this->backUrl));
} }
public function actionLogin() public function actionLogin()
{ {
//echo 'Login controller'; $allow = true;
$session = e107::getSession();
if($session->get('HAuthError'))
{
$allow = false;
}
// FIXME - pref for default XUP - e.g. Facebook, use it when GET is empty
if(vartrue($_GET['provider'])) if(vartrue($_GET['provider']))
{ {
require_once(e_HANDLER."user_handler.php"); require_once(e_HANDLER."user_handler.php");
$provider = new e_user_provider($_GET['provider']); $provider = new e_user_provider($_GET['provider']);
//$provider->setBackUrl(e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)));
try try
{ {
$provider->login($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL $provider->login($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL
} }
catch (Exception $e) catch (Exception $e)
{ {
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage()); e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
// print_a($provider->getUserProfile());
// echo '<br /><br /><a href="'.e107::getUrl()->create($this->backUrl).'">Test page</a>';
return;
} }
// print_a($provider->getUserProfile());
//return;
} }
e107::getRedirect()->redirect(e107::getUrl()->create($this->backUrl)); e107::getRedirect()->redirect(true === $this->backUrl ? SITEURL : e107::getUrl()->create($this->backUrl));
} }
public function actionTest() public function actionTest()
@@ -112,7 +107,9 @@ class core_system_xup_controller extends eController
} }
catch (Exception $e) catch (Exception $e)
{ {
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage()); e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
$session = e107::getSession();
$session->set('HAuthError', true);
} }
//echo 'End point'; //echo 'End point';
} }

View File

@@ -25,6 +25,7 @@ class core_system_rewrite_url extends eUrlConfig
'rules' => array( 'rules' => array(
'error404' => 'error/notfound', 'error404' => 'error/notfound',
'hello' => 'error/hello-world', 'hello' => 'error/hello-world',
'<controller>/<action>' => '<controller>/<action>',
) )
); );
} }

View File

@@ -1311,12 +1311,17 @@ class e107
* *
* @return Hybrid_Auth * @return Hybrid_Auth
*/ */
public static function getHybridAuth() public static function getHybridAuth($config = null)
{ {
$config = array( if(null === $config)
'base_url' => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)), {
'providers' => e107::getPref('social_login', array()) $config = array(
); 'base_url' => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
'providers' => e107::getPref('social_login', array()),
'debug_mode' => false,
'debug_file' => ''
);
}
return new Hybrid_Auth($config); return new Hybrid_Auth($config);
} }

View File

@@ -853,7 +853,6 @@ class e_user_provider
if(!empty($config)) if(!empty($config))
{ {
$this->_config = $config; $this->_config = $config;
$this->hybridauth = new Hybrid_Auth($this->_config);
} }
else else
{ {
@@ -861,16 +860,29 @@ class e_user_provider
"base_url" => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)), "base_url" => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
"providers" => e107::getPref('social_login', array()) "providers" => e107::getPref('social_login', array())
); );
$this->hybridauth = e107::getHybridAuth();
} }
$this->hybridauth = e107::getHybridAuth($this->_config);
$this->setProvider($provider); $this->setProvider($provider);
//require_once(e_HANDLER."hybridauth/Hybrid/Auth.php"); //require_once(e_HANDLER."hybridauth/Hybrid/Auth.php");
} }
public function setProvider($provider) public function setProvider($provider)
{ {
$this->_provider = $provider && isset($this->_config['providers'][$provider]) ? $provider : null; $provider = ucfirst(strtolower($provider));
if(isset($this->_config['providers'][$provider]) && $this->_config['providers'][$provider]['enabled'])
{
if($this->_config['providers'][$provider]['enabled'] && vartrue($this->_config['providers'][$provider]['keys']))
{
$valid = true;
foreach ($this->_config['providers'][$provider]['keys'] as $_key => $_value)
{
if(empty($_value)) $valid = false;
}
if($valid) $this->_provider = $provider;
}
}
} }
public function setBackUrl($url) public function setBackUrl($url)

View File

@@ -1491,11 +1491,19 @@ class e_user extends e_user_model
// don't allow if main admin browse front-end or there is already user session // don't allow if main admin browse front-end or there is already user session
if((!$deniedAs && $this->getSessionDataAs()) || null !== $this->_session_data || !e107::getPref('social_login_active', false)) return $this; if((!$deniedAs && $this->getSessionDataAs()) || null !== $this->_session_data || !e107::getPref('social_login_active', false)) return $this;
// detect all currently connected providers try
$hybrid = e107::getHybridAuth(); // init the auth class {
// detect all currently connected providers
$connected = Hybrid_Auth::getConnectedProviders(); $hybrid = e107::getHybridAuth(); // init the auth class
$connected = Hybrid_Auth::getConnectedProviders();
}
catch(Exception $e)
{
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
$session = e107::getSession();
$session->set('HAuthError', true);
$connected = false;
}
// no active session found // no active session found
if(!$connected) return $this; if(!$connected) return $this;

View File

@@ -714,9 +714,8 @@ if ($qs == 'stage1' && $pref['use_coppa'] == 1)
require_once(e_HANDLER."form_handler.php"); require_once(e_HANDLER."form_handler.php");
$rs = new form; $rs = new form;
$text = $tp->parseTemplate($SIGNUP_BEGIN.$SIGNUP_BODY.$SIGNUP_END, TRUE, $signup_shortcodes); $text = $tp->parseTemplate($SIGNUP_BEGIN.$SIGNUP_BODY.$SIGNUP_END, TRUE, $signup_shortcodes);
$ns->tablerender(LAN_SIGNUP_79, $text); $ns->tablerender(LAN_SIGNUP_79, e107::getMessage()->render('default', true).$text);
require_once(FOOTERF); require_once(FOOTERF);
exit; exit;