mirror of
https://github.com/e107inc/e107.git
synced 2025-07-30 19:30:25 +02:00
social: Fix broken update profile on login feature
This commit is contained in:
@@ -1720,110 +1720,6 @@ class e_user extends e_user_model
|
||||
$this->_destroyAsSession();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function tryProviderSession($deniedAs)
|
||||
{
|
||||
// don't allow if main admin browse front-end or there is already user session
|
||||
if((!$deniedAs && $this->getSessionDataAs()) || null !== $this->_session_data || !e107::getUserProvider()->isSocialLoginEnabled()) return $this;
|
||||
|
||||
$hybrid = e107::getHybridAuth(); // init the auth class
|
||||
|
||||
try
|
||||
{
|
||||
// detect all currently connected providers
|
||||
$connected = $hybrid->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;
|
||||
|
||||
// query DB
|
||||
$sql = e107::getDb();
|
||||
$where = array();
|
||||
$userdata = array();
|
||||
|
||||
foreach ($connected as $providerId)
|
||||
{
|
||||
$adapter = $hybrid->getAdapter($providerId);
|
||||
|
||||
try
|
||||
{
|
||||
$profile = $adapter->getUserProfile();
|
||||
}
|
||||
catch (\Hybridauth\Exception\Exception $e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$profile->identifier) continue;
|
||||
|
||||
$userdata['user_name'] = $sql->escape($profile->displayName);
|
||||
$userdata['user_image'] = $profile->photoURL; // avatar
|
||||
$userdata['user_email'] = $profile->email;
|
||||
|
||||
$id = $providerId.'_'.$profile->identifier;
|
||||
$where[] = "user_xup='".$sql->escape($id)."'";
|
||||
}
|
||||
// no active session found
|
||||
if(empty($where)) return $this;
|
||||
|
||||
$where = implode(' OR ', $where);
|
||||
if($sql->select('user', 'user_id, user_name, user_email, user_image, user_password, user_xup', $where))
|
||||
{
|
||||
|
||||
$user = $sql->fetch();
|
||||
e107::getUserSession()->makeUserCookie($user);
|
||||
$this->setSessionData();
|
||||
|
||||
$spref = e107::pref('social');
|
||||
|
||||
// Update display name or avatar image if they have changed.
|
||||
if(( empty($user['user_email']) && !empty($userdata['user_email']) ) || !empty($spref['xup_login_update_username']) || !empty($spref['xup_login_update_avatar']) || ($userdata['user_name'] != $user['user_name']) || ($userdata['user_image'] != $user['user_image']))
|
||||
{
|
||||
$updateQry = array();
|
||||
|
||||
if(!empty($spref['xup_login_update_username']))
|
||||
{
|
||||
$updateQry['user_name'] = $userdata['user_name'];
|
||||
}
|
||||
|
||||
if(!empty($spref['xup_login_update_avatar']))
|
||||
{
|
||||
$updateQry['user_image'] = $userdata['user_image'];
|
||||
}
|
||||
|
||||
if(empty($user['user_email']))
|
||||
{
|
||||
$updateQry['user_email'] = $userdata['user_email'];
|
||||
}
|
||||
|
||||
$updateQry['WHERE'] = "user_id=".$user['user_id']." LIMIT 1";
|
||||
|
||||
if($sql->update('user', $updateQry) !==false)
|
||||
{
|
||||
$updatedProfile = array_replace($user, $userdata);
|
||||
e107::getEvent()->trigger('user_xup_updated', $updatedProfile);
|
||||
e107::getLog()->add('User Profile Updated', $userdata, E_LOG_INFORMATIVE, "XUP_LOGIN", LOG_TO_ADMIN, array('user_id'=>$user['user_id'],'user_name'=>$user['user_name'], 'user_email'=>$userdata['user_email']));
|
||||
}
|
||||
else
|
||||
{
|
||||
e107::getLog()->add('User Profile Update Failed', $userdata, E_LOG_WARNING, "XUP_LOGIN", LOG_TO_ADMIN, $updateQry);
|
||||
}
|
||||
}
|
||||
|
||||
unset($user['user_password']);
|
||||
e107::getLog()->user_audit(USER_AUDIT_LOGIN,'', $user['user_id'], $user['user_name']);
|
||||
// e107::getLog()->add('XUP Login', $user, E_LOG_INFORMATIVE, "LOGIN", LOG_TO_ROLLING, array('user_id'=>$user['user_id'],'user_name'=>$user['user_name']));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO load user data by cookie/session data
|
||||
@@ -1843,9 +1739,6 @@ class e_user extends e_user_model
|
||||
return $this;
|
||||
}
|
||||
|
||||
// NEW - new external user login provider feature
|
||||
$this->tryProviderSession($denyAs);
|
||||
|
||||
// We have active session
|
||||
if(null !== $this->_session_data)
|
||||
{
|
||||
|
Reference in New Issue
Block a user