Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Register extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->model('users/users_model');
- }
- public function index()
- {
- $msgBoxMsgs = array();
- $cssPageAddons = '';
- $jsPageAddons = '<script src="'.base_url().'assets/js/plugins.js"></script><script src="'.base_url().'assets/js/jquery.validate.js"></script><script src="'.base_url().'assets/js/script.js"></script><script src="'.base_url().'assets/js/validate/register.js"></script>';
- $metaAddons = '';
- $siteTitle = 'KOW Manager Register';
- $bodyContent = '/usermanagement/forms/register_form';//which view file
- $bodyType = 'full';//type of template
- if(count($msgBoxMsgs) !== 0)
- {
- $msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
- }
- else
- {
- $msgBoxes = array('display' => 'none');
- }
- if(isset($siteTitle) && (empty($siteTitle)) )
- {
- $siteTitle = $this->metatags->SiteTitle();
- }
- $this->data = compact(
- 'msgBoxes',
- 'cssPageAddons',
- 'jsPageAddons',
- 'siteTitle',
- 'bodyType',
- 'bodyContent'
- );
- $this->load->view('usermanagement/index', $this->data);
- }
- public function is_username_available()
- {
- if ( $this->users_model->is_username_available($this->input->post('username')) )
- {
- // available
- echo('true');
- }
- else
- {
- // not available
- echo('false');
- }
- }
- public function is_email_available()
- {
- if ( $this->users_model->is_email_available($this->input->post('email_address')))
- {
- // available
- echo('true');
- }
- else
- {
- // not available
- echo('false');
- }
- }
- private function form_is_valid()
- {
- $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|strtolower|callback_username_exists');
- $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric');
- $this->form_validation->set_rules('password_confirm', 'Confirm Password', 'trim|required|xss_clean|matches[password]|min_length[6]|max_length[12]|alpha_numeric');
- $this->form_validation->set_rules('first_name', 'First Name', 'trim|required|xss_clean|alpha');
- $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required|xss_clean|alpha');
- $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email|callback_email_address_exists');
- return $this->form_validation->run();
- }
- public function username_exists($str)
- {
- if ($this->users_model->is_username_available($this->input->post('username')))
- {
- $this->form_validation->set_message('username', 'Testing');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- public function email_address_exists($str)
- {
- if ($this->users_model->is_email_address_available($this->input->post('email_address')))
- {
- $this->form_validation->set_message('email_address', 'Testing2');
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- private function get_post( $post_var )
- {
- return $this->input->post( $post_var );
- }
- private function create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address )
- {
- $return = $this->mylib->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address );
- $user_data =
- if( $return )
- {
- $this->mylib->send_email(
- 'activation',
- 'KOW Manager Registration Details',
- $user_data
- );
- }
- return $return;
- }
- public function submit()
- {
- if ( $this->form_is_valid() )
- {
- $post_username = $this->get_post( 'username' );
- $post_password = $this->get_post( 'password' );
- $post_first_name = $this->get_post( 'first_name' );
- $post_last_name = $this->get_post( 'last_name' );
- $post_email_address = $this->get_post( 'email_address' );
- if ( $this->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address ) )
- {
- $output_array = array(
- 'error' => FALSE,
- 'message' => 'Successful registration! We will be emailing you a confirmation email shortly!'
- );
- }
- else
- {
- $output_array = array(
- 'error' => TRUE,
- 'message' => 'There was a problem creating the user! Please try again!!'
- );
- }
- }
- else
- {
- $output_array = array(
- 'error' => TRUE,
- 'message' => 'The form was not validated!'
- );
- }
- echo json_encode($output_array);
- }
- }
- /* End of file register.php */
- /* Location: ./application/controllers/register.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement