gpt4 book ai didi

yii-cactiverecord - 如何检查数据库中是否存在记录

转载 作者:行者123 更新时间:2023-12-01 09:02:56 24 4
gpt4 key购买 nike

在 yii 中,我使用安全问题创建密码重置功能。首先,用户需要输入他的电子邮件 ID。我在 views->User1 中创建 emailform.php 作为

<?php
$form=$this->beginWidget('CActiveForm', array(
'id'=>'email-form',
'enableClientValidation'=>true,
));
echo CHtml::textField('email');
echo CHtml::submitButton('Send');
$this->endWidget();

在 Controller 中我创建了方法

public function actionPassword() {
if (isset($_POST['email'])) {
$email = $_POST['email'];
//process email....
//....
}
$this->render('_emailForm');
}

现在我想检查这个电子邮件 ID 是否存在于用户表中。如果是这样,那么我想向他显示一个安全问题。我该如何实现?

最佳答案

这将帮助您入门,您可以在 Controller 中放置一个类似的方法并创建一个带有密码字段的 View 。

public function actionPassword() {
if(isset($_POST['email'])) {
$record=User::model()->find(array(
'select'=>'email',
'condition'=>'email=:email',
'params'=>array(':email'=>$_POST['email']))
);

if($record===null) {
$error = 'Email invalid';
} else {
$newpassword = 'newrandomgeneratedpassword';
$record->password = $this->hash_password_secure($newpassword);
$record->save(); //you might have some issues with the user model when the password is protected for security
//Email new password to user
}
} else {
$this->render('forgetPassword'); //show the view with the password field
}
}

关于yii-cactiverecord - 如何检查数据库中是否存在记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13584443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com