Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/ucp/ucp_register.php

    r400 r702  
    33*
    44* @package ucp
    5 * @version $Id: ucp_register.php 8782 2008-08-23 17:20:55Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    3838                include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
    3939
    40                 $confirm_id             = request_var('confirm_id', '');
    4140                $coppa                  = (isset($_REQUEST['coppa'])) ? ((!empty($_REQUEST['coppa'])) ? 1 : 0) : false;
    4241                $agreed                 = (!empty($_POST['agreed'])) ? 1 : 0;
     
    5453                }
    5554
    56 
    5755                if ($change_lang || $user_lang != $config['default_lang'])
    5856                {
     
    6967                                }
    7068
    71                                 $user->lang_name = $lang = $use_lang;
     69                                $user->lang_name = $user_lang = $use_lang;
    7270                                $user->lang = array();
     71                                $user->data['user_lang'] = $user->lang_name;
    7372                                $user->add_lang(array('common', 'ucp'));
    7473                        }
     
    8079                }
    8180
     81
    8282                $cp = new custom_profile();
    8383
    8484                $error = $cp_data = $cp_error = array();
    85 
    8685
    8786                if (!$agreed || ($coppa === false && $config['coppa_enable']) || ($coppa && !$config['coppa_enable']))
     
    9089                        $add_coppa = ($coppa !== false) ? '&coppa=' . $coppa : '';
    9190
    92                         $s_hidden_fields = ($confirm_id) ? array('confirm_id' => $confirm_id) : array();
     91                        $s_hidden_fields = array(
     92                                'change_lang'   => $change_lang,
     93                        );
    9394
    9495                        // If we change the language, we want to pass on some more possible parameter.
     
    100101                                        'email'                         => strtolower(request_var('email', '')),
    101102                                        'email_confirm'         => strtolower(request_var('email_confirm', '')),
    102                                         'confirm_code'          => request_var('confirm_code', ''),
    103                                         'confirm_id'            => request_var('confirm_id', ''),
    104103                                        'lang'                          => $user->lang_name,
    105104                                        'tz'                            => request_var('tz', (float) $config['board_timezone']),
    106105                                ));
    107                         }
     106
     107                        }
     108
     109                        // Checking amount of available languages
     110                        $sql = 'SELECT lang_id
     111                                FROM ' . LANG_TABLE;
     112                        $result = $db->sql_query($sql);
     113
     114                        $lang_row = array();
     115                        while ($row = $db->sql_fetchrow($result))
     116                        {
     117                                $lang_row[] = $row;
     118                        }
     119                        $db->sql_freeresult($result);
    108120
    109121                        if ($coppa === false && $config['coppa_enable'])
     
    114126
    115127                                $template->assign_vars(array(
     128                                        'S_LANG_OPTIONS'        => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
    116129                                        'L_COPPA_NO'            => sprintf($user->lang['UCP_COPPA_BEFORE'], $coppa_birthday),
    117130                                        'L_COPPA_YES'           => sprintf($user->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday),
     
    128141                        {
    129142                                $template->assign_vars(array(
     143                                        'S_LANG_OPTIONS'        => (sizeof($lang_row) > 1) ? language_select($user_lang) : '',
    130144                                        'L_TERMS_OF_USE'        => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
    131145
     
    137151                                );
    138152                        }
     153                        unset($lang_row);
    139154
    140155                        $this->tpl_name = 'ucp_agreement';
    141156                        return;
    142157                }
    143 
     158               
     159               
     160                // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
     161                if ($config['enable_confirm'])
     162                {
     163                        include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
     164                        $captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
     165                        $captcha->init(CONFIRM_REG);
     166                }
    144167
    145168                // Try to manually determine the timezone and adjust the dst if the server date/time complies with the default setting +/- 1
     
    168191                        'email'                         => strtolower(request_var('email', '')),
    169192                        'email_confirm'         => strtolower(request_var('email_confirm', '')),
    170                         'confirm_code'          => request_var('confirm_code', ''),
    171193                        'lang'                          => basename(request_var('lang', $user->lang_name)),
    172194                        'tz'                            => request_var('tz', (float) $timezone),
     
    188210                                        array('email')),
    189211                                'email_confirm'         => array('string', false, 6, 60),
    190                                 'confirm_code'          => array('string', !$config['enable_confirm'], 5, 8),
    191212                                'tz'                            => array('num', false, -14, 14),
    192213                                'lang'                          => array('match', false, '#^[a-z_\-]{2,}$#i'),
    193214                        ));
     215
    194216                        if (!check_form_key('ucp_register'))
    195217                        {
    196218                                $error[] = $user->lang['FORM_INVALID'];
    197219                        }
     220
    198221                        // Replace "error" strings with their real, localised form
    199222                        $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
    200223
     224                        if ($config['enable_confirm'])
     225                        {
     226                                $vc_response = $captcha->validate($data);
     227                                if ($vc_response !== false)
     228                                {
     229                                        $error[] = $vc_response;
     230                                }
     231
     232                                if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
     233                                {
     234                                        $error[] = $user->lang['TOO_MANY_REGISTERS'];
     235                                }
     236                        }
     237
    201238                        // DNSBL check
    202239                        if ($config['check_dnsbl'])
     
    210247                        // validate custom profile fields
    211248                        $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
    212 
    213                         // Visual Confirmation handling
    214                         $wrong_confirm = false;
    215                         if ($config['enable_confirm'])
    216                         {
    217                                 if (!$confirm_id)
    218                                 {
    219                                         $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    220                                         $wrong_confirm = true;
    221                                 }
    222                                 else
    223                                 {
    224                                         $sql = 'SELECT code
    225                                                 FROM ' . CONFIRM_TABLE . "
    226                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    227                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    228                                                         AND confirm_type = " . CONFIRM_REG;
    229                                         $result = $db->sql_query($sql);
    230                                         $row = $db->sql_fetchrow($result);
    231                                         $db->sql_freeresult($result);
    232 
    233                                         if ($row)
    234                                         {
    235                                                 if (strcasecmp($row['code'], $data['confirm_code']) === 0)
    236                                                 {
    237                                                         $sql = 'DELETE FROM ' . CONFIRM_TABLE . "
    238                                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    239                                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    240                                                                         AND confirm_type = " . CONFIRM_REG;
    241                                                         $db->sql_query($sql);
    242                                                 }
    243                                                 else
    244                                                 {
    245                                                         $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    246                                                         $wrong_confirm = true;
    247                                                 }
    248                                         }
    249                                         else
    250                                         {
    251                                                 $error[] = $user->lang['CONFIRM_CODE_WRONG'];
    252                                                 $wrong_confirm = true;
    253                                         }
    254                                 }
    255                         }
    256249
    257250                        if (!sizeof($error))
     
    327320                                );
    328321
     322                                if ($config['new_member_post_limit'])
     323                                {
     324                                        $user_row['user_new'] = 1;
     325                                }
     326
    329327                                // Register user...
    330328                                $user_id = user_add($user_row, $cp_data);
     
    334332                                {
    335333                                        trigger_error('NO_USER', E_USER_ERROR);
     334                                }
     335
     336                                // Okay, captcha, your job is done.
     337                                if ($config['enable_confirm'] && isset($captcha))
     338                                {
     339                                        $captcha->reset();
    336340                                }
    337341
     
    441445                        $s_hidden_fields['coppa'] = $coppa;
    442446                }
     447
     448                if ($config['enable_confirm'])
     449                {
     450                        $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
     451                }
    443452                $s_hidden_fields = build_hidden_fields($s_hidden_fields);
    444 
    445453                $confirm_image = '';
    446454
    447455                // Visual Confirmation - Show images
    448 
    449456                if ($config['enable_confirm'])
    450457                {
    451                         if ($change_lang)
    452                         {
    453                                 $str = '&change_lang=' . $change_lang;
    454                                 $sql = 'SELECT code
    455                                                 FROM ' . CONFIRM_TABLE . "
    456                                                 WHERE confirm_id = '" . $db->sql_escape($confirm_id) . "'
    457                                                         AND session_id = '" . $db->sql_escape($user->session_id) . "'
    458                                                         AND confirm_type = " . CONFIRM_REG;
    459                                 $result = $db->sql_query($sql);
    460                                 if (!$row = $db->sql_fetchrow($result))
    461                                 {
    462                                         $confirm_id = '';
    463                                 }
    464                                 $db->sql_freeresult($result);
    465                         }
    466                         else
    467                         {
    468                                 $str = '';
    469                         }
    470                         if (!$change_lang || !$confirm_id)
    471                         {
    472                                 $user->confirm_gc(CONFIRM_REG);
    473 
    474                                 $sql = 'SELECT COUNT(session_id) AS attempts
    475                                         FROM ' . CONFIRM_TABLE . "
    476                                         WHERE session_id = '" . $db->sql_escape($user->session_id) . "'
    477                                                 AND confirm_type = " . CONFIRM_REG;
    478                                 $result = $db->sql_query($sql);
    479                                 $attempts = (int) $db->sql_fetchfield('attempts');
    480                                 $db->sql_freeresult($result);
    481 
    482                                 if ($config['max_reg_attempts'] && $attempts > $config['max_reg_attempts'])
    483                                 {
    484                                         trigger_error('TOO_MANY_REGISTERS');
    485                                 }
    486 
    487                                 $code = gen_rand_string(mt_rand(5, 8));
    488                                 $confirm_id = md5(unique_id($user->ip));
    489                                 $seed = hexdec(substr(unique_id(), 4, 10));
    490 
    491                                 // compute $seed % 0x7fffffff
    492                                 $seed -= 0x7fffffff * floor($seed / 0x7fffffff);
    493 
    494                                 $sql = 'INSERT INTO ' . CONFIRM_TABLE . ' ' . $db->sql_build_array('INSERT', array(
    495                                         'confirm_id'    => (string) $confirm_id,
    496                                         'session_id'    => (string) $user->session_id,
    497                                         'confirm_type'  => (int) CONFIRM_REG,
    498                                         'code'                  => (string) $code,
    499                                         'seed'                  => (int) $seed)
    500                                 );
    501                                 $db->sql_query($sql);
    502                         }
    503                         $confirm_image = '<img src="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=confirm&amp;id=' . $confirm_id . '&amp;type=' . CONFIRM_REG . $str) . '" alt="" title="" />';
    504                         $s_hidden_fields .= '<input type="hidden" name="confirm_id" value="' . $confirm_id . '" />';
     458                        $template->assign_vars(array(
     459                                'CAPTCHA_TEMPLATE'              => $captcha->get_template(),
     460                        ));
    505461                }
    506462
     
    525481                        'EMAIL'                         => $data['email'],
    526482                        'EMAIL_CONFIRM'         => $data['email_confirm'],
    527                         'CONFIRM_IMG'           => $confirm_image,
    528 
    529                         'L_CONFIRM_EXPLAIN'                     => sprintf($user->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlspecialchars($config['board_contact']) . '">', '</a>'),
     483
    530484                        'L_REG_COND'                            => $l_reg_cond,
    531485                        'L_USERNAME_EXPLAIN'            => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
     
    534488                        'S_LANG_OPTIONS'        => language_select($data['lang']),
    535489                        'S_TZ_OPTIONS'          => tz_select($data['tz']),
    536                         'S_CONFIRM_CODE'        => ($config['enable_confirm']) ? true : false,
     490                        'S_CONFIRM_REFRESH'     => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
     491                        'S_REGISTRATION'        => true,
    537492                        'S_COPPA'                       => $coppa,
    538493                        'S_HIDDEN_FIELDS'       => $s_hidden_fields,
    539494                        'S_UCP_ACTION'          => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
    540                         )
    541                 );
     495                ));
    542496
    543497                //
Note: See TracChangeset for help on using the changeset viewer.