提交密码重置表单时出错

时间:2015-04-22 16:27:36

标签: php yii

我在yii-framework网站中有一个密码重置表单。当用户提交表单时,我收到以下错误消息:

errors

我已设置忘记密码选项

我的控制器功能:

public function actionEmail_for_reset() {
    if (isset($_POST['Members'])) {
        $email = $_POST['Members']['email'];
        $criteria = new CDbCriteria;
        $criteria->condition = 'email=:email';
        $criteria->params = array(':email' => $email);
        $user = Members::model()->find($criteria);
        if (!$user) {
            $errormsg = Yii::t('passwordreset', 'Email ini tidak terdaftar. Silahkan coba lagi.');
            Yii::app()->user->setFlash('error', $errormsg);
            $this->refresh();
        }
        $key = md5(mt_rand() . mt_rand() . mt_rand());
        $user->confirmation_code = $key;
        $reset_url = $this->createAbsoluteUrl('site/password_reset', array('key' => $key, 'email' => $email));
        $user->save();

        if (XHtml::sendHtmlEmail(
                        $user->email, Yii::app()->name . ' Administrator', null, Yii::t('reset', 'Password reset.'), array('username' => $user->username, 'reset_url' => $reset_url), 'pwd_reset', 'main'
                )
        ) {
            $infomsg = Yii::t('passwordreset', 'We have sent you a reset link,please check your email inbox.');
            Yii::app()->user->setFlash('info', $infomsg);
            $this->refresh();
        } else {
            $errormsg = Yii::t('passwordreset', 'We could not email you the password reset link');
            Yii::app()->user->setFlash('info', $errormsg);
            $this->refresh();
        }
    }

    $model = new Members;
    $this->render('email_for_reset', array('model' => $model));
}

形式:

<div class="register-block black-text-color login-form">
    <div class="register-block-header text-center">
        <?php
        $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'EmailForm',
            'type' => 'horizontal',
            'enableAjaxValidation' => false,
            'htmlOptions' => array('class' => 'form')
        ));
        ?>
        <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
        <h3>Lupa Password</h3>
        <!--<span class="label important">Fields with <span class="important">*</span> are required.</span>-->
    </div>
    <span class="line margin-20"></span>
    <?php echo $form->errorSummary($model); ?>
    <p>Kami akan mengirimkan password ke Email Anda</p>
    <div class="form">
        <div class="input-group margin-bottom-20">
            <?php echo $form->textField($model, 'email', array('class' => 'form-control', 'placeholder' => "Enter your Email address", 'maxlength' => 256, 'style' => 'width:200px; height:30px; border-radius:5px; padding-left:10px;')); ?>
        </div>
        <?php // echo $form->error($model,'username'); ?>
        <br>
        <p>
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                'buttonType' => 'submit',
                //'type' => 'primary',
                'label' => $model->isNewRecord ? 'SEND PASSWORD' : 'Save',
                'htmlOptions' => array('class' => 'btn-fp')
            ));
            ?>
        </p>
    </div>
</div>
<?php $this->endWidget(); ?>
</div>

我的webapplication.php文件代码是

class WebApplication extends CWebApplication {

    /**
     * This function is here because we aren't creating a locale file for every client.
     * Thus we provide a fallback to "en".
     */
    public function getLocale($localeID = null) {
        try {
            return parent::getLocale($localeID);
        } catch (Exception $e) {
            return CLocale::getInstance('en');
        }
    }

    /**
     * We were getting tons of errors in the logs from OPTIONS requests for the URI "*"
     * As it turns out, the requests were from localhost (::1) and are apparently a way
     * that Apache polls its processes to see if they're alive. This function causes
     * Yii to respond without logging errors.
     */
    public function runController($route) {
        try {
            parent::runController($route);
        } catch (CHttpException $e) {
            if (@$_SERVER['REQUEST_METHOD'] == 'OPTIONS' && @$_SERVER['REQUEST_URI'] == '*') {
                Yii::app()->end('Hello, friend!');
            } else
                throw $e;
        }
    }
}

我正在使用this helper class

1 个答案:

答案 0 :(得分:0)

我通过描述邮件&#39;来解决这个问题。我的config / main.php文件中的组件。

'mailer' => array(
                   'class' => 'common.extensions.mailer.EMailer',
               ),