FB Connect plugin - better workflow for disconnecting and reconnecting Facebook accounts
This commit is contained in:
parent
60ac9bc6fd
commit
1e9c5b52b4
|
@ -62,7 +62,28 @@ class FBConnectauthAction extends Action
|
||||||
parent::handle($args);
|
parent::handle($args);
|
||||||
|
|
||||||
if (common_is_real_login()) {
|
if (common_is_real_login()) {
|
||||||
$this->clientError(_('Already logged in.'));
|
|
||||||
|
// User is already logged in. Does she already have a linked Facebook acct?
|
||||||
|
$flink = Foreign_link::getByForeignID($this->fbuid, FACEBOOK_CONNECT_SERVICE);
|
||||||
|
|
||||||
|
if ($flink) {
|
||||||
|
|
||||||
|
// User already has a linked Facebook account and shouldn't be here
|
||||||
|
common_debug('There is already a local user (' . $flink->user_id .
|
||||||
|
') linked with this Facebook (' . $this->fbuid . ').');
|
||||||
|
|
||||||
|
// We don't want these cookies
|
||||||
|
getFacebook()->clear_cookie_state();
|
||||||
|
|
||||||
|
$this->clientError(_('There is already a local user linked with this Facebook.'));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// User came from the Facebook connect settings tab, and
|
||||||
|
// probably just wants to link/relink their Facebook account
|
||||||
|
$this->connectUser();
|
||||||
|
}
|
||||||
|
|
||||||
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
|
|
||||||
$token = $this->trimmed('token');
|
$token = $this->trimmed('token');
|
||||||
|
@ -78,7 +99,7 @@ class FBConnectauthAction extends Action
|
||||||
}
|
}
|
||||||
$this->createNewUser();
|
$this->createNewUser();
|
||||||
} else if ($this->arg('connect')) {
|
} else if ($this->arg('connect')) {
|
||||||
$this->connectUser();
|
$this->connectNewUser();
|
||||||
} else {
|
} else {
|
||||||
common_debug(print_r($this->args, true), __FILE__);
|
common_debug(print_r($this->args, true), __FILE__);
|
||||||
$this->showForm(_('Something weird happened.'),
|
$this->showForm(_('Something weird happened.'),
|
||||||
|
@ -259,7 +280,7 @@ class FBConnectauthAction extends Action
|
||||||
303);
|
303);
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectUser()
|
function connectNewUser()
|
||||||
{
|
{
|
||||||
$nickname = $this->trimmed('nickname');
|
$nickname = $this->trimmed('nickname');
|
||||||
$password = $this->trimmed('password');
|
$password = $this->trimmed('password');
|
||||||
|
@ -290,6 +311,23 @@ class FBConnectauthAction extends Action
|
||||||
$this->goHome($user->nickname);
|
$this->goHome($user->nickname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function connectUser()
|
||||||
|
{
|
||||||
|
$user = common_current_user();
|
||||||
|
|
||||||
|
$result = $this->flinkUser($user->id, $this->fbuid);
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
$this->serverError(_('Error connecting user to Facebook.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
common_debug("Connected Facebook user $this->fbuid to local user $user->id");
|
||||||
|
|
||||||
|
// Return to Facebook connection settings tab
|
||||||
|
common_redirect(common_local_url('FBConnectSettings'), 303);
|
||||||
|
}
|
||||||
|
|
||||||
function tryLogin()
|
function tryLogin()
|
||||||
{
|
{
|
||||||
common_debug("Trying Facebook Login...");
|
common_debug("Trying Facebook Login...");
|
||||||
|
|
|
@ -143,23 +143,6 @@ class FBConnectPlugin extends Plugin
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
|
|
||||||
$action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
|
|
||||||
_('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
|
|
||||||
$action->menuItem(common_local_url('profilesettings'),
|
|
||||||
_('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
|
|
||||||
if (common_config('xmpp', 'enabled')) {
|
|
||||||
$action->menuItem(common_local_url('imsettings'),
|
|
||||||
_('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
|
|
||||||
} else {
|
|
||||||
$action->menuItem(common_local_url('smssettings'),
|
|
||||||
_('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
|
|
||||||
}
|
|
||||||
$action->menuItem(common_local_url('invite'),
|
|
||||||
_('Invite'),
|
|
||||||
sprintf(_('Invite friends and colleagues to join you on %s'),
|
|
||||||
common_config('site', 'name')),
|
|
||||||
false, 'nav_invitecontact');
|
|
||||||
|
|
||||||
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
|
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
|
||||||
$fbuid = 0;
|
$fbuid = 0;
|
||||||
|
|
||||||
|
@ -195,9 +178,25 @@ class FBConnectPlugin extends Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to override the Logout link to make it do FB stuff
|
$action->menuItem(common_local_url('all', array('nickname' => $user->nickname)),
|
||||||
|
_('Home'), _('Personal profile and friends timeline'), false, 'nav_home');
|
||||||
|
$action->menuItem(common_local_url('profilesettings'),
|
||||||
|
_('Account'), _('Change your email, avatar, password, profile'), false, 'nav_account');
|
||||||
|
if (common_config('xmpp', 'enabled')) {
|
||||||
|
$action->menuItem(common_local_url('imsettings'),
|
||||||
|
_('Connect'), _('Connect to IM, SMS, Twitter'), false, 'nav_connect');
|
||||||
|
} else {
|
||||||
|
$action->menuItem(common_local_url('smssettings'),
|
||||||
|
_('Connect'), _('Connect to SMS, Twitter'), false, 'nav_connect');
|
||||||
|
}
|
||||||
|
$action->menuItem(common_local_url('invite'),
|
||||||
|
_('Invite'),
|
||||||
|
sprintf(_('Invite friends and colleagues to join you on %s'),
|
||||||
|
common_config('site', 'name')),
|
||||||
|
false, 'nav_invitecontact');
|
||||||
|
|
||||||
if ($fbuid > 0) {
|
// Need to override the Logout link to make it do FB stuff
|
||||||
|
if ($flink && $fbuid > 0) {
|
||||||
|
|
||||||
$logout_url = common_local_url('logout');
|
$logout_url = common_local_url('logout');
|
||||||
$title = _('Logout from the site');
|
$title = _('Logout from the site');
|
||||||
|
@ -258,21 +257,32 @@ class FBConnectPlugin extends Plugin
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onEndLogout($action)
|
function onStartLogout($action)
|
||||||
{
|
{
|
||||||
try {
|
$user = common_current_user();
|
||||||
|
|
||||||
|
$flink = Foreign_link::getByUserId($user->id, FACEBOOK_CONNECT_SERVICE);
|
||||||
|
|
||||||
|
$action->logout();
|
||||||
|
|
||||||
|
if ($flink) {
|
||||||
|
|
||||||
$facebook = getFacebook();
|
$facebook = getFacebook();
|
||||||
$fbuid = $facebook->get_loggedin_user();
|
|
||||||
|
|
||||||
if ($fbuid > 0) {
|
try {
|
||||||
$facebook->logout(common_local_url('public'));
|
$fbuid = $facebook->get_loggedin_user();
|
||||||
|
|
||||||
|
if ($fbuid > 0) {
|
||||||
|
$facebook->logout(common_local_url('public'));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' .
|
||||||
|
$e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception $e) {
|
|
||||||
common_log(LOG_WARNING, 'Could\'t logout of Facebook: ' .
|
|
||||||
$e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,63 +78,73 @@ class FBConnectSettingsAction extends ConnectSettingsAction
|
||||||
function showContent()
|
function showContent()
|
||||||
{
|
{
|
||||||
$user = common_current_user();
|
$user = common_current_user();
|
||||||
|
|
||||||
$flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
|
$flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE);
|
||||||
|
|
||||||
if (!$flink) {
|
|
||||||
|
|
||||||
$this->element('p', 'form_note',
|
|
||||||
_('There is no Facebook user connected to this account.'));
|
|
||||||
|
|
||||||
$this->element('fb:login-button', array('onlogin' => 'goto_login()',
|
|
||||||
'length' => 'long'));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->element('p', 'form_note',
|
|
||||||
_('Connected Facebook user:'));
|
|
||||||
|
|
||||||
$this->elementStart('p', array('class' => 'facebook-user-display'));
|
|
||||||
$this->elementStart('fb:profile-pic',
|
|
||||||
array('uid' => $flink->foreign_id,
|
|
||||||
'size' => 'square',
|
|
||||||
'linked' => 'true',
|
|
||||||
'facebook-logo' => 'true'));
|
|
||||||
$this->elementEnd('fb:profile-pic');
|
|
||||||
|
|
||||||
$this->elementStart('fb:name', array('uid' => $flink->foreign_id));
|
|
||||||
$this->elementEnd('fb:name');
|
|
||||||
$this->elementEnd('p');
|
|
||||||
|
|
||||||
$this->elementStart('form', array('method' => 'post',
|
$this->elementStart('form', array('method' => 'post',
|
||||||
'id' => 'form_settings_facebook',
|
'id' => 'form_settings_facebook',
|
||||||
'class' => 'form_settings',
|
'class' => 'form_settings',
|
||||||
'action' =>
|
'action' =>
|
||||||
common_local_url('FBConnectSettings')));
|
common_local_url('FBConnectSettings')));
|
||||||
|
|
||||||
$this->hidden('token', common_session_token());
|
if (!$flink) {
|
||||||
|
|
||||||
$this->elementStart('fieldset');
|
$this->element('p', 'instructions',
|
||||||
|
_('There is no Facebook user connected to this account.'));
|
||||||
|
|
||||||
$this->element('legend', null, _('Disconnect my account from Facebook'));
|
$this->element('fb:login-button', array('onlogin' => 'goto_login()',
|
||||||
|
'length' => 'long'));
|
||||||
|
|
||||||
if (!$user->password) {
|
|
||||||
|
|
||||||
$this->elementStart('p', array('class' => 'form_guide'));
|
|
||||||
$this->text(_('Disconnecting your Faceboook ' .
|
|
||||||
'would make it impossible to log in! Please '));
|
|
||||||
$this->element('a',
|
|
||||||
array('href' => common_local_url('passwordsettings')),
|
|
||||||
_('set a password'));
|
|
||||||
|
|
||||||
$this->text(_(' first.'));
|
|
||||||
$this->elementEnd('p');
|
|
||||||
} else {
|
} else {
|
||||||
$this->submit('disconnect', _('Disconnect'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->elementEnd('fieldset');
|
$this->element('p', 'form_note',
|
||||||
|
_('Connected Facebook user'));
|
||||||
|
|
||||||
|
$this->elementStart('p', array('class' => 'facebook-user-display'));
|
||||||
|
$this->elementStart('fb:profile-pic',
|
||||||
|
array('uid' => $flink->foreign_id,
|
||||||
|
'size' => 'small',
|
||||||
|
'linked' => 'true',
|
||||||
|
'facebook-logo' => 'true'));
|
||||||
|
$this->elementEnd('fb:profile-pic');
|
||||||
|
|
||||||
|
$this->elementStart('fb:name', array('uid' => $flink->foreign_id,
|
||||||
|
'useyou' => 'false'));
|
||||||
|
$this->elementEnd('fb:name');
|
||||||
|
$this->elementEnd('p');
|
||||||
|
|
||||||
|
$this->hidden('token', common_session_token());
|
||||||
|
|
||||||
|
$this->elementStart('fieldset');
|
||||||
|
|
||||||
|
$this->element('legend', null, _('Disconnect my account from Facebook'));
|
||||||
|
|
||||||
|
if (!$user->password) {
|
||||||
|
|
||||||
|
$this->elementStart('p', array('class' => 'form_guide'));
|
||||||
|
$this->text(_('Disconnecting your Faceboook ' .
|
||||||
|
'would make it impossible to log in! Please '));
|
||||||
|
$this->element('a',
|
||||||
|
array('href' => common_local_url('passwordsettings')),
|
||||||
|
_('set a password'));
|
||||||
|
|
||||||
|
$this->text(_(' first.'));
|
||||||
|
$this->elementEnd('p');
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$note = 'Keep your %s account but disconnect from Facebook. ' .
|
||||||
|
'You\'ll use your %s password to log in.';
|
||||||
|
|
||||||
|
$site = common_config('site', 'name');
|
||||||
|
|
||||||
|
$this->element('p', 'instructions',
|
||||||
|
sprintf($note, $site, $site));
|
||||||
|
|
||||||
|
$this->submit('disconnect', _('Disconnect'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->elementEnd('fieldset');
|
||||||
|
}
|
||||||
|
|
||||||
$this->elementEnd('form');
|
$this->elementEnd('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,8 +181,7 @@ class FBConnectSettingsAction extends ConnectSettingsAction
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// XXX: not sure what exactly to do here
|
// Clear FB Connect cookies out
|
||||||
|
|
||||||
$facebook = getFacebook();
|
$facebook = getFacebook();
|
||||||
$facebook->clear_cookie_state();
|
$facebook->clear_cookie_state();
|
||||||
|
|
||||||
|
@ -182,7 +191,7 @@ class FBConnectSettingsAction extends ConnectSettingsAction
|
||||||
$e->getMessage());
|
$e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->showForm(_('Facebook user disconnected.'), true);
|
$this->showForm(_('You have disconnected from Facebook.'), true);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->showForm(_('Not sure what you\'re trying to do.'));
|
$this->showForm(_('Not sure what you\'re trying to do.'));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user