Welcome Guest, Not a member yet? Register   Sign In
Redux Authentication 1.4a (24th July 2008)
#31

[eluser]patbert[/eluser]
Fair enough Smile.

I am having a spot of trouble getting the register function to work.

http://pastebin.ca/926919

It always seems to fail the registration process. I have no idea if the login ever returns true because I have yet to get a user made lol.

What is most odd is that if I am at the registration page, whether I give it valid data or not, when I submit it I end up at the login page. I can't figure out what is making it go there. It should go back to the registration page.
#32

[eluser]Tom Glover[/eluser]
[quote author="Popcorn" date="1204602497"]Hmm. Without SSL all $_POST data can be readable if your connection is sniffed. I suggest if you're really worried about security you shell out for SSL. Smile[/quote]

good idea.
#33

[eluser]Popcorn[/eluser]
[quote author="patbert" date="1204604416"]Fair enough Smile.

I am having a spot of trouble getting the register function to work.

http://pastebin.ca/926919

It always seems to fail the registration process. I have no idea if the login ever returns true because I have yet to get a user made lol.

What is most odd is that if I am at the registration page, whether I give it valid data or not, when I submit it I end up at the login page. I can't figure out what is making it go there. It should go back to the registration page.[/quote]

Code:
function register() {

        // .. Validation Rules go here.
        
        if ( $this->validation->run() )
        {
            $register = $this->auth->register (
                                        $this->input->post('name'),
                                        $this->input->post('password'),
                                        $this->input->post('email'),
                                        $this->input->post('name'),
            );
            
            // Without Email activation
            if ( $registration === 'registration_success' )
            {
                // Set flash data and redirect.
                $this->session->set_flashdata('response', 'You just registered :)');
                redirect('blog');
            }
            
            // With email activation.
            elseif ( $registration === 'registration_success_email' )
            {
                # code...
            }
            
            // Netiher
            else
            {
                $this->session->set_flashdata('response', 'Oops :(');
                redirect('blog/register');
            }
            
            $this->load->view('header');
            $this->load->view('menu');
            
            # Display any messages, if any
            if ($this->session->flashdata('response') != NULL) {
                $data['response'] = $this->session->flashdata('response');
                $this->load->view('response', $data);
            }
    
            $this->load->view('register');
    
            $this->load->view('footer');
        }
        else
        {
            // Load the registration template again here.
        }

    }

I refactored your code. You can setup validation routines like this :
Code:
$rules['username'] = "required";
http://ellislab.com/codeigniter/user-gui...ation.html

If that fails to work can you send me a copy of you config/auth.php and database layout via PM and I'll check it over for you.
#34

[eluser]patbert[/eluser]
Hello, thank you for the reply!

I feel really stupid because I was yanking my hair out trying to figure out why it kept kicking me back to blog/login. I had copied the login view and edited it a bit to make the register view. In doing so I forgot to change the form action from blog/login to blog/register. Doh!

So now I am getting. . . somewhere. When I submit a registration, I get an undefined variable "$optional" error in the auth.php library at line 179 which is:

// Set Optional Fields.
$this->ci->auth_model->set($optional);

In my auth.php config file there is the $config['optional_columns'] array. Looking at it now it looks like there is something odd going on with the line spacing or returns somewhere. I have just now set it to be empty:

$config['optional_columns'] = array ('');

That gets me a bit farther, now on a registration submission I get:

Unknown column '0' in 'field list'
INSERT INTO `users` (`hash`, `username`, `password`, `email`, `firstname`, `group_id`, `0`) VALUES ('96e6c3c74a966e159d20f5ff078ec99d6811813f', 'Patrick', '2c403dc4ba862c28aa0b0fd1eef1d5b72ffaa50b', '[email protected]', 'Patrick', '2', 0)

I have the exact db setup from your sql file. In 'users' I have hash, username, password, email, firstname, group_id, banned_id, and activation_code. I am not using the email activation function. Also, my groups table has id, title, and description; but it doesn't have any rows. Does it need at least one to work?

Thank you again for your help!



edit: I commented out lines 167-179 in the auth.php library and it works now! My login function never seems to return true. I'll see if I can get anywhere with that.
#35

[eluser]Popcorn[/eluser]
1 : Yes, I found the bug, it appears I assign $optinal without checking to see if a value exists in the config. I'll fix that when I get home tonight.

2 : I'll debug the login function to see if it is doing something wrong otherwise can you show me your latest code? and I'll try to see what's going on.

Sorry for the problems. I hope to roll out a fix tonight some time.
#36

[eluser]Popcorn[/eluser]
Updated the zip on the site with the latest fix. Can you test it out and if you still have problems can you provide me with a code sample? Much appreciated.
#37

[eluser]coldKingdom[/eluser]
Hello!

I have some problems with the autogenerate columns function, maybe i have misunderstood how to use it. This is my code in the controller:

