I am working on a basic blog application in Codeigniter 3.1.8 and Bootstrap 4.
I have added a registration and login system to this application. I am current working on a password reset system.
In the Changepasword controller, the index
method takes the parameters $email
and $token
:
public function index($email, $token) {
$data = $this->Static_model->get_static_data();
$data['pages'] = $this->Pages_model->get_pages();
$data['tagline'] = 'New password';
$data['categories'] = $this->Categories_model->get_categories();
// Form validation rules
$this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
$this->form_validation->set_rules('cpassword', 'Confirm password', 'required|matches[password]');
$this->form_validation->set_error_delimiters('<p class="error-message">', '</p>');
if(!$this->form_validation->run()) {
$this->load->view('partials/header', $data);
$this->load->view('auth/newpassword');
$this->load->view('partials/footer');
} else {
$this->Usermodel->set_new_password($email, $token);
}
}
In the routes file I have this line for the above controller:
$route['changepasword/(:any)/(:any)'] = 'changepasword/$1/$2/';
The entire routes file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['default_controller'] = 'posts';
$route['install'] = 'install';
$route['migrate'] = 'migrate';
$route['register'] = 'register';
$route['login'] = 'login';
$route['newpassword'] = 'newpassword';
$route['changepasword'] = 'changepasword';
$route['changepasword/(:any)/(:any)'] = 'changepasword/$1/$2/';
$route['dashboard'] = 'dashboard';
$route['dashboard/create-post'] = 'dashboard/posts/create';
$route['dashboard/create-page'] = 'dashboard/pages/create';
$route['dashboard/create-category'] = 'dashboard/categories/create';
$route['dashboard/manage-authors'] = 'dashboard/users';
$route['404_override'] = '';
$route['categories/posts/(:any)'] = 'categories/posts/$1';
$route['(:any)'] = 'posts/post/$1';
$route['translate_uri_dashes'] = FALSE;
I also added this to the config.php
file:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@=&\-!';
Yet, at the URL http://ciblog.com/changepasword/myaddress@gmail.com/f450469ac1970b06074acb7c430d431d
instead of the view being rendered, I get the error:
404 Page Not Found
The page you requested was not found.
If I use md5($this->user_email)
instead of $this->user_email
I get the URL: http://ciblog.com/changepasword/ec9814883d7f7149bc15f1ed1f472da9/d7571dc4e25ea76278bee5eb45251f11
, but still, the 404 Page Not Found erroe message.
All the code I have written so far for this update password functionality is HERE.
What am I doing wrong?
Change these 2 lines!
$route['changepasword'] = 'changepasword';
$route['changepasword/(:any)/(:any)'] = 'changepasword/$1/$2/';
UPDATE:
You forget to define function/method name in route:
Modify from this: $route['newpasword/(:any)/(:any)'] = 'newpasword/$1/$2/';
to this: $route['newpasword/(:any)/(:any)'] = 'newpasword/index/$1/$2/';
And the previous line ($route['newpasword'] = 'newpasword';
) is deletable because you not use index function without parameters.