codeigniter- on change password display change password successfully

时间:2015-05-17 07:13:24

标签: php codeigniter

到目前为止,我的代码正在运行并更改用户密码。我现在想要向用户显示他们的密码已成功更改,否则请再试一次,但我无法实现。任何帮助将不胜感激,谢谢。

这是控制器:

public function change_password($arg = "admin")
{
    if(isset($_POST['data']) && !empty($_POST['data']))
    {
        $this->load->library('form_validation');

        $this->form_validation->set_rules('data[oldpassword]', 'old password', 'required');
        $this->form_validation->set_rules('data[password]', 'password', 'trim|required');
    $this->form_validation->set_rules('data[passconf]', 'password Confirmation', 'trim|required|md5|matches[data[password]]');



        if ($this->form_validation->run() == FALSE)
        {
            $data['requestee'] = $arg;
            $this->load->view('change_password', $data);
        }
        else
        {
            $data = $_POST['data'];
            array_pop($data);
            $data['requestee'] = $arg;
            $data['email'] = $this->session->userdata('email');
            //print_r($data); exit;

            if($data['requestee'] == "admin")
            {
                $this->load->model('login_model');
                if($this->login_model->updatepassword($data))
                {
                    redirect('/admin/show', 'refresh');
                }
                else
                {
                    redirect('login/change_password/');
                }
            }
            elseif($data['requestee'] == "org")
            {
                $this->load->model('login_model');
                if($this->login_model->updatepassword($data))
                {
                    redirect('/organizer/show', 'refresh');
                }
                else
                {
                    redirect('login/change_password/org');
                }
            }
            else 
            {
                echo "could not change password";
            }
        }
    }
    else 
    {   
        $data = array('requestee' => $arg);
        $this->load->view('change_password', $data);
    }
}

以下是观点:

     <form action="<?php echo site_url('login/change_password'); ?>" class="login-wrapper" method="post">
                      <div class="header">
                        <div class="row-fluid">
                          <div class="span12">
                            <h3>Change password<img src="<?php echo asset_url();?>img/logo1.png" alt="Logo" class="pull-right"></h3>
                            <p>Fill out the form below to change your password.</p>
                          </div>
                        </div>

                      </div>
                      <div class="content">
                        <div class="row-fluid">
                          <div class="span12">
                            <input class="input span12 password" id="" name="data[oldpassword]" placeholder="Old password" required="required" type="password" value="<?php echo set_value('oldpassword'); ?>">
                          </div>
                        </div>
                        <div class="row-fluid">
                          <div class="span12">
                            <input class="input span12 password" id="" name="data[password]" placeholder="New password" required="required" type="password" value="<?php echo set_value('password'); ?>">
                          </div>
                        </div>
                        <div class="row-fluid">
                          <div class="span12">
                            <input class="input span12 password" id="" name="data[passconf]" placeholder="Confirm new password" required="required" type="password" value="<?php echo set_value('passconf'); ?>" >
                          </div>
                        </div>
                      </div>
                      <div class="actions">
                        <input class="btn btn-danger" name="change_password" type="submit" value="Change" >

                        <div class="clearfix"></div>
                      </div>
                    </form>

1 个答案:

答案 0 :(得分:0)

在更改用户密码后,您似乎正在使用重定向将用户返回到另一个页面。

在您的控制器中,在执行重定向之前,您可以使用CodeIgniters会话数据在flashdata中设置消息,如下所示:

$this->session->set_flashdata('message', 'Your Password Was Successfully Changed');

或     $ this-&gt; session-&gt; set_flashdata(&#39;消息&#39;,&#39;您的密码未更改&#39;);

然后在您的视图中,您可以添加:

<?php echo $this->session->flashdata('message'); ?>

请注意,为了使其正常工作,如果您还没有这样做,则需要在每个使用它的页面上手动加载会话库,或者将其添加到autoload.php文件中。