[eluser]xtremer360[/eluser]
This is my process function for my registration controller and wanted to get some feedback and how it looked and maybe what I can do to improve it any.
Code:
public function process()
{
$output_array = $this->general_functions->get_default_output();
// Load the validation rules from the user model to protect the backend of the system.
$this->form_validation->set_rules($this->user->rules);
// Check to see if validation is properly met.
if ($this->form_validation->run() == FALSE)
{
// Form validation did not pass successfully. Report back to the user there was error(s) on the form.
$output_array['message'] = 'The following form did not validate successfully. Please fix the form errors and try again.';
$output_array['errors'] = $this->form_validation->error_array();
}
else
{
// Form validation passed successfully.
// Set up variables from post data.
$post_username = $this->input->post('username');
$post_email_address = $this->input->post('email_address');
$post_password = $this->input->post('password');
$registration_date = gmdate('Y-m-d H:i:s', time());
$hashed_password = $this->general_functions->generate_password_hash($post_password);
$registration_key = sha1($registration_date.';;'.$post_email_address.';;'.$hashed_password[0]);
// Develop the array of post data for sending to the model.
$data = array(
'username' => $post_username,
'email_address' => $post_email_address,
'password' => $hashed_password[0],
'password_hash' => $hashed_password[1],
'registration_date' => $registration_date,
'registration_key' => $registration_key
);
// Try to create the user.
if ($this->user->create_user($data) == FALSE)
{
// User was not created successfully.
$output_array['message'] = 'The user was not created successfully.';
}
else
{
// User was successfully created and the user needs to verify their account.
// Send registered an email informing them how to validate their account.
$email_data = array(
'company_name' => $this->config->item('company_name'),
'company_email' => $this->config->item('company_email'),
'post_email_address' => $post_email_address,
'post_password' => $post_password,
'registration_key' => $registration_key,
);
$this->general_functions->send_email($this->config->item('company_email'), $post_email_address, 'Registration for '.$this->config->item('company_name'), $this->load->view('emails/registration', $email_data, TRUE));
$output_array['status'] = 'success';
$output_array['message'] = 'The user was created successfully. Please check your email for the link to activate your account.';
}
}
echo json_encode($output_array);
}