1

我正在为我工​​作的公司开发一个网站。它需要用户注册并登录。所有数据都存储在 SQL 数据库中。我正在尝试添加一个“丢失的用户名”表单,以便通过电子邮件恢复用户名。现在......我不是编码员。我只是一个相当有天赋的代码浏览器。我已经成功完成了他们要求的所有事情,除了这个,并且不能完全弄清楚为什么它不起作用。我想是时候寻求一些帮助了。

这是我的控制器的代码:

        function forgot_pass(){

          $data['page_title']=" Forgot Password ";
          $data['item']="Password";

          // initializing db keys
          $data['table_name'] ="physicians";
          $data['primary_key_name']="physician_id";

           //BOF Edit physician
           if( isset( $_REQUEST['physician_forgot_pass'] ) ){

              if ($this->form_validation->run('physician_forgot_pass'))
              {
                $physician_row=$this->model_site->check_physcian_retrive_password( $_REQUEST['username'],  encode_decode($_REQUEST['email'],'encode')  );
                //echo "<pre />"; print_r($physician_row); die;
                if($physician_row){

                    $physician_exist=1;

                    if($physician_row['approved']==1){ 

                       //Generate new Randmo password
                       $this->load->helper( 'get_random_password' );
                       $new_password=get_random_password(); //echo $new_password; die;

                       $update_data=array(
                                        'password'   => md5($new_password)
                                      );
                       $this->model_site->update_table('physicians', $update_data, 'username', $_REQUEST['username']  );


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

                       //GET SENDER EMAIL ADDRESS
                       $data['email_data']=$this->model_cms->get_single_record( 'email', 'email_id', 1 );
                       //echo "<pre />"; print_r($data['email_data']); die;

                       //Sending Mail To Physician
                       $physician_email = encode_decode($physician_row['email'],'decode');

                       $data['physician_email_msg']="Your New Password is ".$new_password;
                       $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $physician_email  , "Retrive Password", $data['physician_email_msg']);
                       if($data['email_sent']){
                              $data['status']=1;
                              $data['status_message']="Your password has been sent to your mail at ".$physician_email;
                              $data['notification']=  array(
                                                        "notify_type"  => "notify_site_success",
                                                        "notify_message"   => $data['status_message']
                                                     );

                              //insert to audit log table
                              $audit_log_details="Physician <b>".encode_decode($physician_row['name'],'decode')."</b> ( Username : <b>".$physician_row['username']."</b> ) requested for retrieving lost passwords. A new password was sent to Physician. Email Address of the Physician is  <i>".$physician_email."</i> . ";
                              $audit_log_id = $this->model_cms->add_audit_log_record( $physician_row['physician_id'] , $physician_row['username'] , 'physician', "Retrieving lost passwords request ", $audit_log_details, time() );

                              $data['nbc_email_msg']=$audit_log_details."Here is the email below \n Your New Password is ".$new_password;
                              $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $data['email_data']['email'], "Retrive Password", $data['nbc_email_msg']);
                       }
                       else {
                          $data['status']=0;
                          $data['status_message']="Error in sending mail to National Biological Corporation. Please try again later";
                          $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                       }

                    }
                    else {
                         $data['status']=0;
                         $data['status_message']="Your account is not approved yet. you will be able to request for retrive password after your account is approved.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                    }
                }
                else {
                         $data['status']=0;
                         $data['status_message']="Sorry! Could not found physcian with this username and email.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                }
              }
            }
           //EOF Edit physician

          $this->load->view('site/view_header',$data);
          $this->load->view('site/view_left_panel',$data);
          $this->load->view('site/view_physician_forgot_password',$data);
          $this->load->view('site/view_footer');
    }

    function forgot_userid(){

          $data['page_title']=" Forgot Username ";
          $data['item']="Username";

          // initializing db keys
          $data['table_name'] ="physicians";
          $data['primary_key_name']="physician_id";

           //BOF Edit physician
           if( isset( $_REQUEST['physician_forgot_userid'] ) ){

              if ($this->form_validation->run('physician_forgot_userid'))
              {
                $physician_row=$this->model_site->check_physician_get_userid( $_REQUEST['dea_number'],  encode_decode($_REQUEST['email'],'encode')  );
                //echo "<pre />"; print_r($physician_row); die;
                if($physician_row){

                    $physician_exist=1;

                    if($physician_row['approved']==1){ 

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

                       //GET SENDER EMAIL ADDRESS
                       $data['email_data']=$this->model_cms->get_single_record( 'email', 'email_id', 1 );
                       //echo "<pre />"; print_r($data['email_data']); die;

                       //Sending Mail To Physician
                       $physician_email = encode_decode($physician_row['email'],'decode');

                       $data['physician_email_msg']="According to our records, your registered username is ".$physician_row['username'];
                       $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $physician_email  , "Your requested username reminder from phototherapydoctor.com", $data['physician_email_msg']);
                       if($data['email_sent']){
                              $data['status']=1;
                              $data['status_message']="Your username has been sent to your mail at ".$physician_email;
                              $data['notification']=  array(
                                                        "notify_type"  => "notify_site_success",
                                                        "notify_message"   => $data['status_message']
                                                     );

                              //insert to audit log table
                              $audit_log_details="Physician <b>".encode_decode($physician_row['name'],'decode')."</b> ( Username : <b>".$physician_row['username']."</b> ) requested for retrieving lost passwords. A new password was sent to Physician. Email Address of the Physician is  <i>".$physician_email."</i> . ";
                              $audit_log_id = $this->model_cms->add_audit_log_record( $physician_row['physician_id'] , $physician_row['username'] , 'physician', "Retrieving lost passwords request ", $audit_log_details, time() );

                              $data['nbc_email_msg']=$audit_log_details."Here is the email below \n Your New Password is ".$physician_row['username'];
                              $data['email_sent']=email_send( $data['email_data']['email'], $data['email_data']['email_name'], $data['email_data']['email'], "Retrive Password", $data['nbc_email_msg']);
                       }
                       else {
                          $data['status']=0;
                          $data['status_message']="Error in sending mail to National Biological Corporation. Please try again later";
                          $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                       }

                    }
                    else {
                         $data['status']=0;
                         $data['status_message']="Your account is not approved yet. You will be able to request username after your account is approved.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                    }
                }
                else {
                         $data['status']=0;
                         $data['status_message']="Sorry! We could not find a physician with this DEA number and email.";
                         $data['notification']=  array(
                                                    "notify_type"  => "notify_site_error",
                                                    "notify_message"   => $data['status_message']
                                                 );
                }
              }
            }
           //EOF Edit physician

          $this->load->view('site/view_header',$data);
          $this->load->view('site/view_left_panel',$data);
          $this->load->view('site/view_physician_forgot_userid',$data);
          $this->load->view('site/view_footer');
    }

