0

好的,所以我为注册过程添加了出生日期部分。我可能以一种奇怪的方式完成了它,但在我看来这是一种合乎逻辑的方式,只要它有效,我就可以接受它。我创建了 3 个 dob 字段(dob1、dob2、dob3 - 代表月、日、年)。我现在遇到的问题是当用户注册时,dob 值没有正确存储到数据库中(似乎这些值只是随机的,它们显示为随机数字和字母)。所以我很好奇我做错了什么。这是我所做的。

编辑:我发现了问题,但仍在寻找解决方案。排序在某个地方混淆了。我的前2个电子邮件字母进入dob1,前2个密码字母进入dob2(不知道是否通过或确认通过),dob1进入firstname,dob2进入lastnam,用户名很好,dob3进入电子邮件。所以我在某个地方混淆了我的数组的顺序,但我很确定它在哪里重要。

EDIT2:我发现了我的问题。答案如下。

在 controllers/auth.php 中注册函数

function register()
        {
                if ($this->tank_auth->is_logged_in()) {                                                                 // logged in
                        redirect('');

                } elseif ($this->tank_auth->is_logged_in(FALSE)) {                                              // logged in, not activated
                        redirect('/auth/send_again/');

                } elseif (!$this->config->item('allow_registration', 'tank_auth')) {    // registration is off
                        $this->_show_message($this->lang->line('auth_message_registration_disabled'));

                } else {
                        $use_username = $this->config->item('use_username', 'tank_auth');
                        if ($use_username) {
                                $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length['.$this->config->item('username_min_length', 'tank_auth').']|max_length['.$this->config->item('username_max_le\
ngth', 'tank_auth').']|alpha_dash');
                        }

                        $this->form_validation->set_rules('dob1', 'DOB1', 'trim|required|xss_clean|min_length[2]|max_length[2]');
                        $this->form_validation->set_rules('dob2', 'DOB2', 'trim|required|xss_clean|min_length[2]|max_length[2]');
                        $this->form_validation->set_rules('dob3', 'DOB3', 'trim|required|xss_clean|min_length[2]|max_length[4]');
                        $this->form_validation->set_rules('firstname', 'First Name', 'trim|xss_clean|min_length[2]|max_length[50]');
                        $this->form_validation->set_rules('lastname', 'Last Name', 'trim|xss_clean|min_length[2]|max_length[50]');

                        $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
                        $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email|callback_is_email_domain[ku.edu]');
                        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length['.$this->config->item('password_min_length', 'tank_auth').']|max_length['.$this->config->item('password_max_length', '\
tank_auth').']|alpha_dash');
                        $this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');

                        $captcha_registration   = $this->config->item('captcha_registration', 'tank_auth');
                        $use_recaptcha                  = $this->config->item('use_recaptcha', 'tank_auth');
                        if ($captcha_registration) {
                                if ($use_recaptcha) {
                                        $this->form_validation->set_rules('recaptcha_response_field', 'Confirmation Code', 'trim|xss_clean|required|callback__check_recaptcha');
                                } else {
                                        $this->form_validation->set_rules('captcha', 'Confirmation Code', 'trim|xss_clean|required|callback__check_captcha');
                                }
                        }
                        $data['errors'] = array();

                        $email_activation = $this->config->item('email_activation', 'tank_auth');

                        if ($this->form_validation->run()) {                                                            // validation ok
                                if (!is_null($data = $this->tank_auth->create_user(
                                                $use_username ? $this->form_validation->set_value('username') : '',

                                                $this->form_validation->set_value('dob1'),
                                                $this->form_validation->set_value('dob2'),
                                                $this->form_validation->set_value('dob3'),
                                                $this->form_validation->set_value('firstname'),
                                                $this->form_validation->set_value('lastname'),

                                                $this->form_validation->set_value('email'),
                                                $this->form_validation->set_value('password'),
                                                $email_activation))) {                                                                  // success

                                        $data['site_name'] = $this->config->item('website_name', 'tank_auth');

                        $email_activation = $this->config->item('email_activation', 'tank_auth');

                        if ($this->form_validation->run()) {                                                            // validation ok
                                if (!is_null($data = $this->tank_auth->create_user(
                                                $use_username ? $this->form_validation->set_value('username') : '',

                                                $this->form_validation->set_value('dob1'),
                                                $this->form_validation->set_value('dob2'),
                                                $this->form_validation->set_value('dob3'),
                                                $this->form_validation->set_value('firstname'),
                                                $this->form_validation->set_value('lastname'),

                                                $this->form_validation->set_value('email'),
                                                $this->form_validation->set_value('password'),
                                                $email_activation))) {                                                                  // success

                                        $data['site_name'] = $this->config->item('website_name', 'tank_auth');

                                        if ($email_activation) {                                                                        // send "activate" email
                                                $data['activation_period'] = $this->config->item('email_activation_expire', 'tank_auth') / 3600;

                                                $this->_send_email('activate', $data['email'], $data);

                                                unset($data['password']); // Clear password (just for any case)

                                                $this->_show_message($this->lang->line('auth_message_registration_completed_1'));

                                        } else {
                                                if ($this->config->item('email_account_details', 'tank_auth')) {        // send "welcome" email

                                                        $this->_send_email('welcome', $data['email'], $data);
                                                }
                                                unset($data['password']); // Clear password (just for any case)

                                                $this->_show_message($this->lang->line('auth_message_registration_completed_2').' '.anchor('/auth/login/', 'Login'));
                                        }
                                } else {
                                        $errors = $this->tank_auth->get_error_message();
                                        foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);
                                }
                        }
                        if ($captcha_registration) {
                                if ($use_recaptcha) {
                                        $data['recaptcha_html'] = $this->_create_recaptcha();
                                } else {
                                        $data['captcha_html'] = $this->_create_captcha();
                                }
                        }
                        $data['use_username'] = $use_username;
                        $data['captcha_registration'] = $captcha_registration;
                        $data['use_recaptcha'] = $use_recaptcha;
                        $this->load->view('auth/register_form', $data);
                }
        }

库:Tank_Auth.php - 我知道这不是整个 dob,但调用此函数不会返回任何内容,我想如果我可以返回 1 个 dob,那么我可以轻松地将它们全部返回。编辑:我刚刚意识到我没有包含我对该文件的所有更改。

else {  
    $this->ci->session->set_userdata(array(     
        'user_id'  => $user->id,    
        'dob1'     => $user->dob1,
        'dob2'     => $user->dob2,
        'dob3'     => $user->dob3,
        'firstname'  => $user->firstname,
        'lastname'  => $user->lastname,   
        'username'  => $user->username, 
        'status'  => ($user->activated == 1) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED, 

         ));

. . .

function get_dob()
        {
                return $this->ci->session->userdata('dob1');
        }

. . .

function create_user($username, $firstname, $lastname, $email, $password, $email_activation, $dob1, $dob2, $dob3)
{
    if ((strlen($username) > 0) AND !$this->ci->users->is_username_available($username)) {
        $this->error = array('username' => 'auth_username_in_use');
        $hashed_password = $hasher->HashPassword($password);
        $data = array(
            'firstname' => $firstname,
            'lastname' => $lastname,
            'dob1' => $dob1,
            'dob2' => $dob2,
            'dob3' => $dob3,
            'username' => $username,
            'password' => $hashed_password,
            'email' => $email,

浏览量:registration_form.php

<?php
if ($use_username) {
        $username = array(
                'name'  => 'username',
                'id'    => 'username',
                'value' => set_value('username'),
                'maxlength'     => $this->config->item('username_max_length', 'tank_auth'),
                'size'  => 30,
        );
}
$email = array(
        'name'  => 'email',
        'id'    => 'email',
        'value' => set_value('email'),
        'maxlength'     => 80,
        'size'  => 30,
);
$firstname = array(
        'name'  => 'firstname',
        'id'    => 'firstname',
        'value' => set_value('firstname'),
        'maxlength'     => 50,
        'size'  => 30,
);
$lastname = array(
        'name'  => 'lastname',
        'id'    => 'lastname',
        'value' => set_value('lastname'),
        'maxlength'     => 50,
        'size'  => 30,
);
$password = array(
        'name'  => 'password',
        'id'    => 'password',
        'value' => set_value('password'),
        'maxlength'     => $this->config->item('password_max_length', 'tank_auth'),
        'size'  => 30,
);
$confirm_password = array(
        'name'  => 'confirm_password',
        'id'    => 'confirm_password',
        'value' => set_value('confirm_password'),
        'maxlength'     => $this->config->item('password_max_length', 'tank_auth'),
        'size'  => 30,
);
$dob1 = array(
        'name'  => 'dob1',
        'id'    => 'dob1',
        'value' => set_value('dob1'),
        'maxlength'     => 2,
        'size'  => 30,
);
$dob2 = array(
        'name'  => 'dob2',
        'id'    => 'dob2',
        'value' => set_value('dob2'),
        'maxlength'     => 2,
        'size'  => 30,
);
$dob3 = array(
        'name'  => 'dob3',
        'id'    => 'dob3',
        'value' => set_value('dob3'),
        'maxlength'     => 4,
        'size'  => 30,
);
$captcha = array(
        'name'  => 'captcha',
        'id'    => 'captcha',
        'maxlength'     => 8,
);
?>
<?php echo form_open($this->uri->uri_string()); ?>
<table>
        <?php if ($use_username) { ?>
        <tr>
                <td><?php echo form_label('Username', $username['id']); ?></td>
                <td><?php echo form_input($username); ?></td>
                <td style="color: red;"><?php echo form_error($username['name']); ?><?php echo isset($errors[$username['name']])?$errors[$username['name']]:''; ?></td>
        </tr>
        <?php } ?>
        <tr>
                <td><?php echo form_label('Email Address', $email['id']); ?></td>
                <td><?php echo form_input($email); ?></td>
                <td style="color: red;"><?php echo form_error($email['name']); ?><?php echo isset($errors[$email['name']])?$errors[$email['name']]:''; ?></td>
        </tr>
        <tr>
                <td><?php echo form_label('First Name', $firstname['id']); ?></td>
                <td><?php echo form_input($firstname); ?></td>
                <td style="color: red;"><?php echo form_error($firstname['name']); ?><?php echo isset($errors[$firstname['name']])?$errors[$firstname['name']]:''; ?></td>
        </tr>
        <tr>
                <td><?php echo form_label('Last Name', $lastname['id']); ?></td>
                <td><?php echo form_input($lastname); ?></td>
                <td style="color: red;"><?php echo form_error($lastname['name']); ?><?php echo isset($errors[$lastname['name']])?$errors[$lastname['name']]:''; ?></td>
        </tr>
        <tr>
                <td><?php echo form_label('Password', $password['id']); ?></td>
                <td><?php echo form_password($password); ?></td>
                <td style="color: red;"><?php echo form_error($password['name']); ?></td>
        </tr>
        <tr>
                <td><?php echo form_label('Confirm Password', $confirm_password['id']); ?></td>
                <td><?php echo form_password($confirm_password); ?></td>
                <td style="color: red;"><?php echo form_error($confirm_password['name']); ?></td>
        </tr>
        <tr>
                <td><?php echo form_label('Date of Birth', $dob1['id']); ?></td>
                <td><?php echo form_input($dob1); ?></td>
                <td><?php echo form_input($dob2); ?></td>
                <td><?php echo form_input($dob3); ?></td>
                <td style="color: red;"><?php echo form_error($dob1['name']); ?><?php echo isset($errors[$dob1['name']])?$errors[$dob1['name']]:''; ?></td>
        </tr>

        <?php if ($captcha_registration) {
                if ($use_recaptcha) { ?>
        <tr>
                <td colspan="2">
                        <div id="recaptcha_image"></div>
                </td>
                <td>
                        <a href="javascript:Recaptcha.reload()">Get another CAPTCHA</a>
                        <div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div>
                        <div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">Get an image CAPTCHA</a></div>
                </td>
        </tr>
        <tr>
                <td>
                        <div class="recaptcha_only_if_image">Enter the words above</div>
                        <div class="recaptcha_only_if_audio">Enter the numbers you hear</div>
                </td>
                <td><input type="text" id="recaptcha_response_field" name="recaptcha_response_field" /></td>
                <td style="color: red;"><?php echo form_error('recaptcha_response_field'); ?></td>
                <?php echo $recaptcha_html; ?>
        </tr>
        <?php } else { ?>
        <tr>
                <td colspan="3">
                        <p>Enter the code exactly as it appears:</p>
                        <?php echo $captcha_html; ?>
                </td>
        </tr>
        <tr>
                <td><?php echo form_label('Confirmation Code', $captcha['id']); ?></td>
                <td><?php echo form_input($captcha); ?></td>
                <td style="color: red;"><?php echo form_error($captcha['name']); ?></td>
        </tr>
<?php }
        } ?>
</table>
<?php echo form_submit('register', 'Register'); ?>
<?php echo form_close(); ?>

**另外:如果您知道如何更改 registration_form.php 的 td 标签的宽度,请告诉我。我正在努力解决这个问题,简单的也行不通。

4

1 回答 1

0

我找到了我搞砸的地方。当我在 auth.php 中调用 create_user() 函数时,我以错误的顺序传递字段。我进入 Tank_Auth.php 文件并重新排序该函数的参数以匹配我在 auth.php 中传递的内容。

function create_user($username, $firstname, $lastname, $email, $password, $email_activation, $dob1, $dob2, $dob3)

变成

function create_user($username, $dob1, $dob2, $dob3, $firstname, $lastname, $email, $password, $email_activation)

这与我在 auth.php 中的 create_user() 调用相匹配:

if (!is_null($data = $this->tank_auth->create_user(
                                                $use_username ? $this->form_validation->set_value('username') : '',

                                                $this->form_validation->set_value('dob1'),
                                                $this->form_validation->set_value('dob2'),
                                                $this->form_validation->set_value('dob3'),
                                                $this->form_validation->set_value('firstname'),
                                                $this->form_validation->set_value('lastname'),

                                                $this->form_validation->set_value('email'),
                                                $this->form_validation->set_value('password'),
                                                $email_activation)))
于 2012-09-12T19:53:40.047 回答