I'm just trying to see if there's a better way to write the code i between the aestrick characters.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Activate extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/usersmodel');
}
public function index()
{
//Config Defaults Start
$msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
$cssPageAddons = '';//If you have extra CSS for this view append it here
$jsPageAddons = '';//If you have extra JS for this view append it here
$metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
$siteTitle = '';//alter only if you need something other than the default for this view.
//Config Defaults Start
//examples of how to use the message box system (css not included).
//$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');
/**********************************************************Your Coding Logic Here, Start*/
$userID = $this->uri->segment(2);
$registrationKey = $this->uri->segment(3);
if ( ((!is_numeric($userID)) || (is_null($userID))) || ((is_null($registrationKey)) || (!preg_match('/^[A-Za-z0-9]+$/', $registrationKey))) )
{
$bodyContent = $this->config->item('defaultTemplate') ."/404";//which view file
}
else
{
$registrationDetails = $this->usersmodel->getRegistrationDetails($userID);
if (!is_null($registrationDetails))
{
if ($this->usersmodel->activateUser($userID, $registrationKey))
{
$jsPageAddons .= '<script src='.base_url().'assets/'. $this->config->item('defaultTemplate') .'/js/validate/activate.js></script>';
$message = 'User was activated successfully! You may now login!';
$bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
}
else
{
$message = 'User was not activated successfully! Please try again with the right credentials!';
$bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
}
$this->data['message'] = $message;
}
else
{
$bodyContent = $this->config->item('defaultTemplate') ."/404";
}
}
$bodyType = "full";//type of template
/***********************************************************Your Coding Logic Here, End*/
//Double checks if any default variables have been changed, Start.
//If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.
if(count($msgBoxMsgs) !== 0)
{
$msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
}
else
{
$msgBoxes = array('display' => 'none');
}
if($siteTitle == '')
{
$siteTitle = $this->metatags->SiteTitle(); //reads
}
//Double checks if any default variables have been changed, End.
$this->data['msgBoxes'] = $msgBoxes;
$this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
$this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
$this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
$this->data['bodyType'] = $bodyType;
$this->data['bodyContent'] = $bodyContent;
$this->load->view($this->config->item('defaultTemplate') .'/usermanagement/index', $this->data);
}
}
/* End of file activate.php */
/* Location: ./application/controllers/activate.php */
UPDATE:
Here's my update tell me what you think now?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Activate extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/usersmodel');
}
public function index()
{
//Config Defaults Start
$msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
$cssPageAddons = '';//If you have extra CSS for this view append it here
$jsPageAddons = '';//If you have extra JS for this view append it here
$metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
$siteTitle = '';//alter only if you need something other than the default for this view.
//Config Defaults Start
//examples of how to use the message box system (css not included).
//$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');
/**********************************************************Your Coding Logic Here, Start*/
$userID = $this->uri->segment(2);
$registrationKey = $this->uri->segment(3);
if( ! $this->verify( $userID, $registrationKey ) )
{
$bodyContent = $this->kow->return404();
}
else
{
if ( ! isRegistered( $userID ))
{
$message = 'User was not registered successfully! Please try again with the right credentials!';
if ($this->usersmodel->activateUser($userID, $registrationKey))
{
$jsPageAddons .= '<script src='.base_url().'assets/'. $this->config->item('defaultTemplate') .'/js/validate/activate.js></script>';
$message = 'User was activated successfully! You may now login!';
}
$bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
$this->data['message'] = $message;
}
else
{
$bodyContent = $this->kow->return404();
}
}
$bodyType = "full";//type of template
/***********************************************************Your Coding Logic Here, End*/
//Double checks if any default variables have been changed, Start.
//If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.
if(count($msgBoxMsgs) !== 0)
{
$msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
}
else
{
$msgBoxes = array('display' => 'none');
}
if($siteTitle == '')
{
$siteTitle = $this->metatags->SiteTitle(); //reads
}
//Double checks if any default variables have been changed, End.
$this->data['msgBoxes'] = $msgBoxes;
$this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
$this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
$this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
$this->data['bodyType'] = $bodyType;
$this->data['bodyContent'] = $bodyContent;
$this->load->view($this->config->item('defaultTemplate') .'/usermanagement/index', $this->data);
}
private function verify( $userID, $registrationKey )
{
if( ! $userID || ! is_numeric( $userID ) )
{
return false;
}
$matches = preg_match('/^[A-Za-z0-9]+$/', $registrationKey);//You should comment this to explain what it does
if ( ! $registrationKey || ! $matches )
{
return false;
}
return TRUE;
}
}
/* End of file activate.php */
/* Location: ./application/controllers/activate.php */
FINAL UPDATE
Hopefully. Please do one final look over for me please.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Activate extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/usersmodel');
}
public function index()
{
//Config Defaults Start
$msgBoxMsgs = array();//msgType = dl, info, warn, note, msg
$cssPageAddons = '';//If you have extra CSS for this view append it here
$jsPageAddons = '';//If you have extra JS for this view append it here
$metaAddons = '';//Sometimes there is a need for additional Meta Data such in the case of Facebook addon's
$siteTitle = '';//alter only if you need something other than the default for this view.
$message = '';
//Config Defaults Start
//examples of how to use the message box system (css not included).
//$msgBoxMsgs[] = array('msgType' => 'dl', 'theMsg' => 'This is a Blank Message Box...');
/**********************************************************Your Coding Logic Here, Start*/
$userID = $this->uri->segment(2);
$registrationKey = $this->uri->segment(3);
$bodyContent = $this->kow->return404();
if( $this->verify( $userID, $registrationKey ) )
{
if ( ! isRegistered( $userID ))
{
$message = 'User was not registered successfully! Please try again with the right credentials!';
if ($this->auth->activateUser($userID, $registrationKey))
{
$jsPageAddons .= '<script src='.base_url().'assets/'. $this->config->item('defaultTemplate') .'/js/validate/activate.js></script>';
$message = 'User was activated successfully! You may now login!';
}
$bodyContent = $this->config->item('defaultTemplate') ."/usermanagement/forms/activate";//which view file
}
}
$bodyType = "full";//type of template
/***********************************************************Your Coding Logic Here, End*/
//Double checks if any default variables have been changed, Start.
//If msgBoxMsgs array has anything in it, if so displays it in view, else does nothing.
if(count($msgBoxMsgs) !== 0)
{
$msgBoxes = $this->msgboxes->buildMsgBoxesOutput(array('display' => 'show', 'msgs' =>$msgBoxMsgs));
}
else
{
$msgBoxes = array('display' => 'none');
}
if($siteTitle == '')
{
$siteTitle = $this->metatags->SiteTitle(); //reads
}
//Double checks if any default variables have been changed, End.
$this->data['message'] = $message;
$this->data['msgBoxes'] = $msgBoxes;
$this->data['cssPageAddons'] = $cssPageAddons;//if there is any additional CSS to add from above Variable this will send it to the view.
$this->data['jsPageAddons'] = $jsPageAddons;//if there is any addictional JS to add from the above variable this will send it to the view.
$this->data['siteTitle'] = $siteTitle;//defaults can be changed via models/metatags.php
$this->data['bodyType'] = $bodyType;
$this->data['bodyContent'] = $bodyContent;
$this->load->view($this->config->item('defaultTemplate') .'/usermanagement/index', $this->data);
}
private function verify( $userID, $registrationKey )
{
if( ! $userID || ! is_numeric( $userID ) )
{
return false;
}
$matches = preg_match('/^[A-Za-z0-9]+$/', $registrationKey);//You should comment this to explain what it does
if ( ! $registrationKey || ! $matches )
{
return false;
}
return true;
}
}
/* End of file activate.php */
/* Location: ./application/controllers/activate.php */