这是我的模型中的块......:

  function check_physician_get_userid( $dea_number, $email ) {  //check if physcian exist with this dea number and password

    $query = $this->db->get_where( "physicians", array( "dea_number" => $dea_number , "email" => $email ) ) ;

    if( $query->num_rows() > 0 ) {
        return $query->row_array();
    }
    else {
        return false;
    }

} //end check_physcian_retrive_userid

这是我的 form_validation 条目:

                  'physician_forgot_userid'=> array(
                               array(
                                        'field' => 'dea_number',
                                        'label' => 'DEA Number',
                                        'rules' => 'required'
                                     ),
                               array(
                                        'field' => 'email',
                                        'label' => 'Email',
                                        'rules' => 'required|valid_email'
                                     )
                                ),

最后,我的观点:

<div class="middle_panel">

 <p style="color:#424A8D;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:15pt;font-weight:bold;">Retrieve Lost Username</p>

 <div class="physician_join_form">

    <?php echo  form_open('physician/forgot_userid'); ?>

       <div class="register_box_text">DEA Number : </div>
       <div class="register_box_field">
         <input name="dea_number" id="dea_number" value="<?php echo set_value('dea_number'); ?>" type="dea_number" size="20">
         <?php echo form_error('dea_number'); ?>
       </div>

       <div class="register_box_text">Email : </div>
       <div class="register_box_field">
         <input name="email" id="email" value="<?php echo set_value('email'); ?>" type="email" size="20">
         <?php echo form_error('email'); ?>
       </div>

       <div class="register_box_text" style="background:#F9F9F9;"> &nbsp; </div>
       <div class="register_box_field">
          <input type="submit" id="physician_forgot_userid" name="physician_forgot_userid" value="Submit">
       </div>

    <?php echo form_close(); ?>

 </div>

4

1 回答 1

1

  1. 在您看来:将 DEA 编号字段的输入类型更改为有效的输入类型:[但这不会解决您的问题。]

    类型="dea_number"

  2. 只需编写一个单独的函数和模型,从physicians表中获取所有详细信息。

控制器:在您当前的控制器内部。



    function fetch_details_ctrl($dea_number) {
           if(!empty($dea_number)) {
               $result = $this->model_cms->fetch_details_model($dea_number);
               print_r($result);
           }
           else
               echo 'Pls. provide a DEA NUMBER';
    }

型号:内models/model_cms.php



    function fetch_details_model($dea_number) {
       $query = $this->db->get_where("physicians",array("dea_number"=>$dea_number));
       if( $query->num_rows() > 0 ) {
           return $query->row_array();
       }
       else {
           return false;
       }
    }


像这样调用控制器函数:http://{YOURSITE}.com/{CONTROLLER_NAME}/fetch_details_ctrl/[DEA_NUMBER]
DEA_NUMBER 应该是用户将在恢复视图中提供的输入字段中输入的那个。
如果这产生了结果,则意味着问题不完全在于dea数。如果没有,可能有两个原因:
1. 用户输入的 DEA 号码在数据库中不存在。
2.电子邮件地址加密存在一些问题,但您明确表示它可以正常工作[忘记密码]。但是我还没有看到那个代码,所以我仍然有这个疑问。

于 2013-04-12T12:30:12.917 回答