我在Code Igniter中正在执行密码重置功能。我是这个框架的新手。
我有控制器名为user_forgot_password_con 和Model是user_forgot_password_model
控制器中的我有两个功能 一个是user_forgot_password_process() 此功能从用户检查数据库中收取电子邮件,并使用链接http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email'发送邮件到该电子邮件。$ to_email。''
另一个函数是user_new_password_process() 此功能允许用户输入新密码
模型是user_forgot_password_model
它有3个功能,一个是获取用户邮箱查看邮箱 第二个是sendMail发送电子邮件第三是更新用户密码以更新密码..
发送电子邮件和其他东西正在运作
当链接被删除时,我通过$email= $this->input->get("email");
输入新密码并更新表格后我收到此错误
发生数据库错误 错误号码:1292 截断不正确的DOUBLE值:'fgh@gmail.com' UPDATE
register
SETpassword
= 0 WHERE
如何解决..
我的控制器代码是
<?php
through CI
Class User_forgot_password_con extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('user_forgot_password_model');
}
// Show login page
public function index()
{
$this->user_forgot_password_process();
}
//Forgot Password Link Sending....
public function user_forgot_password_process()
{
// get form input
$email = $this->input->post("email");
// form validation
$this->form_validation->set_rules("email", "Email-ID", "trim|required|xss_clean");
if ($this->form_validation->run() == FALSE)
{
// validation fail
$this->load->view('header');
$this->load->view('user_forgot_password_view');
$this->load->view('footer');
}
else
{
$uresult = $this->user_forgot_password_model->get_user_email($email);
if (count($uresult) > 0)
{
//send mail
if ($this->user_forgot_password_model->sendEmail($this->input->post('email')))
{
// successfully sent mail
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Password Reset Link Is Sent To Your Email Reset Your Password..!!!</div>');
$this->load->view('header');
redirect('user_forgot_password_con/user_forgot_password_process');
$this->load->view('footer');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Email Not Registered...</div>');
$this->load->view('header');
redirect('user_forgot_password_con/user_forgot_password_process');
$this->load->view('footer');
}
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Email Not Registered..</div>');
$this->load->view('header');
redirect('user_forgot_password_con/user_forgot_password_process');
$this->load->view('footer');
}
}
}
public function user_new_password_process()
{
$password = $this->input->post("passwword");
$cpassword= $this->input->post("cpasswword");
$this->form_validation->set_rules('password', 'Password', 'trim|required|md5');
$this->form_validation->set_rules('cpassword', 'Confirm Password', 'trim|required|matches[password]|md5');
if ($this->form_validation->run() == FALSE)
{
// validation fail
$this->load->view('header');
$this->load->view('user_new_password_view');
$this->load->view('footer');
}
else
{
$email= $this->input->get("email");
$this->user_forgot_password_model->update_user_password($email,$password);
}
}
}
?>
我的模特是
<?php
class user_forgot_password_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_user_email($email)
{
$this->db->where('email', $email);
$query = $this->db->get('register');
return $query->result();
}
//send verification email to user's email id
function sendEmail($to_email)
{
$from_email = 'team@mydomain.com';
$subject = 'Reset Password Link...';
$message = 'Dear User, Please click on the below link to Reset your password.
http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email'.$to_email.'';
//configure email settings
$this->email->initialize();
//send mail
$this->email->from($from_email, 'Mydomain');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
return $this->email->send();
}
// Update Table
function update_user_password($email,$password)
{
$data = array('password' => $password);
$this->db->where('email', $email);
return $this->db->update('register', $data);
}
}
答案 0 :(得分:0)
我可以告诉你一些事情。首先,错误消息表示您正在将String
(电子邮件)与Double
(0)进行比较,因此您提取的电子邮件无效。
http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email'.$to_email.
我认为您错过了链接末尾附近的=
- &gt; ?email='.$to_email.'
,它带有变量,因此可以通过GET
获取,没有它它只是链接的一部分,所以你需要通过$this->uri()->segment(3)
获取它并且它将导致在像?emailexample@email.com
这样的字符串中。你不想要那个。在链接中传递私人数据是一种不好的做法,因为任何人都可以直接调用该电子邮件的重置功能。我输入http://localhost/codeigniter/user_forgot_password_con/user_new_password_process/?email=your@email.com
我只是希望这是一个学校项目,如果不是,你需要对如何安全地重置用户密码进行大量研究。
在user_new_password_process
函数中,我认为没有任何作用,因为直接来自邮件中的链接会将您带到尝试从POST
读取某些数据的方法:
$password = $this->input->post("passwword");
$cpassword= $this->input->post("cpasswword");
但那里什么都没有。您需要通过该电子邮件转到user_new_password_show()
,在其中加载包含这两个字段的表单的视图,此外您需要传递电子邮件,而不是当他提交到user_new_password_process
时