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('confirm_password', 'Confirm Password', 'trim|required|xss_clean|min_length[6]|max_length[12]|alpha_numeric|matches[password]');
- $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_address', 'Email Address', 'trim|required|xss_clean|valid_email|callback__email_exists');
- return $this->form_validation->run();
- }
- public function _username_exists($str)
- {
- if ($this->users_model->is_username_available($this->input->post('username')))
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- public function _email_address_exists($str)
- {
- if ($this->users_model->is_email_address_available($this->input->post('email_address')))
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- public function submit()
- {
- if ( $this->form_is_valid() )
- {
- $post_username = $this->input->post( 'username' );
- $post_password = $this->input->post( 'password' );
- $post_first_name = $this->input->post( 'first_name' );
- $post_last_name = $this->input->post( 'last_name' );
- $post_email_address = $this->input->post( 'email_address' );
- $user_data = $this->mylib->create_user( $post_username, $post_password, $post_first_name, $post_last_name, $post_email_address );
- if ( $user_data )
- {
- $this->mylib->send_email(
- 'registration_email',
- 'KOW Manager Registration Details',
- $user_data
- );
- $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