mirror of
https://github.com/e107inc/e107.git
synced 2025-07-29 19:00:26 +02:00
Work on #34, extensive testing is required. Work in progress.
This commit is contained in:
@@ -29,58 +29,53 @@ class core_system_xup_controller extends eController
|
||||
|
||||
public function actionSignup()
|
||||
{
|
||||
// echo 'Signup controller';
|
||||
//$back = 'system/xup/test';
|
||||
$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($allow && vartrue($_GET['provider']))
|
||||
{
|
||||
require_once(e_HANDLER."user_handler.php");
|
||||
$provider = new e_user_provider($_GET['provider']);
|
||||
//$provider->setBackUrl(e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)));
|
||||
try
|
||||
{
|
||||
$provider->signup($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage());
|
||||
// print_a($provider->getUserProfile());
|
||||
// echo '<br /><br /><a href="'.e107::getUrl()->create($this->backUrl).'">Test page</a>';
|
||||
return;
|
||||
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
|
||||
}
|
||||
// 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()
|
||||
{
|
||||
//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']))
|
||||
{
|
||||
require_once(e_HANDLER."user_handler.php");
|
||||
$provider = new e_user_provider($_GET['provider']);
|
||||
//$provider->setBackUrl(e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)));
|
||||
try
|
||||
{
|
||||
$provider->login($this->backUrl); // redirect to test page is expected, if true - redirect to SITEURL
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage());
|
||||
// print_a($provider->getUserProfile());
|
||||
// echo '<br /><br /><a href="'.e107::getUrl()->create($this->backUrl).'">Test page</a>';
|
||||
return;
|
||||
e107::getMessage()->addError('['.$e->getCode().']'.$e->getMessage(), 'default', true);
|
||||
}
|
||||
// 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()
|
||||
@@ -112,7 +107,9 @@ class core_system_xup_controller extends eController
|
||||
}
|
||||
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';
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ class core_system_rewrite_url extends eUrlConfig
|
||||
'rules' => array(
|
||||
'error404' => 'error/notfound',
|
||||
'hello' => 'error/hello-world',
|
||||
'<controller>/<action>' => '<controller>/<action>',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@@ -1311,12 +1311,17 @@ class e107
|
||||
*
|
||||
* @return Hybrid_Auth
|
||||
*/
|
||||
public static function getHybridAuth()
|
||||
public static function getHybridAuth($config = null)
|
||||
{
|
||||
$config = array(
|
||||
'base_url' => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
|
||||
'providers' => e107::getPref('social_login', array())
|
||||
);
|
||||
if(null === $config)
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@@ -853,7 +853,6 @@ class e_user_provider
|
||||
if(!empty($config))
|
||||
{
|
||||
$this->_config = $config;
|
||||
$this->hybridauth = new Hybrid_Auth($this->_config);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -861,16 +860,29 @@ class e_user_provider
|
||||
"base_url" => e107::getUrl()->create('system/xup/endpoint', array(), array('full' => true)),
|
||||
"providers" => e107::getPref('social_login', array())
|
||||
);
|
||||
$this->hybridauth = e107::getHybridAuth();
|
||||
|
||||
}
|
||||
|
||||
$this->hybridauth = e107::getHybridAuth($this->_config);
|
||||
$this->setProvider($provider);
|
||||
//require_once(e_HANDLER."hybridauth/Hybrid/Auth.php");
|
||||
}
|
||||
|
||||
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)
|
||||
|
@@ -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
|
||||
if((!$deniedAs && $this->getSessionDataAs()) || null !== $this->_session_data || !e107::getPref('social_login_active', false)) return $this;
|
||||
|
||||
// detect all currently connected providers
|
||||
$hybrid = e107::getHybridAuth(); // init the auth class
|
||||
|
||||
$connected = Hybrid_Auth::getConnectedProviders();
|
||||
|
||||
try
|
||||
{
|
||||
// detect all currently connected providers
|
||||
$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
|
||||
if(!$connected) return $this;
|
||||
|
||||
|
@@ -714,9 +714,8 @@ if ($qs == 'stage1' && $pref['use_coppa'] == 1)
|
||||
require_once(e_HANDLER."form_handler.php");
|
||||
$rs = new form;
|
||||
|
||||
|
||||
$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);
|
||||
exit;
|
||||
|
||||
|
Reference in New Issue
Block a user