Welcome Guest, Not a member yet? Register   Sign In
Reset Password Errors
#1

[eluser]Kemik[/eluser]
Hello,

I'm building a reset password page. The random key is passed via the third uri and a form (password & repeat password text fields) is displayed if it's valid.

Code:
if (logged_in()) {
    show_error("You've already logged in. Why would you need to request your password?");
} elseif (!$this->uri->segment(3)) {
    show_error('No random string passed.');
} else {
    $data['str'] = $this->uri->segment(3);
}

// Query the database to get the email if the the string exists in the user_resets table.
// If num_rows < 1 display an error stating the string isn't valid.

// If form is submitted do password update, delete string, etc.
$this->session->set_flashdata('reset', TRUE);
redirect('user/reset');

The problem I'm having is how I redirect the user back to the page so I can display the success message without getting errors. Number one, the "No random string passed" error will be displayed and even if I add a string (e.g. done) to the end of the url the valid string check will give the "String not in the database" error.

I'm sure I've encountered the problem before but I cannot remember how I got around it. I want to try and keep my code in the one view file.

View
Code:
if flashdata display success message else display form

To be clear, I don't want to know how to code the page itself. I've already done that. The problem I'm having is how can I display the success message to the user without errors?

As a temp fix I've set the code to redirect to the login page and check for the flashdata there. It seems like a better idea in this case as the user can log straight in after resetting their password. However, it would be nice to know how I can get around the problem for future reference.




Theme © iAndrew 2016 - Forum software by © MyBB