Jump to content

Recommended Posts

I have a lot of if statements here and curious to know if someone thinks I should do something different here.

 

/**
     * Accepts the parameters given with the controller and attempts to activate the user from the email link
     * 
     */
    public function _remap()
    {
        $user_id = (int) $this->uri->segment(2);
        $registration_key = $this->uri->segment(3);
        
        if ((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key)))))
        {
            if (($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))
            {   
                if ($this->users_model->is_registered($user_id))
                {
                    $user_status_id = $this->users_model->get_user_status_id($user_id);
                    
                    if ($user_status_id == 1)
                    {
                        if ($this->users_model->check_user_registration_key($user_id, $registration_key))
                        {
                            $this->db->trans_start();
                            
                            if ($this->users_model->change_account_type($user_id, 2))
                            {
                                if ($this->users_model->erase_registration_key($user_id, $registration_key))
                                {
                                    $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
                                }
                                else
                                {
                                    $message = 'The registration key failed to erase for the user specified!';         
                                }
                            }
                            else
                            {
                                $message = 'The user specified was not able to have his account changed!';
                            }
                            
                            $this->db->trans_complete();
                            
                            if ($this->db->trans_status())
                            { 
                                $output_array = array('error' => FALSE, 'message' => 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>');
                            }
                            else
                            {
                                $output_array = array('error' => TRUE, 'message' => 'The user was not able to be activated. The account specified was not able to be changed into a user!');   
                            }
                        }
                        else
                        {
                            $message = 'The registration key did not match the user specified!';
                        }
                    }
                    else
                    {
                        $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
                    }
                }
                else
                {
                    $message = 'The user specified does not exist in the database!!';
                }
            } 
            else
            {
                $message = 'The parameters do not meet the validation criteria!';
            }
        }
        else
        {
            $message = 'One or both parameters were not entered!';
        }

Link to comment
https://forums.phpfreaks.com/topic/267764-account-activation/
Share on other sites

You can inverse it. So you don't have to indent like mad.

 

public function _remap()
{
    $user_id = (int) $this->uri->segment(2);
    $registration_key = $this->uri->segment(3);
    
    if (!((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key)))))) {
        $message = 'One or both parameters were not entered!';
    } else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) {   
        $message = 'The parameters do not meet the validation criteria!';
    }
        
    if (!$this->users_model->is_registered($user_id)) {
        $message = 'The user specified does not exist in the database!';
    }
    
    if ($message) return $message;
    
    $user_status_id = $this->users_model->get_user_status_id($user_id);
        
    if ($user_status_id != 1) {
        $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
    } else if (!$this->users_model->check_user_registration_key($user_id, $registration_key)) {
        $message = 'The registration key did not match the user specified!';
    }
        
    if ($message) return $message;
    
    $this->db->trans_start();
        
    if ($this->users_model->change_account_type($user_id, 2)) {
        if ($this->users_model->erase_registration_key($user_id, $registration_key)) {
            $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
        } else {
            $message = 'The registration key failed to erase for the user specified!';         
        }
    } else {
        $message = 'The user specified was not able to have his account changed!';
    }
    
    $this->db->trans_complete();
    
    if ($message) return $message;
    
    if ($this->db->trans_status()) { 
        $output_array = array('error' => FALSE, 'message' => 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>');
    } else {
        $output_array = array('error' => TRUE, 'message' => 'The user was not able to be activated. The account specified was not able to be changed into a user!');   
    }
    
    return $output_array;
}

 

Further more I think the HTML should not be in the _remap function.

Link to comment
https://forums.phpfreaks.com/topic/267764-account-activation/#findComment-1373638
Share on other sites

Here comes the tricky part. I looked over the code you gave and used it. I think it does look nicer and cleaner and accomplishes everything still the same way but of the return is it still going to work with how I still have the rest of the controller being used because its supposed to load a view.

 

<?php
if (!defined('BASEPATH')) exit('No direct script acess allowed');

/**
* Activation Controller
* 
* @package KOW Manager
* @author Jeffrey Davidson
* @copyright 2012
* @version 1.0
* @access public
*/
class Activation extends CI_Controller
{
    /**
     * Loads various models needed for parent construct.
     * 
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->model( 'users/users_model' );
    }
    
    /**
     * Accepts the parameters given with the controller and attempts to activate the user from the email link
     * 
     */
    public function _remap()
    {
        $user_id = (int) $this->uri->segment(2);
        $registration_key = $this->uri->segment(3);
        
        if (!((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key)))))) 
        {
            $message = 'One or both parameters were not entered!';
        } 
        else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) 
        {   
            $message = 'The parameters do not meet the validation criteria!';
        }
        
        if (!$this->users_model->is_registered($user_id)) 
        {
            $message = 'The user specified does not exist in the database!';
        }
    
        if ($message) return $message;
        
        if ($user_status_id != 1) 
        {
            $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
        } 
        else if (!$this->users_model->check_user_registration_key($user_id, $registration_key)) 
        {
            $message = 'The registration key did not match the user specified!';
        }
        
        if ($message) return $message;
        
        $this->db->trans_start();
        
        if ($this->users_model->change_account_type($user_id, 2)) 
        {
            if ($this->users_model->erase_registration_key($user_id, $registration_key)) 
            {
                $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
            } 
            else 
            {
                $message = 'The registration key failed to erase for the user specified!';         
            }
        } 
        else 
        {
            $message = 'The user specified was not able to have his account changed!';
        }
    
        $this->db->trans_complete();
        
        if ($message) return $message;
    
        if ($this->db->trans_status()) 
        { 
            $output_array = array('error' => FALSE, 'message' => 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>');
        } 
        else 
        {
            $output_array = array('error' => TRUE, 'message' => 'The user was not able to be activated. The account specified was not able to be changed into a user!');   
        }
    
        return $output_array;
        
        $message_box_messages = array();
        $css_page_addons = '';
        $js_page_addons =  '';
        $meta_tag_addons = '';
        $site_title = 'KOW Manager Account Activation';
        
        $body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/general_message';
        $body_type = 'full';
        
        if (count($message_box_messages) !== 0)
        {
            $message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'messages' => $message_box_messages));
        }
        else
        {
            $message_boxes = array('display' => 'none');
        }
        
        $meta_tags = $this->functions_model->meta_tags();
        
        if (isset($site_title) && (empty($site_title)))
        {
            $site_title = $this->functions_model->site_title();
        }
        
        $this->data['message_boxes'] = $messages_boxes;
        $this->data['css_page_addons'] = $css_page_addons;
        $this->data['js_page_addons'] = $js_page_addons;
        $this->data['js_page_addons'] = $js_page_addons;
        $this->data['body_content'] = $body_content;
        $this->data['body_type'] = $body_type;
        $this->data['meta_tags'] = $meta_tags;
        $this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/index', $this->data );
    }
    
    public function index()
    {
        
    }
}

