EllisLab text mark
Advanced Search
1 of 2
1
   
Confirmation Activation (e-mail)
Posted: 14 August 2011 01:49 PM
Joined: 2011-08-10
18 posts

i’m at my final step in processing my registration form. I’m at the part where a e-mail is sent and the only way to activate the account is to click on the link. Once clicked i would run a function where it looks for a scrambled code at the end of the url and match it with the one in the database. Once confirmed i would set my activated field to 1 (default as 0). I tried something which makes logical sense to me but it doesn’t seem to change my activated field into 1. any ideas? i dont get any error. key function to look into are
function account_activation—>controller and function confirm_registration—> model
Controller

function register(){
        
            $this
->load->library('form_validation');
            
            
$this->form_validation->set_rules('username''Username''required|min_length[5]|max_length[12]|xss_clean|callback_dbcheck');
            
$this->form_validation->set_rules('name''Name''required|min_length[3]|max_length[20]|xss_clean');
            
$this->form_validation->set_rules('email''E-mail''required|min_length[3]|max_length[20]|xss_clean|valid_email');
            
$this->form_validation->set_rules('password''Password''required|min_length[3]|max_length[20]|xss_clean');
            
$this->form_validation->set_rules('password_conf''Re-type Password''required|min_length[3]|max_length[20]|xss_clean|matches[password]');
    
            if (
$this->form_validation->run() == FALSE{
            
                $this
->load->view('viewregister');
            
}
                
else {
                $username 
$this->input->post('username');
                
$name $this->input->post ('name');
                
$email $this->input->post ('email');
                
$password $this->input->post ('password');
                
                
$activation_code $this->random_string(10);
                
                
$this->Usermodel->register_user($username,$name$email$password$activation_code); 
                
                
// send e-mail verification
                
                
$this->load->library('email');
                
$this->email->from('bingo@gmail.com''al');
                
$this->email->to($email);
                
$this->email->subject('Registration Confirmation');
                
$this->email->message('Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/confirmation_activation/' $activation_code,'Confirmation Register'));
                
//$this->email->send();
                
echo 'Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/account_activation/' $activation_code,'Confirmation Register');
            
//    echo " you have been registered $username";
                
            
}
        }
        
        
function account_activation() {
            $register_code 
$this->url->segment(3);
            if (
$register_code == '')    {
                
                
echo 'errpr no registration code in URL';
                exit();
            
}
            $reg_confirm 
$this->usermodel->confirm_registration($register_code);
            
$this->output->enable_profiler(1);
            if(
$reg_confirm)    {
                
echo 'You have registered into our syster';
            
}
            
else {
                
echo 'you have failed to register';
            
}
            
        } 

Model

function confirm_registration ($register_code)    {
            
            $val_code 
"SELECT id from tbregister where activationcode = ?";
            
$result $this->db->query($val_code$register_code);
            
            if (
$result->num_rows() == 1{
                
            $update_activated 
"UPDATE `tbregister` SET activated = 1 WHERE activationcode = ?";
        
            
$this->db->query($update_activated$register_code);
            
            return 
TRUE;
            
}
            
else {
                
return FALSE;
            
}
            
        } 
 
Posted: 14 August 2011 03:23 PM   [ # 1 ]   [ Rating: 1 ]
Joined: 2011-08-07
41 posts

The link in the email you are sending out is pointing to /user/confirmation_activation but your function is called account_activation. The echo is correct, but the email message is not.

in the anchor call, change confirmation_activation to account_activation

$this->email->message('Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/account_activation/' $activation_code,'Confirmation Register'));
                
//$this->email->send();
                
echo 'Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/account_activation/' $activation_code,'Confirmation Register'); 
 
Posted: 14 August 2011 04:42 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2011-08-10
18 posts

