【问题标题】:Username recovery code not working as expected用户名恢复代码未按预期工作
【发布时间】:2013-04-04 20:30:15
【问题描述】:

我正在为我工​​作的公司开发一个网站。它需要用户注册和登录。所有数据都存储在 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>

【问题讨论】:

  • 你有什么错误吗???
  • All of the data is stored on _SQL_ database 是什么意思?
  • 不,没有任何 php 错误。只是一个网站错误,说没有用户拥有这个 dea 号码和电子邮件......
  • 只是说它在SQL数据库上。不确定该信息可能具有什么价值。只是想我会提到它。其他一切正常。
  • 我确实知道这一点,我在下面的行中将 'userid' 更改为 'password' ,它有效,但错误。它要求您输入您的用户名。然后它会从数据库中通过电子邮件将您的用户名发送给您... $physician_row=$this->model_site->check_physician_get_userid

标签: php forms codeigniter validation


【解决方案1】:

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

    type="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 number。如果没有,可能有两个原因:
1.用户输入的DEA号码在数据库中不存在。
2.电子邮件地址加密存在一些问题,但您明确表示它以另一种方式正常工作[忘记密码]。但是我没有看到那个代码,所以我仍然有这个疑问。

【讨论】:

  • 谢谢!我肯定会很快尝试这个,然后会更新。感谢您的关注和帮助。
  • 好的,所以我尝试这个没有结果。虽然,我很可能做错了什么。我应该将它添加到我当前的模型和控制器中还是创建新的单独的?除了一般编辑之外,我真的不知道我在做什么。我确实知道进行原始构建/设计的人倾向于定制一些不符合标准的东西。此外,如果它提供了任何见解,那么这个网站在公众可以看到的内容和内容管理系统之间有点“分裂”。两个模型和两组视图,model_site 和 model_cms。其他所有内容似乎都是共享的。
  • 那是相当多的评论......!我已经编辑了我的答案。如果它仍然没有帮助你,我仍然很乐意帮助你......
  • 首先,我非常感谢您对我问题的关注。我尝试了你所描述的最好的理解和能力,但没有运气,虽然,我不确定你所说的“像这样调用控制器函数”是什么意思。我正在学习其中的大部分内容,并且觉得我应该/需要更详细地了解这意味着什么。我编辑了我的 Q 并添加了代码的密码部分以供审核。
  • “像这样调用控制器函数:”表示您必须在浏览器地址栏上输入的 URL 是我在顶部输入的 URL。现在检查您的找回密码代码后,第二点被排除在外。问题肯定出在 DEA 号码上!您输入的号码可能不存在于数据库中/它可能以不同的格式存储。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-11
  • 2020-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多