/* End of file activation.php */
/* Location: ./application/controllers/activation.php */

Link to comment
https://forums.phpfreaks.com/topic/267764-account-activation/#findComment-1374181
Share on other sites

But for some reason though when I go to http://www.kansasoutlawwrestling.com/kowmanager/activation/25/027875e00efgsj454

430699ec0eab4d then it says undefined variable $message on two different lines 48.  Here's the updated code.

 

<?php
if (!defined('BASEPATH')) exit('No direct script acess allowed');

/**
* Activation Controller
* 
* @package KOW Manager
* @author Jeffrey Davidson
* @copyright 2012
* @version 1.0
* @access public
*/
class Activation extends CI_Controller
{
    /**
     * Loads various models needed for parent construct.
     * 
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->model( 'users/users_model' );
    }
    
    /**
     * Accepts the parameters given with the controller and attempts to activate the user from the email link and returns message
     * 
     */
    public function _remap()
    {
        $user_id = (int) $this->uri->segment(2);
        $registration_key = $this->uri->segment(3);
        
        if (!((is_numeric($user_id)) && ((isset($registration_key)) && (!empty($registration_key) && (!is_null($registration_key)))))) 
        {
            $message = 'One or both parameters were not entered!';
        } 
        else if (!(($user_id > 0) && (preg_match('/^[A-Za-z0-9]+$/', $registration_key)))) 
        {   
            $message = 'The parameters do not meet the validation criteria!';
        }
        
        if (!$this->users_model->is_registered($user_id)) 
        {
            $message = 'The user specified does not exist in the database!';
        }
    
        if ($message) return $message;

       $user_status_id = $this->users_model->get_user_status_id($user_id);
        
        if ($user_status_id != 1) 
        {
            $message = 'The user specified is already activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
        } 
        else if (!$this->users_model->check_user_registration_key($user_id, $registration_key)) 
        {
            $message = 'The registration key did not match the user specified!';
        }
        
        if ($message) return $message;
        
        $this->db->trans_start();
        
        if ($this->users_model->change_account_type($user_id, 2)) 
        {
            if ($this->users_model->erase_registration_key($user_id, $registration_key)) 
            {
                $message = 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>';
            } 
            else 
            {
                $message = 'The registration key failed to erase for the user specified!';         
            }
        } 
        else 
        {
            $message = 'The user specified was not able to have his account changed!';
        }
    
        $this->db->trans_complete();
        
        if ($message) return $message;
    
        if ($this->db->trans_status()) 
        { 
            $output_array = array('error' => FALSE, 'message' => 'The user is now activated! You may now proceed to the login page.<br /><br /><a href="' . base_url() . 'login">KOW Manager Login Page</a>');
        } 
        else 
        {
            $output_array = array('error' => TRUE, 'message' => 'The user was not able to be activated. The account specified was not able to be changed into a user!');   
        }
    
        return $output_array;
        
    }
    
    public function index()
    {
        $message_box_messages = array();
        $css_page_addons = '';
        $js_page_addons =  '';
        $meta_tag_addons = '';
        $site_title = 'KOW Manager Account Activation';
        
        $general_message = $this->_remap();
        $body_content = $this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/general_message';
        $body_type = 'full';
        
        if (count($message_box_messages) !== 0)
        {
            $message_boxes = $this->functions_model->build_message_boxes_output(array('display' => 'show', 'messages' => $message_box_messages));
        }
        else
        {
            $message_boxes = array('display' => 'none');
        }
        
        $meta_tags = $this->functions_model->meta_tags();
        
        if (isset($site_title) && (empty($site_title)))
        {
            $site_title = $this->functions_model->site_title();
        }
        
        $this->data['message_boxes'] = $messages_boxes;
        $this->data['css_page_addons'] = $css_page_addons;
        $this->data['js_page_addons'] = $js_page_addons;
        $this->data['js_page_addons'] = $js_page_addons;
        $this->data['body_content'] = $body_content;
        $this->data['body_type'] = $body_type;
        $this->data['meta_tags'] = $meta_tags;
        $this->data['general_message'] = $general_message;
        $this->load->view($this->config->item('themes_path').'/'.$this->config->item('default_theme').'/usermanagement/index', $this->data );
    }
}

/* End of file activation.php */
/* Location: ./application/controllers/activation.php */

Link to comment
https://forums.phpfreaks.com/topic/267764-account-activation/#findComment-1374185
Share on other sites

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.