2013-11-12 3 views
-1

В приведенном ниже коде я использовал код codeigniter. Я вводил имя пользователя и пароль в db.but. Я хочу получить забытый пароль. Я попытался, но у меня появились следующие ошибки.Чтобы получить забыли пароль

Контроллер:

<?php 

class Login extends CI_Controller { 

    function index() 
    { 
     $data['main_content'] = 'login_form'; 
     $this->load->view('includes/template', $data);  
    } 

    function validate_credentials() 
    {  
     $this->load->model('membership_model'); 
     $query = $this->membership_model->validate(); 

     if($query) // if the user's credentials validated... 
     { 
      $data = array(
       'username' => $this->input->post('username'), 
       'is_logged_in' => true 
      ); 
      $this->session->set_userdata($data); 
      redirect('site1/members_area'); 
     } 
     else // incorrect username or password 
     { 
      $this->index(); 
     } 
    } 

    function signup() 
    { 
     $data['main_content'] = 'signup_form'; 
     $this->load->view('includes/template', $data); 
    } 

    function create_member() 
    { 
     $this->load->library('form_validation'); 

     // field name, error message, validation rules 
     $this->form_validation->set_rules('first_name', 'Name', 'trim|required'); 
     $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required'); 
     $this->form_validation->set_rules('email_address', 'Email Address', 'trim|required|valid_email'); 
     $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]'); 
     $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]'); 
     $this->form_validation->set_rules('password2', 'Password Confirmation', 'trim|required|matches[password]'); 
     $this->load->helper('date'); 

     if($this->form_validation->run() == FALSE) 
     { 
      $this->load->view('signup_form'); 
     } 

     else 
     {   
      $this->load->model('membership_model'); 

      if($query = $this->membership_model->create_member()) 
      { 
       $data['main_content'] = 'signup_successful'; 
       $this->load->view('includes/template', $data); 
      } 
      else 
      { 
       $this->load->view('signup_form');   
      } 
     } 

    } 
    public function forgot_password() 
{ 
    $this->form_validation->set_rules('email_address','Email Address','trim|required|valid_email|callback__check_email_exists'); 

    if($this->form_validation->run() == FALSE) 
    { 
     // VALIDATION ERRORS, SHOW VIEWS 
     $this->index(); 
    } 
    else 
    { 
     // ALL IS GOOD, UPDATE EMAIL, AND REDIRECT TO CURRENT URL 
     $this->load->view('login_form'); 
    } 
} 
public function _check_email_exists($email) 
{ 
    // LOAD AND USE YOUR MODEL TO CHECK EMAIL EXISTS HERE 
    if (! $email_exists) 
    { 
    $this->form_validation->set_message('email_address', 'That email address don\'t exist, sucka!'); 
    return FALSE; 
    } 
    else 
    { 
    return TRUE; 
    } 
} 
    function logout() 
    { 
     $this->session->sess_destroy(); 
     $this->index(); 
    } 

} 

модель

<?php 

class Membership_model extends CI_Model { 

    function validate() 
    { 
     $this->db->where('username', $this->input->post('username')); 
     $this->db->where('password', md5($this->input->post('password'))); 
     $query = $this->db->get('membership'); 

     if($query->num_rows == 1) 
     { 
      return true; 
     } 

    } 

    function create_member() 
    { 

     $new_member_insert_data = array(
      'first_name' => $this->input->post('first_name'), 
      'last_name' => $this->input->post('last_name'), 
      'email_address' => $this->input->post('email_address'),   
      'username' => $this->input->post('username'), 
      'date' => date('Y-m-d H:i:s', now()), 
      'password' => md5($this->input->post('password'))      
     ); 

     $insert = $this->db->insert('membership', $new_member_insert_data); 
     if ($this->db->_error_number() == 1062) 
       { 
       echo"<script>alert('This value already exists');</script>"; 
       } 
       if ($this->db->_error_number() == "") 
       { 
       $this->session->set_flashdata('create', 'create'); 
       } 

     return $insert; 
    } 


    public function val_forgot_password() 
{ 
    $this->db->where('email_address', $this->input->post('email_address')); 
    $query = $this->db->get($this->members); 

    if($query->num_rows == 1) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 
    function curdate() { 
    // gets current timestamp 
    date_default_timezone_set('Asia/Manila'); // What timezone you want to be the default value for your current date. 
    return date('Y-m-d H:i:s'); 
} 
} 

вид: login_form

<?php $this->load->view('includes/header'); ?> 
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style1.css" /> 
<div id="login_form"> 

    <h1>Login!</h1> 
    <?php 
    echo form_open('login/validate_credentials'); 
    echo form_input('username', 'Username'); 
    echo form_password('password', 'Password'); 
    echo form_submit('submit', 'Login'); 
    echo anchor('login/signup', 'Create Account'); 
    echo form_close(); 
    ?> 

</div><!-- end login_form--> 


<?php $this->load->view('includes/footer'); ?> 
<?php 

echo form_open('login/forgot_password'); 
echo "Email Address: " . form_input('email_address', set_value('email_address', '')); 
echo br(2); 
echo form_submit('submit','Send Email'); 
echo form_close(); 
echo br(1); 

echo validation_errors('<p>Error: '); 

?> 

ответ

0

Ну прежде всего вам потребуется функция в контроллере, чтобы привести пользователя к забыли пользовательская страница.

public function forgot_pass(){ 
$this->load->view('forgot_pass_view'); 
} 

Тогда вам, вероятно, потребуется задать по крайней мере адрес электронной почты в представлении. Создайте еще одну функцию, чтобы проверить адрес электронной почты в контроллере, и если он совпадает с отправкой почты с новым временным паролем.

public function check_email(){ 
    $this->load->helper(array('form', 'url')); 
    $this->load->library('form_validation'); 
    $this->form_validation->set_rules('email', 'email_check', 'callback_email_check'); 
    if ($this->form_validation->run() == FALSE){ 
    //throw error 
    } else { 
    //send email 
    } 
} 
public function email_check(){ 
    //use this function to check if the email exists and return false if it is not the DB 
} 
Смежные вопросы