Welcome Guest, Not a member yet? Register   Sign In
Activation Routes
#1

[eluser]xtremer360[/eluser]
After a user registers on my site they are sent an email containing a link to my activation controller. The link comprises of the siteurl.com/activation/$user_id/$activation_key. I'm trying to figure out if these are the proper routes I need for the activation page. I also included what the index function line starts with?

Code:
$route['activation/(:num)/(:any)'] = 'activation/index/$1/$2';
$route['activation/(:num)'] = 'activation/index/$1';
$route['activation'] = 'activation';

Code:
public function index( $user_id = NULL, $registration_key = NULL )
#2

[eluser]PhilTem[/eluser]
As long as you got a controller called activation it would be easier to do the following:

routes:
don't alter

controller 'activation'
Code:
class Activation extends CI_Controller {
  function _remap()
  {
    $user_id = $this->uri->segment(2);
    $activation_key = $this->uri->segment(3);
    
    // do your activation stuff here ;)
  }
}
#3

[eluser]xtremer360[/eluser]
But if the activation is good then I want it to display a view though.
#4

[eluser]xtremer360[/eluser]
Here's my new updated Activation controller. Verify that the remap looks good and what I want is display a view with a specified message regardless of if it was good or not.

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

class Activation extends CI_Controller {

function __construct()
{
        parent::__construct();
        $this->load->model('users/users_model');
}

    private function _remap()
    {
        $user_id = $this->uri->segment(2);
        $registration_key = $this->uri->segment(3);
        
        $this->error = FALSE;
        
        if ( ( $user_id !== NULL ) && ( $registration_key !== NULL ) )
        {
            
            if ( ( isset( $user_id )) && ( ( trim( $user_id ) !== '' ) || ( !empty( $user_id ) ) ) )
            {
                if ( !is_numeric( $user_id ) )
                {
                    $this->error = TRUE;
                }
            }
            
            if ( ( isset( $registration_key ) ) && ( ( trim( $registration_key ) !== '' ) || ( !empty( $registration_key ) ) ) )
            {
                if ( !preg_match( '/^[A-Za-z0-9]+$/', $registration_key ) )
                {
                    $this->error = TRUE;
                }
            }
        }      
    }
    
    public function index( $user_id = NULL, $registration_key = NULL )
{
  $msgBoxMsgs = array();
  $cssPageAddons = '';
  $jsPageAddons =  '[removed][removed][removed][removed][removed][removed][removed][removed]';
  $metaAddons = '';
  $siteTitle = 'KOW Manager Account Activation';
        
        $bodyContent = $this->error ? show_404() : '/usermanagement/forms/activation_form';
        $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);
}
    
}

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

[eluser]PhilTem[/eluser]
Yeah, you almost got it correctly Wink

However, you might want to take an even closer look at this user's guide topic
http://codeigniter.com/nightly_user_guid...tion-calls
describing the usage and idea behind the _remap() method.

Basically, all you would need to do is putting you index()-method code inside the _remap()-method.
#6

[eluser]xtremer360[/eluser]
That's great. Are you sure this is all I needed to do?

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

class Activation extends CI_Controller {

function __construct()
{
        parent::__construct();
        $this->load->model('users/users_model');
}

    private function _remap()
    {
        $user_id = $this->uri->segment(2);
        $registration_key = $this->uri->segment(3);
        
        $this->error = FALSE;
        
        if ( ( $user_id !== NULL ) && ( $registration_key !== NULL ) )
        {
            
            if ( ( isset( $user_id )) && ( ( trim( $user_id ) !== '' ) || ( !empty( $user_id ) ) ) )
            {
                if ( !is_numeric( $user_id ) )
                {
                    $this->error = TRUE;
                }
            }
            
            if ( ( isset( $registration_key ) ) && ( ( trim( $registration_key ) !== '' ) || ( !empty( $registration_key ) ) ) )
            {
                if ( !preg_match( '/^[A-Za-z0-9]+$/', $registration_key ) )
                {
                    $this->error = TRUE;
                }
            }
        }
        
        $msgBoxMsgs = array();
  $cssPageAddons = '';
  $jsPageAddons =  '[removed][removed][removed][removed][removed][removed][removed][removed]';
  $metaAddons = '';
  $siteTitle = 'KOW Manager Account Activation';
        
        $bodyContent = $this->error ? show_404() : '/usermanagement/forms/activation_form';
        $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 index( )
{
  
}
    
}

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

[eluser]PhilTem[/eluser]
I'm like 99.9999% sure it will work - assuming your code for activation is correct Wink
#8

[eluser]xtremer360[/eluser]
So what I"m trying to do is with the general message is have it display a message for each reason why it could or could not be validated with the two paramters. In my general_message view I have a <?php echo $message ?> that I need passed. Also at this point if one of the parameters or both of them are not included in the url it does not show the error page. Any ideas why?

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

class Activation extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }
    
    public function _remap()
    {
        $user_id = $this->uri->segment( 2 );
        $registration_key = $this->uri->segment( 3 );
        
        $this->error = FALSE;
        if ( ( $user_id !== NULL ) && ( $registration_key !== NULL ) )
        {
            if ( ( isset ( $user_id ) ) && ( ( trim( $user_id ) !== '' ) || ( !empty( $user_id ) ) ) )
            {
                if ( !is_numeric( $user_id ) )
                {
                    $this->error = TRUE;
                }
            }
            
            if ( ( isset ( $registration_key ) ) && ( ( trim( $registration_key ) !== '' ) || ( !empty( $registration_key ) ) ) )
            {
                if ( !preg_match( '/^[A-Za-z0-9]+$/', $registration_key ) )
                {
                    $this->error = TRUE;
                }
            }
        }
        
        $msgBoxMsgs = array();
        $cssPageAddons = '';
        $jsPageAddons = '';
        $metaAddons = '';
        $siteTitle = 'KOW Manager Account Activation';
        
        $bodyContent = $this->error ? show_404() : 'usermanagement/general_message';
        $bodyType = 'full';
        
        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', 'bodyContent', 'bodyType' );
        $this->load->view('usermanagement/index', $this->data);      
    }
    
    public function index()
    {
        
    }
}

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

[eluser]xtremer360[/eluser]
Any ideas from anyone?




Theme © iAndrew 2016 - Forum software by © MyBB