通过覆盖旧密码来插入新密码 [英] Inserting new password by overriding old password
问题描述
在yii中,我正在创建项目.验证用户输入的电子邮件后,我正在显示password.php文件,该文件具有用于输入新密码的文本字段. Password.php =
In yii i am creating project. After validation of user's entered email, i am displaying password.php file which is having textfield for entering new password. Password.php=
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('Enter new password');
echo CHtml::textField('Repeat password');
echo CHtml::submitButton('Submit');
$this->endWidget();
当用户输入新密码并单击提交"按钮时,我想将此新密码插入用户"表的密码字段中,以使其覆盖旧密码.
When user will enter new password and click on submit button i want to insert this new password into User table's password field, in such a way that it overright old password.
在控制器中,我创建的方法为-
In controller i had created method as-
public function actionCreate(){
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
echo "email exists";
$this->render('Password');
if(isset($_POST['Password']))
{
$command = Yii::app()->db->createCommand();
$command->insert('User', array(
'password'=>$_POST['password'] ,
//'params'=>array(':password'=>$_POST['password'])
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
但未插入新密码.那么我该如何实施...请帮助我
But its not inserting new password. So How can i implement this...Please help me
推荐答案
您无法获得像$_POST['Password']
这样的密码,因为您尚未设置此post变量.
You can't get password like this $_POST['Password']
, because you haven't set this post variable.
您必须使用:
echo CHtml::textField('password');
echo CHtml::textField('repeatPassword');
echo CHtml::hiddenField('email', $email);
'password'和'repeatPassword'是POST变量的名称
'password' and 'repeatPassword' are names of POST vars
在您的控制器中,您有太多错误,请尝试以下操作(检查输入错误):
And in your controller you have too many mistakes, try this (check for typos):
if(isset($_POST['email']))
{
$record=User2::model()->find(array(
'select'=>'userId, securityQuestionId, primaryEmail',
'condition'=>'primaryEmail=:email',
'params'=>array(':email'=>$_POST['email']))
);
if($record===null) {
echo "Email invalid";
}
else {
if(isset($_POST['password']) && isset($_POST['repeatPassword']) && ($_POST['password'] === $_POST['repeatPassword']))
{
$record->password = $_POST['password'];
if ($record->save()) {
$this->render('saved');
}
}
$this->render('Password' array('email'=>$_POST['email']));
}
}
}
else{
$this->render('emailForm'); //show the view with the password field
}
在您的代码中if(isset($_POST['Password']))
将永远不会执行,因为发送密码后,您尚未设置email
变量.所以你只是$this->render('emailForm');
.因此,我们通过CHtml::hiddenField('email', $email);
In your code if(isset($_POST['Password']))
won't ever execute, because after sending password you haven't set email
variable. So you just $this->render('emailForm');
. Thus we set it by CHtml::hiddenField('email', $email);
更新.我强烈建议您阅读本指南 .这样可以为您节省很多时间.
Upd. I strongly recommend you to read this guide. It will save a lot of time for you.
这篇关于通过覆盖旧密码来插入新密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!