某些功能在codeigniter 3控制器中不起作用

时间:2017-03-08 09:29:41

标签: php codeigniter-3

我有Settingcontroller,因为所有其他功能都正常工作,但updatepassword功能不起作用。在这个updatepassword函数中,我将更新新密码。

Settingcontroller

<?php
require APPPATH . '/controllers/admin/Admin_controller.php';
include APPPATH . 'third_party/currency/currencies.php';

class Settingcontroller extends Admin_controller{
    public function __construct(){
        parent::__construct();

        $this->load->model("Adminmodel","",true);
    }

    public function index(){
        $adminId=$this->session->userdata('cp_adminid');
        $data['userId']=$adminId;
        $data['title']='Settings';
        $data['content']=$this->load->view("admin/settings",$data,true);
        $permissions=$this->Adminmodel->getpermissions($adminId);
        $row = $permissions->row();
        $data['isAdmin'] = 0;
        if($row->view == 1 or $row->add == 1 or $row->edit == 1 or $row->deleteRole == 1 ){
            $data['isAdmin'] = 1;
        }

        //$this->load->view("admin/headerview",$data);
        $headerContent = $this->load->view("admin/headerview",$data,true);
        $this->render($headerContent);
    } 

    public function passwordcheck(){
        $pass="";
        $current = md5($this->input->post('currentpassword'));
        $sql=$this->adminmodel->checkpassword();
        foreach($sql->result() as $s)
        {
            $pass=$s->password;
        }
        if($pass==$current){
            $result="true";
        }else{
            $result="false";
        }

        echo $result;
    }

    public function updatepassword(){
        $password=$this->input->post('newpassword');
        if($password != ""){
            $a=$this->Adminmodel->updatepassword(do_hash($password, 'md5'));
        }
        $this->Adminmodel->saveGlobalSettings($this->input->post());
        $s="Successfully Updated";
        $n="An error occured";
        $value=array(
            'result'=>$a,
            'msg'=>$s,
            'mesg'=>$n
        );
        echo json_encode($value);
    } 

}
?>

setting.php

<form id="updatepassword">
   <div class="security">
      <div class="tittle-security">
         <h5>Change Password</h5>
         <div id="up"></div>
         <input type="password" name="currentpassword" id="currentpassword" placeholder="Current password">
         <input type="password" name="newpassword" id="newpassword" placeholder="New password">
         <input type="password" name="confirmpassword" id="confirmpassword" placeholder="Confirm password">
      </div>
   </div>
</form>

admin.js

updatepassword();
 function updatepassword(){
        $('#updatepassword').validate({

            errorClass: 'error',
            validClass: 'valid',
            errorPlacement: function(error, element) {
                     error.insertAfter(element);
            },
            rules: {

                currentpassword:{
                    required: function(element){
                        return (($("#newpassword").val().length > 0)||($("#currentpassword").val().length > 0)||($("#confirmpassword").val().length > 0));
                    },
                    minlength: 6,
                    remote: {
                        url: urljs+"admin/Settingcontroller/passwordcheck",
                        type: "post"
                     }

                },
                newpassword:{
                    required:function(element){
                        return (($("#newpassword").val().length > 0)||($("#currentpassword").val().length > 0)||($("#confirmpassword").val().length > 0));
                    },
                    minlength: 6,
                },
                confirmpassword:{
                    required:function(element){
                        return (($("#newpassword").val().length > 0)||($("#currentpassword").val().length > 0)||($("#confirmpassword").val().length > 0));
                    },
                    minlength: 6,
                    equalTo: "#newpassword"
                }

            },
            messages:{

            currentpassword:{
                required:"Please enter current password",
                minlength: "Atleast 6 characters",
                remote:"Password not in database"

            },
            newpassword:{
                required:"Please enter new password",
                minlength: "Atleast 6 characters",
            },
            confirmpassword:{
                required:"Please enter confirm password",
                minlength: "Atleast 6 characters",
            }
            },
            submitHandler: function(){
                var user=$('#updatepassword').serializeArray();
                alert('first');
                alert(urljs);
                $.post(urljs+"admin/Settingcontroller/updatepassword",user,function(data){
                    if(data.result>0){
                        $("#up").html(data.msg);
                        window.location.href=urljs+"/admin/adminlogout";
                    }
                    else{
                        $("#up").html(data.mesg);
                    }   
                },"json");
            }
        });
    }

所有其他索引,密码检查功能都正常,但此更新密码无法正常工作。如果我把print_r();在这个功能甚至也没有到来。这有什么不对吗?

0 个答案:

没有答案