通过覆盖旧密码插入新密码 [英] Inserting new password by overriding old password
问题描述
在 yii 中,我正在创建项目.验证用户输入的电子邮件后,我将显示 password.php 文件,该文件具有用于输入新密码的文本字段.密码.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屋!