good eye, i corrected that error but i still get the same thing. anything else which doesn’t seem right?

 
Posted: 14 August 2011 05:19 PM   [ # 3 ]   [ Rating: 0 ]
Joined: 2011-08-06
241 posts

I see you have $this->output->enable_profiler(1); there, but have you actually used it to check the query formats in your function to ensure they are properly formatted to actually run?

 Signature 

Create Dynamic Popups with Jquery

 
Posted: 14 August 2011 10:42 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2011-08-10
18 posts

i plugged it into this function but i got no output, like nothing showed, its like that line of script didnt exist. what did i do wrong?

function account_activation() {
                
            $register_code 
$this->url->segment(3);
            if (
$register_code == '')    {
                
                
echo 'errpr no registration code in URL';
                exit();
            
}
            $reg_confirm 
$this->usermodel->confirm_registration($register_code);
            
$this->output->enable_profiler(1);
            if(
$reg_confirm)    {
                
echo 'You have registered into our syster';
            
}
            
else {
                
echo 'you have failed to register';
            
}
            
        } 
 
Posted: 14 August 2011 11:31 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-08-06
241 posts

Try putting it at the beginning of the function.. also take out the 1.. and see if you get any output then…

 Signature 

Create Dynamic Popups with Jquery

 
Posted: 14 August 2011 11:49 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-08-10
18 posts

I tried both of your suggestions and still no luck. what do you think happened?

 
Posted: 15 August 2011 06:25 AM   [ # 7 ]   [ Rating: 0 ]
Joined: 2010-12-23
254 posts

You have too much something when you used the anchor function

$this->email->message('Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/confirmation_activation/' $activation_code,'Confirmation Register'));
                
//$this->email->send();
                
echo 'Click the link below to activate your account' anchor('http://localhost/codetwo/index.php/user/account_activation/' $activation_code,'Confirmation Register'); 

it should just be

$this->email->message('Click the link below to activate your account' anchor('user/confirmation_activation/' $activation_code,'Confirmation Register'));
                
//$this->email->send();
echo 'Click the link below to activate your account' anchor('user/account_activation/' $activation_code,'Confirmation Register'); 
 Signature 

Half the battle is won by following The User Guide. cool grin

 
Posted: 15 August 2011 10:46 AM   [ # 8 ]   [ Rating: 0 ]
Joined: 2011-08-10
18 posts

wait i just realized i put the wrong directory in the anchor. i have changed that and now it goes to the function account_activation but i get a error on line 57

Line 57

$register_code $this->url->segment(3); 
function account_activation() {
        
//    $this->output->enable_profiler(1);
            
$register_code $this->url->segment(3);
            if (
$register_code == '')    {
                
                
echo 'errpr no registration code in URL';
                exit();
            
}
            $reg_confirm 
$this->usermodel->confirm_registration($register_code);
            
            if(
$reg_confirm)    {
                
echo 'You have registered ';
            
}
            
else {
                
echo 'you have failed to register';
            
}
            
        } 
 
Posted: 15 August 2011 12:17 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2011-08-07
41 posts

url should be uri

$register_code $this->uri->segment(3); 
 
Posted: 15 August 2011 12:23 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2011-08-10
18 posts

perfect it works, i was wondering would it be possible to use localhost to send out a e-mail and test it? can someone send me a link to how this would be done.


Thanks to everyone who helped!!!

 
Posted: 15 August 2011 10:43 PM   [ # 11 ]   [ Rating: 0 ]
Joined: 2010-12-23
254 posts

Yes, actually you can send emails using your local apache server because ironically, you are using an apache server. You must first set the smtp server that handling your email sending. You can read the email class in the user_guide

 Signature 

Half the battle is won by following The User Guide. cool grin

 
Posted: 21 November 2011 12:06 AM   [ # 12 ]   [ Rating: 0 ]
Joined: 2011-11-21
14 posts

hello,
i’m new in codeigniter. i am trying to put some activation member by confirmation in email.

i used the above code, but i got a fatal error : call to undefined user::random_string(); so, what i should do?

 
Posted: 21 November 2011 03:51 AM   [ # 13 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

Load the ‘string’-helper with

$this->load->helper('string'); 

wink

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 21 November 2011 04:42 AM   [ # 14 ]   [ Rating: 0 ]
Joined: 2011-11-21
14 posts

i have put the strill caller code, but it still the same. here’s my code :

this is the controller.

function add(){
  $webconfig 
$this->config->item('webconfig');  
  
$ldata $fdata $tdata = array();
  require_once(
dirname(__FILE__).'/../libraries/formvalidator.php');
  
   
$validator = new FormValidator();
      
$validator->addValidation("name","req","Please insert user fullname.");
      
$validator->addValidation("username","req","Please insert username.");
      
$validator->addValidation("password","req","Please insert password.");
   
$validator->addValidation("password","minlen=5","Password must contain min 5 character.");
      
$validator->addValidation("password_1","req","Please retype above password for validation.");
      
$validator->addValidation("password_1","eqelmnt=password","Please type same value above.");
   
$validator->addValidation("email","req","Please input email.");
   
$validator->addValidation("email","email","Please input email.");
      if(
$validator->ValidateForm())
      
{
          $doInsert 
$this->UserModel->entriData(array(
                      
'name'=>$this->input->post('name')
                      ,
'username'=>$this->input->post('username')
                      ,
'password'=>$this->input->post('password')
                ,
'email'=>$this->input->post('email')
                ));
    if(
$doInsert == 'exist'){
     $tdata[
'error_hash'= array('error' => 'Username is already exist in our database, choose another username.');
    
}else if($doInsert == 'failed'){
     $tdata[
'error_hash'= array('error' => 'Sorry, there is error in our database system.');
    
}else if($doInsert == 'empty'){
     $tdata[
'error_hash'= array('error' => 'Please corect your entri.');
    
}else if($doInsert == 'success'){
     
     
// send e-mail verification
     
$this->load->helper('string'); 
     
$activation_code $this->random_string(10);
     
     
//$this->Usermodel->register_user($username,$name, $email, $password, $activation_code);
    
                
require_once(dirname(__FILE__).'/../libraries/PHPMailer_v5.1/class.phpmailer.php');
    
$mail = new PHPMailer();
                
$mail->IsSMTP(); 
    
$mail->Host     'ssl://smtp.gmail.com';
    
$mail->Port       465;                    // set the SMTP port for the GMAIL server
    
$mail->SMTPAuth true
    
$mail->Username "";                     //untuk meng-inputkan accout gmail yang akan digunakan
    
$mail->Password "";                                   //untuk meng-inputkan password accout gmail yang akan digunakan
    
$mail->AddReplyTo(''''); //untuk men-definiskan alamat & nama reply email
    
$mail->SetFrom('''');
    
$mail->Subject "Email Activation";
    
$mail->MsgHTML($this->load->view('bodyemail'$tdatatrue));
    
$text_body  "Click the link below to activate your account' . anchor('user/confirmation_activation/' . $activation_code,'Confirmation Register')";
    
$mail->AltBody $text_body;
    
$mail->AddAddress($this->input->post('email'));
   
    if(!
$mail->Send()){
     $tdata[
'error_hash'= array('error' => 'Maaf, telah terjadi kesalahan dalam sistem kami. Silahkan coba lagi beberapa saat lagi.');
    
}else{
     $tdata[
'success'"Terimakasih, email kepada teman Anda telah kami kirimkan.";
    
}
    
// Clear all addresses and attachments for next loop
    
$mail->ClearAddresses();
    
$mail->ClearAttachments();
            
    
}  
      }
      
else
      

          $tdata[
'name']     $this->input->post('name');
       
$tdata['username'$this->input->post('username');
       
$tdata['password'$this->input->post('password');
       
$tdata['password_1'$this->input->post('password_1');
    
$tdata['email'$this->input->post('email');
       
$tdata['error_hash'$validator->GetErrors();
    
                
                
      
}
   $this
->load->view("result"$tdata);
  

So now, can anyone help me in fixing this ? the error report after submit is : Fatal error: Call to undefined method User::random_string()

thank you

 
Posted: 21 November 2011 05:00 AM   [ # 15 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

‘random_string()’ is provided as a function not a method so you call it simply by using

$string random_string('alnum'10); // or whatever config you need for the function call 

That should fix your problem wink

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
1 of 2
1