在yii我创建忘记密码功能。对于此用户输入电子邮件ID。如果此电子邮件ID正确,那么我想从数据库中检索securityQuestion id并将该问题显示给user.if他的答案是正确的然后密码重置链接将发送到用户的电子邮件ID。在控制器中我已经采取了行动
public function ActionForget{if(isset($_POST['email']))
{ $record=User::model()->find(array(
'select'=>'primaryEmail',
'condition'=>'PrimaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
); if($record===null) {
$error = 'Email invalid';
} else {
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->IsSMTP();
$mailer->IsHTML(true);
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
$mailer->Port = 465;
$mailer->CharSet = 'UTF-8';
$mailer->Username = "abc@shailani.com";
$mailer->Password = "abc";
$mailer->From = "xyz@shailani.com";
$mailer->FromName = "Balaee.com";
$mailer->AddAddress($record);
$mailer->Subject = "welcome to Balaee";
$mailer->IsHTML(true);
$mailer->Body = "<h1>Thanks to showing interest </h1><br>click on link for other detail ".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($mailer->Send()) {echo "Please check mail";}
else {echo "Fail to send your message!"; }}}
else{ $this->render('emailForm'); //show the view with the password field}}
我将password.php作为用于输入主电子邮件ID和提交按钮的视图文件
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('email');
echo CHtml::submitButton('Send');
$this->endWidget();
但是,在按用户提交主电子邮件ID后,不会执行任何操作。那么请有人告诉我需要做些什么改变
答案 0 :(得分:0)
控制器方法的名称不应该是actionForgot
而不是ActionForgot
。 PHP区分大小写,当您呈现页面时也会发送模型,例如this->render->('emailForm',$email)
$email
是您的模型名称
答案 1 :(得分:0)
好的我喜欢一开始,以下是对上述现有代码的一些修复。
但是,一旦您成功发送电子邮件,您的计划是什么;看到现有代码会为您提供一个类似于此http://yoursite.com/yourapp/user/forget的网址,这会将您带回到您输入电子邮件的表单,从而创建一个巨大的循环。
查看链接实际上应该创建验证,从而为用户提供对其用户记录的访问权限。您需要一些其他功能来验证并允许更改密码。
<code>
public function actionForget() {
if(isset($_POST['email'])) {
$record=User::model()->findByAttributes(array('email' => Yii::app()->request->getPost('email')));
if ($record != NULL) {
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->IsSMTP();
$mailer->IsHTML(true);
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = "ssl";
$mailer->Host = "smtp.gmail.com";
$mailer->Port = 465;
$mailer->CharSet = 'UTF-8';
$mailer->Username = "yourgmailacccount@gmail.com";
$mailer->Password = "P@ssWord";
$mailer->From = "yourfromemail@yourdomain.com";
$mailer->FromName = "HQ-DEV-01";
$mailer->AddAddress($_POST['email']);
$mailer->Subject = "welcome to CES Document Site";
$mailer->IsHTML(true);
$mailer->Body = "<h1>Thanks, please</h1><br>
click on link for other detail
".$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if($mailer->Send()) {
echo "Please check your email";
}
else {
echo "Fail to send your message!";
}
} else {
echo 'Email invalid';
}
else {
$this->render('password');
Yii::app()->user->setFlash('error', "Email is not valid!");
//echo 'Email invalid';
}
}
else{ $this->render('password'); //show the view with the password field}}
Yii::app()->user->setFlash('info', "Enter a valid e-mail!");
}
}