Commit 5a1b9519 authored by jonnybradley's avatar jonnybradley

[FIX] socialnetworks: Make facebook login work better when login_is_email (thanks BSfez)

parent d56320ea
......@@ -103,6 +103,13 @@ function prefs_socialnetworks_list()
'type' => 'flag',
'default' => 'n',
),
'socialnetworks_facebook_email' => array(
'name' => tra('Tiki can get email'),
'description' => tra("Tiki can request the user's email"),
'keywords' => 'social networks',
'type' => 'flag',
'default' => 'n',
),
'socialnetworks_bitly_login' => array(
'name' => tra('bit.ly Login'),
'description' => tra('Site wide login (username) for bit.ly'),
......
......@@ -159,6 +159,9 @@ class SocialNetworksLib extends LogsLib
if ($prefs['socialnetworks_facebook_manage_pages'] == 'y') {
$scopes[] = 'manage_pages';
}
if ($prefs['socialnetworks_facebook_email'] === 'y') {
$scopes[] = 'email';
}
$scope = implode(',', $scopes);
$url = $this->getURL();
if (strpos($url, '?') != 0) {
......@@ -221,6 +224,7 @@ class SocialNetworksLib extends LogsLib
if (empty($fb_profile->id)) {
return false;
}
// echo '<!-- $ret=' . var_export($fb_profile, true) . '-->';
if (!$user) {
if ($prefs['socialnetworks_facebook_login'] != 'y') {
return false;
......@@ -230,8 +234,13 @@ class SocialNetworksLib extends LogsLib
$user = $local_user;
} elseif ($prefs['socialnetworks_facebook_autocreateuser'] == 'y') {
$randompass = $userlib->genPass();
$user = 'fb_' . $fb_profile->id;
$userlib->add_user($user, $randompass, '');
$email = $prefs['socialnetworks_facebook_email'] === 'y' ? $fb_profile->email : '';
if ($prefs['login_is_email'] == 'y' && $email) {
$user = $email;
} else {
$user = 'fb_' . $fb_profile->id;
}
$userlib->add_user($user, $randompass, $email);
$this->set_user_preference($user, 'realName', $fb_profile->name);
if ($prefs['socialnetworks_facebook_firstloginpopup'] == 'y') {
$this->set_user_preference($user, 'socialnetworks_user_firstlogin', 'y');
......
......@@ -43,6 +43,7 @@
{preference name=socialnetworks_facebook_manage_events}
{preference name=socialnetworks_facebook_manage_pages}
{preference name=socialnetworks_facebook_sms}
{preference name=socialnetworks_facebook_email}
</div>
{/tab}
{tab name="{tr}bit.ly{/tr}"}
......
......@@ -8,7 +8,10 @@ window.parent.location = 'tiki-index.php';
<p>{tr}You will be redirected to the home page shortly.{/tr} <a href="tiki-index.php" target="_parent">{tr}Click here{/tr}</a> {tr}to go to the home page immediately.{/tr}</p>
{else}
{jq}
$("#name").val("{{($prefs.login_is_email eq 'y' and $userinfo.login neq 'admin') ? {$userinfo.email|escape} : {$userinfo.login|escape} }}");
$("#email").val("{{$userinfo.email|escape}}");
{/jq}
{if $msg}<p><strong>{$msg|escape}</strong></p>{/if}
<h4>{tr}Please provide local account information{/tr}</h4>
......
......@@ -30,6 +30,8 @@ $access->check_user($user);
$smarty->assign('msg', '');
$smarty->assign('alldone', false);
$smarty->assign('userinfo', $userlib->get_user_info($user));
//groups choice
if (count($registrationlib->merged_prefs['choosable_groups'])) {
$smarty->assign('listgroups', $registrationlib->merged_prefs['choosable_groups']);
......@@ -43,7 +45,7 @@ if (isset($_REQUEST["localinfosubmit"])) {
$smarty->assign('msg', tra('Email is mandatory'));
} else if (empty($_REQUEST["name"]) || (empty($_REQUEST["email"]) && $prefs['login_is_email'] !== 'y')) {
$smarty->assign('msg', tra('Username and email are mandatory'));
} elseif ($userlib->user_exists($_REQUEST["name"])) {
} elseif ($user !== $_REQUEST['name'] && $userlib->user_exists($_REQUEST['name'])) {
$smarty->assign('msg', tra('User already exists'));
} elseif (!preg_match('/^[_a-z0-9\.\-]+@[_a-z0-9\.\-]+\.[a-z]{2,4}$/i',
($prefs['login_is_email'] !== 'y') ? $_REQUEST['email'] : $_REQUEST['name'])) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment