benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.35k stars 1.14k forks source link

No showing message after user successful change password #1009

Closed kresnasatya closed 7 years ago

kresnasatya commented 7 years ago

Mr. Benedmunds, I just test change password method as below:

    public function change_password()
    {
        $this->form_validation->set_rules('old', $this->lang->line('change_password_validation_old_password_label'), 'required');
        $this->form_validation->set_rules('new', $this->lang->line('change_password_validation_new_password_label'), 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[new_confirm]');
        $this->form_validation->set_rules('new_confirm', $this->lang->line('change_password_validation_new_password_confirm_label'), 'required');

        if (!$this->ion_auth->logged_in())
        {
            redirect('auth/login', 'refresh');
        }

        $user = $this->ion_auth->user()->row();

        if ($this->form_validation->run() == false)
        {
            // display the form
            // set the flash data error message if there is one
            $this->data['message'] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message');

            $this->data['min_password_length'] = $this->config->item('min_password_length', 'ion_auth');
            $this->data['old_password'] = array(
                'name' => 'old',
                'id'   => 'old',
                'type' => 'password',
            );
            $this->data['new_password'] = array(
                'name'    => 'new',
                'id'      => 'new',
                'type'    => 'password',
                'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
            );
            $this->data['new_password_confirm'] = array(
                'name'    => 'new_confirm',
                'id'      => 'new_confirm',
                'type'    => 'password',
                'pattern' => '^.{'.$this->data['min_password_length'].'}.*$',
            );
            $this->data['user_id'] = array(
                'name'  => 'user_id',
                'id'    => 'user_id',
                'type'  => 'hidden',
                'value' => $user->id,
            );

            // render
            $this->_render_page('auth/change_password', $this->data);
        }
        else
        {
            $identity = $this->session->userdata('identity');

            $change = $this->ion_auth->change_password($identity, $this->input->post('old'), $this->input->post('new'));

            if ($change)
            {
                //if the password was successfully changed
                $this->session->set_flashdata('message', $this->ion_auth->messages());
                $this->logout();
            }
            else
            {
                $this->session->set_flashdata('message', $this->ion_auth->errors());
                redirect('auth/change_password', 'refresh');
            }
        }
    } 

After I succesfull change password, it must be show message 'Password Successfully Changed' which I check on ion_auth_lang.php is exist on $lang['password_change_successful'] . But, it didn't show message like that in login page.

This is the login view:

<h1><?php echo lang('login_heading');?></h1>
<p><?php echo lang('login_subheading');?></p>

<div id="infoMessage"><?php echo $message;?></div>

<?php echo form_open("auth/login");?>

  <p>
    <?php echo lang('login_identity_label', 'identity');?>
    <?php echo form_input($identity);?>
  </p>

  <p>
    <?php echo lang('login_password_label', 'password');?>
    <?php echo form_input($password);?>
  </p>

  <p>
    <?php echo lang('login_remember_label', 'remember');?>
    <?php echo form_checkbox('remember', '1', FALSE, 'id="remember"');?>
  </p>

  <p><?php echo form_submit('submit', lang('login_submit_btn'));?></p>

<?php echo form_close();?>

<p><a href="forgot_password"><?php echo lang('login_forgot_password');?></a></p>

I do a silly things like adding ion_auth lang in Auth controller because the $lang['password_change_successful'] is located on ion_auth_lang.php : $this->lang->load(array('auth', 'ion_auth')); But, it doesn't work.

I hope, I can get your answer about this case to make this ion auth more better and used by others developer. Thanks a lot

Note: That code overall based on your repository (branch 2), I just copy controller, models, and anything else to CodeIgniter and test it.

benedmunds commented 7 years ago

I dont see you echoing "password_change_successful" anywhere in this code. Maybe I'm not following?

kresnasatya commented 7 years ago

Yes, I didn't do that because that the words "password_change_successful" is already exist on ion_auth_lang.php. I try again to add ion_auth_lang.php to Auth controller so like this:

$this->load->lang(array('auth', 'ion_auth')); but, it doesn't work to show the messange "password change successful" when user logout and direct to login page by system.

I think, you can test with your own ion auth on section change_password. Thank you.

On Dec 17, 2016 12:22 AM, "Ben Edmunds" notifications@github.com wrote:

I dont see you echoing "password_change_successful" anywhere in this code. Maybe I'm not following?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/benedmunds/CodeIgniter-Ion-Auth/issues/1009#issuecomment-267631921, or mute the thread https://github.com/notifications/unsubscribe-auth/AKlcMjPj1L1papmLQaD-BJM3KjYD_qdmks5rIrqxgaJpZM4LPDg- .

kresnasatya commented 7 years ago

Wait a moment. I think the message "password successful change" because $this->logout(); run after I set the message and it destroy the session flashdata.

kresnasatya commented 7 years ago

I have one alternative, just let show "password successful change" on page "change_password" without logout. Thank you Mr. Benedmuns.