Code:
function validate()
    {
        //Sätt alla regler
        $rules['name']        = "required|min_length[4]";
        $rules['sex']        = "trim|required";
        $rules['username']     = "trim|required|alpha_dash|min_length[4]|max_length[20]|callback_check_username";
        $rules['pass']        = "trim|required|min_length[4]|matches[pass2]";
        $rules['pass2']        = "trim|required|min_length[4]";
        $rules['email']        = "trim|required|valid_email|callback_check_email";
        $this->validation->set_rules($rules);

        //Skapa namn på alla reglerna
        $fields['name']        = 'Namn';
        $fields['sex']        = 'Kön';
        $fields['username'] = 'Användarnamn';
        $fields['pass']     = 'Lösenord';
        $fields['pass2']     = 'Bekräfta lösenord';
        $fields['email']     = 'E-post';

        $this->validation->set_fields($fields);
        
        //Sätt en delimiter
        $this->validation->set_error_delimiters('<em>', "</em>\n<br />");
        
        if ($this->validation->run() == FALSE)
            $this->ocular->render();
        else
        {
            $this->check_register(
                $this->input->post('username'),
                $this->input->post('pass'),
                $this->input->post('email'),
                $this->input->post('name'));
            $this->ocular->render();
        }    
    }
    
    function check_register($username, $password, $email, $firstname)
    {
        $this->load->helper('security');
        
        if ( $this->auth->register($username, $password, $email, $firstname) )
        {
            return true;
        }
        else
        {    
            $this->validation->set_message('check_register', 'De gick inte så bra. Försök igen!');
            return false;
        }
    }

This is my config file

Code:
$config['optional_columns']  = array (
'name' => array ('type' => 'varchar', 'constraint' => '100'),
'sex' => array ('type' => 'char', 'constraint' => '1'));

Is this all i have todo for the fields to be generated and add the values to db?

Thanks for an excellent auth library! Smile
#38

[eluser]Popcorn[/eluser]
Yep, you only have to set the columns in the config and just make sure the form elements have the same name and it should input them into the table when registering.

The register function doesn't doesn't return true and false like most functions but infact it's returns are :

'registration_success' - This is for a complete registration without email activation.
'registration_success_email' - This is for a complete registration with email activation.
false - Failed to register.

I chose this because you can control the output for different situations as you can see in the code below :
Code:
function registration ()
        {
            /*
            |---------------------------------------------------------
            | Required Fields
            |---------------------------------------------------------
            */
            $rules['username']     = 'trim|required|callback_check_username';
            $rules['email']        = 'trim|required|callback_check_email';
            $rules['password']    = 'trim|required|matches[password2]';
            $rules['password2'] = 'trim|required';
            $rules['firstname'] = 'trim|required';
            /*
            |---------------------------------------------------------
            | Optional Fields
            |---------------------------------------------------------
            */
            $rules['lastname']    = 'trim';
            $rules['location']    = 'trim';
            $rules['website']    = 'trim';
            $rules['msn']        = 'trim';
            $rules['yahoo']        = 'trim';
            $rules['aim']        = 'trim';
            $rules['gtalk']        = 'trim';
            $rules['skype']        = 'trim';
            /*
            |---------------------------------------------------------
            | Required Field Names
            |---------------------------------------------------------
            */
            $fields['username']        = 'Username';
            $fields['email']        = 'Email Address';
            $fields['password']        = 'Password';
            $fields['password2']    = 'Repeat Password';
            $fields['firstname']    = 'First Name';
            /*
            |---------------------------------------------------------
            | Ooptional Field Names
            |---------------------------------------------------------
            */
            $fields['lastname']    = 'Last Name';
            $fields['location']    = 'Location';
            $fields['website']    = 'Website';
            $fields['msn']        = 'Msn Messenger';
            $fields['yahoo']    = 'Yahoo';
            $fields['aim']        = 'AIM';
            $fields['gtalk']    = 'Google Talk';
            $fields['skype']    = 'Skype';

            $this->validation->set_rules($rules);
            $this->validation->set_fields($fields);
            $this->validation->set_error_delimiters('<span class="error">', '</span>');
            
            if ( $this->validation->run() )
            {

                $registration = $this->auth->register(    $this->input->post('username'),
                                                        $this->input->post('password'),
                                                        $this->input->post('email'),
                                                        $this->input->post('firstname')
                );
                
                if ( $registration === 'registration_success' )
                {
                    $this->view->part('content', 'user/registration_success');
                    $this->view->load('layout');
                }
                elseif ( $registration === 'registration_success_email' )
                {
                    $this->view->part('content', 'user/registration_success_email');
                    $this->view->load('layout');
                }                
            }
            else
            {
                $this->view->set('countries', $this->auth->get_countries());
                $this->view->part('content', 'user/registration');
                $this->view->load('layout');
            }

        }
#39

[eluser]coldKingdom[/eluser]
Alright, i understand. Then it's not working to well for me, the script doesn't make the columns for some reason and I don't get any messages either.
#40

[eluser]Popcorn[/eluser]
Hmmm, have you correctly set the table names in the config/auth.php file?




Theme © iAndrew 2016 - Forum software by © MyBB