Jump to content

Recommended Posts

Hey guys!

 

I know I've asked a couple of different questions in this matter, but this is getting to the point of sheer frustration. I've gathered many resources to check against my logic and syntax - mainly the code igniter user guide and tips and suggestions I've gathered on this forum.

 

I have restructured to where it makes the most logical sense to me, and for some reason the validation errors for my login are still acting screwy.

 

Here is what I have with comments on my logic:

 

I'm still getting white pages with some combinations. Everyone has said because there are extra "elses" that I am leaving blank, however I am confused on what to put there because I feel like my bases of all the criteria are already covered. What am I missing?

 

 

function validate_credentials_login()
{
// LOAD THE SESSION LIBRARY
$this->load->library('session');
// LOAD THE URL AND FORM HELPERS
$this->load->helper(array('form','url'));
// LOAD THE RELEVENT MODEL AND SET A NAME FOR IT
$this->load->model('user_model', 'um');
// LOAD ENCRYTPION LIBRARY IN ORDER TO ENCRYPT PASSWORDS PROPERLY
$this->load->library('encrypt');
// LOAD THE FORM VALIDATION LIBARARY TO MAKE USE OF ERROR HANDLING
$this->load->library('form_validation');
// SET RULES FOR MY EMAIL FIELD 
$this->form_validation->set_rules('email_login', 'Email', 'trim|required');
// SET RULES FOR MY PASSWORD FIELD
$this->form_validation->set_rules('password_login', 'Password', 'trim|required');
// MAKE A VARIABLE FOR MY SUBMIT BUTTON
$login = $this->input->post('submit_login');

// IF THE SUBMIT BUTTON IS SET
if($login) {

// MAKE THIS VARIABLE THAT CHECKS THE EMAIL FEILD INSERTED VIA POST AGAINST THE ONE STORED IN MY DATABASE 
$user = $this->um->validate_home_login(array('email' => $this->input->post('email_login')));

// IF THIS USER EXISTS AND THERE ARE NO ERRORS SET OFF BY THE FORM VALIDATION CHECK
if($user && $this->form_validation->run()) {
// DO THIS STUFF AKA IF THE USERS PASSWORD IS THE SAME AS THE ONE INSERTED VIA POST AND THE USERS EMAIL IS THE SAME INSERTED VIA POST EVERYTHING IS GOOD AND YOU CAN LOG THEM IN AND START A SESSION
if($user->password == $this->encrypt->sha1( $user->salt .  $this->encrypt->sha1($this->input->post('password_login'))) && $user->email == $this->input->post('email_login')) {
$this->session->set_userdata(array(
'email' => $this->input->post('email_login')
));
redirect('account/edit');
} $data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}

// IF ANYTHING IS OFF OR DOESN'T MATCH ( SUPOSEDELY ) RUN THE FORM VALIDATION AS FALSE AND RELAOD THE PAGE WITH ERRORS
elseif($this->form_validation->run() == FALSE)
{
$data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}
} 
}


function create_member() 
{
$this->load->library('form_validation');
$this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required'); 
$this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]');

if($this->form_validation->run() == FALSE)
{
$data['main_content'] = 'home/home_page';
$this->load->view('includes/templates/home_page_template', $data);
}
else 
{
$this->load->model('user_model');
if($query = $this->user_model->create_member())
{
$this->load->model('user_model');
$this->varification_email();
$data['main_content'] = 'account/welcome';
$this->load->view('includes/templates/main_page_template', $data);

}
else
{
$this->load->view('home/home_page');
}
}
}

 

 

 

I will paypal $10 to the person that helps me get this in order to purchase their 6 pack of choice! I just want to get this figured out and move on and am stumped.

 

 

<?php

echo form_open('auth/validate_credentials_login');
echo "<span class='errors_login'>";
echo form_error('email_login');
echo "</span>";
echo form_label('', 'Email', 'email_login');
$data = array( 'name' => 'email_login', 'class' => 'input', 'placeholder' => 'Email');
echo form_input($data, set_value('email_login'));
echo "<span class='errors_login'>";
echo form_error('password_login');
echo "</span>";
echo form_label('', 'Password;', 'password_login');
$data = array( 'name' => 'password_login', 'class' => 'input', 'placeholder' => 'Password');
echo form_password($data, set_value('sha1(password_login)'));
echo form_submit('submit_login', 'Login');
echo form_close();

?>

 

 

function validate_home_login($data)
{
// TAKING THE DATA FROM THE MODEL AND CHECKING IT AGAINST THE STORED INFO IN THE DB
$query = $this->db->where($data)->get('users', '1');

if($query->row())
{
return $query->row();
}
}

Not certain if this is your actual code or if you've pasted the closing brackets of the controller class. Also, not certain if this is the same post in the Frameworks board, but whatever - this one is formatted.

 

Here's your code tabbed out. see my comments

function create_member() {
   $this->load->library('form_validation');
   $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
   $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
   $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
   $this->form_validation->set_rules('password', 'Password', 'trim|required'); 
   $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]');

   if($this->form_validation->run() == FALSE) {
       $data['main_content'] = 'home/home_page';
       $this->load->view('includes/templates/home_page_template', $data);
   }
   else {
       $this->load->model('user_model');
       if($query = $this->user_model->create_member()) {
           $this->load->model('user_model');
           $this->varification_email();
           $data['main_content'] = 'account/welcome';
           $this->load->view('includes/templates/main_page_template', $data);
   }
   // extra else here. if you want three conditions, you'll need to turn the 
   // previous else into an elseif()
   else
   {
       $this->load->view('home/home_page');
   }
// one of these brackets has to go, unless you've pasted the closing
// class bracket.
} 
}

 

I really recommend an editor that has folding and hilighting. It'll help you spot these errors

Edited by Mahngiel
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.