2017-01-15 16 views
1

にプロセスを登録するためのトークンを右登録プロセスの後にパスワードを設定することが示されたリンクがあります: http://website.de/main/complete/token/MTkyYTBiY2EyNWE2ZDYwOTdhN2U4NjJkMjZmYzYyNTAPHP CodeIgniterのURLのルーティング:URL

は、問題は、私は、登録プロセスを完了するために、このページを表示することができないです。

誰かがヒントを持っていますか?

 public function complete() 
     {         
     $token = base64_decode($this->uri->segment(4));  
     $cleanToken = $this->security->xss_clean($token); 

     $user_info = $this->user_model->isTokenValid($cleanToken); //either false or array();   

     if(!$user_info){ 
      $this->session->set_flashdata('flash_message', 'Token is invalid or expired'); 
      redirect(base_url().'login'); 
     }    
     $data = array(
      'firstName'=> $user_info->first_name, 
      'email'=>$user_info->email, 
      'user_id'=>$user_info->id, 
      'token'=>$this->base64url_encode($token) 
     ); 

     $this->form_validation->set_rules('password', 'Password', 'required|min_length[5]'); 
     $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required|matches[password]');    

     if ($this->form_validation->run() == FALSE) { 
      $this->load->view('header'); 
      $this->load->view('complete', $data); 
      $this->load->view('footer'); 
     }else{ 

      $this->load->library('password');     
      $post = $this->input->post(NULL, TRUE); 

      $cleanPost = $this->security->xss_clean($post); 

      $hashed = $this->password->create_hash($cleanPost['password']);     
      $cleanPost['password'] = $hashed; 
      unset($cleanPost['passconf']); 
      $userInfo = $this->user_model->updateUserInfo($cleanPost); 

      if(!$userInfo){ 
       $this->session->set_flashdata('flash_message', 'There was a problem updating your record'); 
       redirect(base_url().'login'); 
      } 

      unset($userInfo->password); 

      foreach($userInfo as $key=>$val){ 
       $this->session->set_userdata($key, $val); 
      } 
      redirect(base_url()); 

     } 
    } 


    public function register() 
    { 

     $this->form_validation->set_rules('firstname', 'First Name', 'required'); 
     $this->form_validation->set_rules('lastname', 'Last Name', 'required');  
     $this->form_validation->set_rules('email', 'Email', 'required|valid_email');  

     if ($this->form_validation->run() == FALSE) { 
      $this->load->view('header'); 
      $this->load->view('register'); 
      $this->load->view('footer'); 
     }else{     
      if($this->user_model->isDuplicate($this->input->post('email'))){ 
       $this->session->set_flashdata('flash_message', 'User email already exists'); 
       redirect(base_url().'login'); 
      }else{ 

       $clean = $this->security->xss_clean($this->input->post(NULL, TRUE)); 
       $id = $this->user_model->insertUser($clean); 
       $token = $this->user_model->insertToken($id);           

       $qstring = $this->base64url_encode($token);      
       $url = base_url() . 'complete/token/' . $qstring; 
       $link = '<a href="' . $url . '">' . $url . '</a>'; 

       $message = '';      
       $message .= '<strong>You have signed up with our website</strong><br>'; 
       $message .= '<strong>Please click:</strong> ' . $link;       
       echo $message; //send this in email 
       exit; 


      };    
     } 
    } 

モデル機能:あなたが何をしたいか

public function insertToken($user_id) 
    { 
    $token = substr(sha1(rand()), 0, 30); 
    $date = date('Y-m-d'); 

    $string = array(
      'token'=> $token, 
      'user_id'=>$user_id, 
      'created'=>$date 
     ); 
    $query = $this->db->insert_string('tokens',$string); 
    $this->db->query($query); 
    return $token . $user_id; 

} 

public function isTokenValid($token) 
{ 
    $tkn = substr($token,0,30); 
    $uid = substr($token,30);  

    $q = $this->db->get_where('tokens', array(
     'tokens.token' => $tkn, 
     'tokens.user_id' => $uid), 1);       

    if($this->db->affected_rows() > 0){ 
     $row = $q->row();    

     $created = $row->created; 
     $createdTS = strtotime($created); 
     $today = date('Y-m-d'); 
     $todayTS = strtotime($today); 

     if($createdTS != $todayTS){ 
      return false; 
     } 

     $user_info = $this->getUserInfo($row->user_id); 
     return $user_info; 

    }else{ 
     return false; 
    } 

}  
+0

あなたは実際に「探している」方法で何をしましたか? – TimBrownlaw

+0

routes.phpでコントローラとメソッドを表示するために異なるパスを試しましたが、動作しませんでした。 – Ifloop

答えて

0

は、ユーザーが正常に登録した後、ある、ショー私はすでにそれのために2時間...

コントローラ機能するので探しています彼/彼女の登録の権利を完了するURL?

限り、私は問題を理解して、あなたのコントローラで

$message = '';      
$message .= '<strong>You have signed up with our website</strong><br>'; 
$message .= '<strong>Please click:</strong> ' . $link; 

$data = array(
       'message' => $message 
     ); 

$this->load->view('header'); 
$this->load->view('complete', $data); 
$this->load->view('footer'); 

、次のように行うと、complete.php

<html> 
<head> 
<title></title> 
</head> 
<body> 
    <h1><?php echo $message;?></h1> 
</body> 
</html> 

というビューを作成することができますビューに動的データを追加する - https://www.codeigniter.com/userguide2/general/views.html

+0

私はそれをやってくれてありがとう。 – Ifloop

関連する問題