Ignore:
Timestamp:
Jan 11, 2014, 3:50:26 PM (10 years ago)
Author:
mistic100
Message:

add 'allow_merge_accounts' parameter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/oAuth/include/public_events.inc.php

    r26619 r26626  
    5656function oauth_begin_register()
    5757{
    58   global $conf, $template, $hybridauth_conf, $page;
     58  global $conf, $template, $hybridauth_conf, $page, $user;
    5959 
    6060  if ($hybridauth_conf['enabled'] == 0)
     
    110110      $page['infos'][] = l10n('Your registration is almost done, please complete the registration form.');
    111111     
    112       // form submited
     112      // register form submited
    113113      if (isset($_POST['submit']))
    114114      {
     
    141141        unset($_POST['submit']);
    142142      }
     143      // login form submited
     144      else if (isset($_POST['login']) && $conf['oauth']['allow_merge_accounts'])
     145      {
     146        if ($conf['insensitive_case_logon'] == true)
     147        {
     148          $_POST['username'] = search_case_username($_POST['username']);
     149        }
     150       
     151        if ( pwg_login(false, $_POST['username'], $_POST['password'], false) )
     152        {
     153          pwg_unset_session_var('oauth_new_user');
     154         
     155          // update oauth field
     156          $query = '
     157UPDATE ' . USER_INFOS_TABLE . '
     158  SET oauth_id = "' . $oauth_id . '"
     159  WHERE user_id = ' . $user['id'] . '
     160;';
     161          pwg_query($query);
     162
     163          redirect('profile.php');
     164        }
     165        else
     166        {
     167          $page['errors'][] = l10n('Invalid password!');
     168        }
     169      }
    143170      else
    144171      {
     
    158185      // template
    159186      $template->assign('OAUTH_PATH', OAUTH_PATH);
    160       $template->set_prefilter('register', 'oauth_add_profile_prefilter');
    161       $template->set_prefilter('register', 'oauth_remove_password_fields_prefilter');
     187      if ($conf['oauth']['allow_merge_accounts'])
     188      {
     189        $template->assign('OAUTH_LOGIN_IN_REGISTER', true);
     190        $template->set_prefilter('register', 'oauth_add_login_in_register');
     191      }
     192      else
     193      {
     194        $template->set_prefilter('register', 'oauth_add_profile_prefilter');
     195        $template->set_prefilter('register', 'oauth_remove_password_fields_prefilter');
     196      }
    162197    }
    163198    catch (Exception $e)
     
    335370  return preg_replace($search, '$1 '.$add, $content);
    336371}
     372
     373function oauth_add_login_in_register($content)
     374{
     375  $search[0] = '<form method="post" action="{$F_ACTION}"';
     376  $replace[0] = file_get_contents(OAUTH_PATH . 'template/register.tpl') . $search[0];
     377 
     378  $search[1] = '{\'Enter your personnal informations\'|@translate}';
     379  $replace[1] = '{\'Create a new account\'|@translate}';
     380 
     381  return str_replace($search, $replace, $content);
     382}
Note: See TracChangeset for help on using the changeset viewer.