Updated:
RJZ:
TdjxQetc is the $activateCode that comes from the DB so when I run /confirm/ I should be getting Sorry you did not have a correct Activation Code as I am not passing in any var ($activateCode) but when I run /confirm/$activateCode I should get Thanks your account is now active you may login! and with the else statement
I am thinking that it should be changed and a new model function developed to check if userActive has been set to 1 and then display another $message so that the link can only be used.
View:
<div class = "messages">
<?php if($confirmMessage != ''): ?>
<?php if($confirmError): ?>
<p class="error">
<?php echo $confirmMessage; ?>
</p>
<?php else: ?>
<p class="message">
<?php $confirmMessage?>
</p>
<?php endif; ?>
<?php endif; ?>
</div>
Controller:
function confirm(){
$activateCode = $this->uri->segment(3);
$error = FALSE;
$message = '';
if($activateCode == '')
{
$error = TRUE;
$message = 'Sorry you did not have a correct Activation Code.';
}
$userConfirmed = $this->users_model->confirm_user($activateCode);
if($userConfirmed){
$message = 'Thanks your account is now active you may login!';
}else{
$error = TRUE;
$message = 'I am sorry we do not have any details with that Activation Code';
}
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['pageTitle'] = "User Confirm";
$data['confirmError'] = $error;
$data['confirmMessage'] = $message;
$this->load->view('frontend/assets/header', $data);
$this->load->view('frontend/user_confirm', $data);
$this->load->view('frontend/assets/footer');
}
I am unsure why I am not getting the validation messages, I just get my view. The database is updating to 1.
View:
<h1><?php echo $companyName; echo nbs(1);?> - <?php echo $pageTitle; ?></h1>
<p>Error: <?php echo validation_errors();?></p>
Controller:
function confirm(){
$activateCode = $this->uri->segment(3);
if($activateCode == '')
{
$this->form_validation->set_message('userConfirmError', 'Sorry you did not have a correct Activation Code.');
}
$userConfirmed = $this->users_model->confirm_user($activateCode);
if($userConfirmed){
$this->form_validation->set_message('userConfirmed', 'Thanks your account is now active you may login!');
}else{
$this->form_validation->set_message('userRecord', 'I am sorry we do not have any details with that Activation Code');
}
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['pageTitle'] = "User Confirm";
$this->load->view('frontend/assets/header', $data);
$this->load->view('frontend/user_confirm', $data);
$this->load->view('frontend/assets/footer');
}
Confirm Function:
function confirm_user($activateCode)
{
//Selects the userID where the given URI activateCode = ?
$this->db->select('userID');
$this->db->from('users');
$this->db->where('userActiveCode', $activateCode);
$result = $this->db->get();
if($result->num_rows == 1) // If the above result is = 1 then update the userActive row else it will fail
{
$this->db->set('userActive', 1);
$this->db->where('userActiveCode', $activateCode);
return TRUE;
}else{
return FALSE;
}
Core Model:
function companyDetails()
{
static $details;
if(!$details)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$details = $this->db->get('core')->first_row();
}
return $details;
}