S
S
Svetlana Galenko2019-05-16 18:02:58
Yii
Svetlana Galenko, 2019-05-16 18:02:58

Why doesn't registration work on a site made on yii?

Hello, when registering, an error occurs: "Page not found", but should fall into the account. Why this happened I can not understand ... The entrance is carried out without problems.
I provide the code:
SignupController.php:

<?php

class SignupController extends Controller
{
    public function actions()
    {
        return array(
            'captcha'=>array(
                'class' => 'CaptchaAction',
            )
        );
    }

    public function actionIndex()
    {
        $form = new User(User::SCENARIO_SIGNUP);

        if (isset($_POST['User']) && $_POST['action'] == User::SCENARIO_SIGNUP)
        {
            $form->attributes = $_POST['User'];

            if ($form->validate())
            {
                $transaction = Yii::app()->db->beginTransaction();
                try
                {
                    $form->create();
                    $transaction->commit();

                    // send register info
                    $user = User::model()->findByAttributes(array('email' => $form->email));
                    $user->sendRegisterInfo();

                    Yii::app()->user->setFlash('success', 'Вы успешно зарегистрировались. На указанный E-mail было отправлено письмо с паролем для входа.');
                }
                catch (Exception $e)
                {
                    $transaction->rollback();
                    Yii::app()->user->setFlash('error', Yii::t('main', 'unknown_error'));
                }
            }
        }

        $this->render('index', array(
            'form'=>$form
        ));
    }
}

signup.php
<div class="col-12">
                <div class="uza-contact-form mb-80">
                    <div class="contact-heading mb-50">
                        <h4 style="text-align: center;">Для регистрации введите настоящий Email адрес, в течении нескольких минут вы получите письмо с паролем.</h4>
                    </div>

                    <?php echo CHtml::beginForm(); ?>
                        <div class="row">
                            <div class="col-12">
                                <div class="form-group" style="color: red;">
                                    <p><?php $this->widget('FlashMessagesWidget'); ?>
                                        <?php echo DHtml::errorSummary($form, '', array('style'=>'color: red;')); ?></p>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <?php echo CHtml::activeTextField($form, 'username', array('class'=>'form-control mb-30', 'placeholder'=>'Введите логин')); ?>
                                </div>
                            </div>
                            <div class="col-lg-6">
                                <div class="form-group">
                                    <?php echo CHtml::activeTextField($form, 'email', array('class'=>'form-control mb-30', 'placeholder'=>'Введите email')); ?>
                                </div>
                            </div>
                            <div class="contact-heading mb-50" style="color: red; text-align: center; margin: 0 auto; width: 100%;">
                                <p>
                                    <?php if ($form->hasRefererCookie()) { ?>
                                    <?php $refererUsername = $form->refererUsernameFromCookie(); ?>
                                    <?php echo CHtml::activeHiddenField($form, 'inviterUsername', array('value' => $refererUsername)); ?>
                                </p>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <input type="text" class="form-control mb-30" value="Вас пригласил: <?php echo $refererUsername; ?>" readonly style="width: 100%;">
                                </div>
                            </div>
                            <?php } ?>
                            <div class="col-12">
                                <div class="form-group form-control mb-30" style="text-align: center; height: 62px; cursor: pointer;">
                                    <img <?php $this->widget('CCaptcha'); ?>
                                </div>
                            </div>
                            <div class="col-12">
                                <div class="form-group">
                                    <?php echo CHtml::activeTextField($form, 'verifyCode', array('placeholder'=>$form->getAttributeLabel('enterVerifyCode'), 'class'=>'form-control mb-30')); ?>
                                </div>
                            </div>
                            <div class="col-12">
                                <?php echo CHtml::hiddenField('action', User::SCENARIO_SIGNUP); ?>
                                <button class="btn uza-btn btn-3 mt-15" style="width: 100%;">Зарегистрироваться</button>
                            </div>
                        </div>
                    <?php echo CHtml::endForm(); ?>
                </div>
                <div class="contact-heading mb-50">
                    <h5 style="text-align: center; margin-top: 70px;"><a href="<?php echo Yii::app()->createUrl('signin'); ?>" style="color: #1583e9">Войти в кабинет</a></h5>
                </div>
            </div>

And just in case, layouts/mini.php:
<?php if (Yii::app()->user->isGuest) { ?>

                            <!-- Get A Quote -->
                            <div class="get-a-quote ml-4 mr-3" style="margin-left: 0rem !important;">
                                <a href="<?php echo Yii::app()->createUrl('signin'); ?>" class="btn uza-btn">Вход</a>
                            </div>

                            <!-- Login / Register -->
                            <div class="login-register-btn mx-3" style="margin-left: 0rem !important;">
                                <a href="<?php echo Yii::app()->createUrl('signup'); ?>">Регистрация</a>
                            </div>

                        <?php } ?>

                        <?php if (!Yii::app()->user->isGuest) { ?>
                            <!-- Get A Quote -->
                            <div class="get-a-quote ml-4 mr-3" style="margin-left: 0rem !important;">
                                <a href="<?php echo Yii::app()->createUrl('user/profile'); ?>" class="btn uza-btn">Кабинет</a>
                            </div>

                            <!-- Login / Register -->
                            <div class="login-register-btn mx-3" style="margin-left: 0rem !important;">
                                <a href="<?php echo Yii::app()->createUrl('user/signout'); ?>">Выйти</a>
                            </div>

                        <?php } ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Kizyma, 2019-05-17
@Brain_code

$_POST['User'] - no need to write like thisYii::@app->request->post('user');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question