Welcome Guest, Not a member yet? Register   Sign In
Registration Form Issues With Community Auth
#1

Hello,

I am relatively new to Community Auth but have a bit of experience working around Code Igniter. I am having issues getting a basic registration page working on my site. 

Here is my User controller for the registration:

PHP Code:
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

defined('BASEPATH') OR exit('No direct script access allowed');

class 
User extends MY_Controller {

 
   public function __construct() {
 
       parent::__construct();

 
       // Force SSL
 
       //$this->force_ssl();
 
       // Form and URL helpers always loaded (just for convenience)
 
       $this->load->helper('url');
 
       $this->load->helper('form');
 
   }

 
   public function register() {

 
       // Load resources
 
       $this->load->model('bc_user');
 
       $this->load->model('validation_callables');
 
       $this->load->library('form_validation');

 
       $validation_rules = array(
 
           array(
 
               'field' => 'username',
 
               'label' => 'Username',
 
               'rules' => 'max_length[12]|is_unique[' config_item('user_table') . '.username]',
 
               'errors' => array(
 
                   'is_unique' => 'Username already in use.'
 
               )
 
           ),
 
           array(
 
               'field' => 'password',
 
               'label' => 'Password',
 
               'rules' => array(
 
                   'trim',
 
                   'required',
 
                   array(
 
                       '_check_password_strength',
 
                       array($this->validation_callables'_check_password_strength')
 
                   )
 
               ),
 
               'errors' => array(
 
                   'required' => 'The password field is required.'
 
               )
 
           ),
 
           array(
 
               'field' => 'email',
 
               'label' => 'Email',
 
               'rules' => 'trim|required|valid_email|is_unique[' config_item('user_table') . '.email]',
 
               'errors' => array(
 
                   'is_unique' => 'Email address already in use.'
 
               )
 
           ),
 
           array(
 
               'field' => 'auth_level',
 
               'label' => 'auth_level',
 
               'rules' => 'required|integer|in_list[1,9]'
 
           )
 
       );

 
       $this->form_validation->set_rules($validation_rules);

 
       if ($this->form_validation->run()) {

 
           $this->bc_user->register();
 
           redirect('dashboard');

 
           /* if ($this->db->affected_rows() == 1)
              echo '<h1>Congratulations</h1>' . '<p>User ' . $user_data['username'] . ' was created.</p>';
              }
              else {
              echo '<h1>User Creation Error(s)</h1>' . validation_errors();
              }

              echo $this->load->view('examples/page_footer', '', TRUE);
             */
 
       }
 
   }



Here is my basic model: 

PHP Code:
<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class Bc_user extends CI_Model {

 
   public function register() {

 
       $data = array(
 
           'user_id' => $this->bc_user->get_unused_id(),
 
           'username' => $this->input->post('username'),
 
           'email' => $this->input->post('email'),
 
           'auth_level' => $this->input->post('auth_level'),
 
           'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT),
 
           'created_at' => date('Y-m-d H:i:s'),
 
       );

 
       return $this->db->insert('users'$data);
 
   }
 
   
    public 
function get_unused_id()
 
   {
 
       // Create a random user id between 1200 and 4294967295
 
       $random_unique_int 2147483648 mt_rand( -21474824482147483647 );

 
       // Make sure the random user_id isn't already in use
 
       $query $this->db->where'user_id'$random_unique_int )
 
           ->get_whereconfig_item('user_table') );

 
       if$query->num_rows() > )
 
       {
 
           $query->free_result();

 
           // If the random user_id is already in use, try again
 
           return $this->get_unused_id();
 
       }

 
       return $random_unique_int;
 
   }



and here is my form:

PHP Code:
   <!-- Contact Section -->
 
   <section id="contact">
 
       <div class="container">
 
           <div class="row">
 
               <div class="col-lg-12 text-center">
 
                   <h2>Sign Up</h2>
 
                   <hr class="star-primary">
 
               </div>
 
           </div>
 
           <div class="row">
 
               <div class="col-lg-8 col-lg-offset-2">
 
                   <?php echo form_open('user/register'); ?>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 floating-label-form-group controls">
                                <label>Username</label>
                                <input type="text" class="form-control" placeholder="Username" id="display_name" name="username" required data-validation-required-message="Choose your Username.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 floating-label-form-group controls">
                                <label>Login Name</label>
                                <input type="email" class="form-control" placeholder="Email Address" id="email" name="email" required data-validation-required-message="Please enter your Login Name.">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="row control-group">
                            <div class="form-group col-xs-12 floating-label-form-group controls">
                                <label>Password</label>
                                <input type="password" class="form-control" placeholder="Password" id="password" name="password" required data-validation-required-message="Please enter your password">
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <br />
                        <div id="success"></div>
                        <div class="row">
                            <div class="form-group col-xs-12">
                                <button type="submit" class="btn btn-success btn-lg">Send</button>
                            </div>
                        </div>
                    <?php echo form_close(); ?>
                </div>
            </div>
        </div>
    </section> 

When the form is submitted it goes to /user/register but it simply is a blank page. The redirect is not registered, which is suppose to go to the users personal dashboard.

Does anything jump out to anyone here? I was able to create a user without an issue via the example page but can't knock something as basic as this out.
Reply
#2

I narrowed it down to poor error checking on my part. The forum was not validating and had no idea what to do if it did not validate. Long night...
Reply
#3

(04-16-2016, 08:45 AM)BamaStangGuy Wrote: I narrowed it down to poor error checking on my part. The forum was not validating and had no idea what to do if it did not validate. Long night...

Normally what happens to me is I stay up SUPER late working on something I can't figure out, then I go to sleep. When I wake up I figure it out in like 10 minutes Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB