/**
  * Registration user
  */
 public function actionRegistration()
 {
     Profile::$regMode = true;
     $model = new RegistrationForm();
     $profile = new Profile();
     $module = Module::getInstance();
     // ajax validator
     //        if (Yii::$app->request->isAjax) {
     //            if ($model->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
     //                Yii::$app->response->format = Response::FORMAT_JSON;
     //                return ActiveForm::validateMultiple([$model, $profile]);
     //            }
     //        }
     if (Yii::$app->user->id) {
         $this->redirect($module->profileUrl);
     } else {
         if ($model->load(Yii::$app->request->post())) {
             $profile->load(Yii::$app->request->post());
             if ($model->validate() && $profile->validate()) {
                 $model->activkey = Module::encrypting(microtime() . $model->password);
                 $model->superuser = 0;
                 $model->status = $module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE;
                 if ($model->save(false)) {
                     $profile->user_id = $model->id;
                     $profile->save(false);
                     if ($module->sendActivationMail) {
                         $url = Url::to(array_merge($module->activationUrl, ["activkey" => $model->activkey, "email" => $model->email]), true);
                         $activation_url = Html::a($url, $url);
                         Module::sendMail($model->email, Module::t("{site_name} account activation", ['site_name' => Yii::$app->name]), 'register', ['activation_url' => $activation_url]);
                     }
                     if (($module->loginNotActiv || $module->activeAfterRegister && $module->sendActivationMail == false) && $module->autoLogin) {
                         Yii::$app->user->login($model);
                         $this->redirect($module->returnUrl);
                     } else {
                         if (!$module->activeAfterRegister && !$module->sendActivationMail) {
                             Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Contact Admin to activate your account."));
                         } elseif ($module->activeAfterRegister && $module->sendActivationMail == false) {
                             Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please {{login}}.", ['{{login}}' => Html::a(Module::t('Login'), $module->loginUrl)]));
                         } elseif ($module->loginNotActiv) {
                             Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please check your email or login."));
                         } else {
                             Yii::$app->user->setFlash('success', Module::t("Thank you for your registration. Please check your email."));
                         }
                         return $this->refresh();
                     }
                 }
             } else {
                 $profile->validate();
             }
         }
         return $this->render('/user/registration', ['model' => $model, 'profile' => $profile]);
     }
 }
Example #2
0
}
Module::getInstance()->setMenu($menu);
?>
    <h1><?php 
echo Module::t('Your profile');
?>
</h1>

<?php 
$attributes = ['username', 'email:email', 'create_at:date', 'lastvisit_at:date'];
$profileFields = ProfileField::find()->forOwner()->sort()->all();
if ($profileFields) {
    foreach ($profileFields as $field) {
        $val = '';
        if ($field->widgetView($model->profile)) {
            $val = $field->widgetView($model->profile);
        } else {
            if ($field->range) {
                $val = Profile::range($field->range, $model->profile->getAttribute($field->varname));
            } else {
                $val = $model->profile->getAttribute($field->varname);
            }
        }
        $type = 'html';
        if ($field->field_type == "DATE" || $field->widget == "UWjuidate") {
            $type = 'date';
        }
        array_push($attributes, ['label' => Module::t($field->title), 'name' => $field->varname, 'format' => $type, 'value' => $val]);
    }
}
echo DetailView::widget(['model' => $model, 'attributes' => $attributes]);
Example #3
0
    <?php 
$form = ActiveForm::begin(['id' => 'profile-form', 'enableAjaxValidation' => true, 'options' => ['enctype' => 'multipart/form-data']]);
?>

    <p class="note"><?php 
echo Module::t('Fields with <span class="required">*</span> are required.');
?>
</p>

    <?php 
echo $form->errorSummary([$model, $profile]);
?>

    <?php 
$profileFields = Profile::getFields();
if ($profileFields) {
    foreach ($profileFields as $field) {
        echo $field->renderField($profile, $form);
    }
}
?>

    <?php 
echo $form->field($model, 'username');
?>

    <?php 
echo $form->field($model, 'email');
?>
Example #4
0
 /**
  * @param $profile Profile
  * @param $form ActiveForm
  * @return string
  */
 public function renderField($profile, $form)
 {
     $input = $form->field($profile, $this->varname);
     if ($widgetEdit = $this->widgetEdit($profile, ['formField' => $input])) {
         return $widgetEdit;
     } elseif ($this->range) {
         return $input->dropDownList(Profile::range($this->range));
     } elseif ($this->field_type == "TEXT") {
         return $input->textarea(['rows' => 6, 'cols' => 50]);
     } else {
         return $input->textInput(['size' => 60, 'maxlength' => $this->field_size ? $this->field_size : 255]);
     }
 }
Example #5
0
    ?>

            <?php 
    echo $form->field($model, 'email');
    ?>

            <?php 
    $profileFields = Profile::getFields();
    if ($profileFields) {
        foreach ($profileFields as $field) {
            /**@var \marsoltys\yii2user\models\ProfileField $field*/
            $input = $form->field($profile, $field->varname);
            if ($widgetEdit = $field->widgetEdit($profile)) {
                echo $widgetEdit;
            } elseif ($field->range) {
                echo $input->dropDownList(Profile::range($field->range));
            } elseif ($field->field_type == "TEXT") {
                echo $input->textarea(['rows' => 6, 'cols' => 50]);
            } else {
                echo $input->textInput(['size' => 60, 'maxlength' => $field->field_size ? $field->field_size : 255]);
            }
        }
    }
    ?>

            <?php 
    if (Module::doCaptcha('registration')) {
        echo $form->field($model, 'captcha')->widget(\yii\captcha\Captcha::classname(), ['captchaAction' => '/site/captcha'])->hint(Module::t("Please enter the letters as they are shown in the image above.") . "<br/>" . Module::t("Letters are not case-sensitive."));
    }
    ?>
Example #6
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  */
 public function actionDelete()
 {
     if (Yii::$app->request->isPost) {
         // we only allow deletion via POST request
         $model = $this->loadModel();
         /** @var Profile $profile */
         $profile = Profile::findOne($model->id);
         // Make sure profile exists
         if ($profile) {
             $profile->delete();
         }
         $model->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (Yii::$app->request->isAjax) {
             return '';
         }
         return $this->redirect(['/user/admin']);
     } else {
         throw new HttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
Example #7
0
 /**
  * Relations
  */
 public function getProfile()
 {
     return $this->hasOne(Profile::className(), ['user_id' => 'id']);
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  */
 public function actionDelete()
 {
     if (Yii::$app->request->isPost) {
         // we only allow deletion via POST request
         $scheme = get_class(Yii::$app->db->schema);
         $model = $this->loadModel();
         if ($scheme == 'yii\\db\\sqlite\\Schema') {
             $attr = Profile::getFields();
             unset($attr[$model->varname]);
             $attr = array_keys($attr);
             $connection = Yii::$app->db;
             $transaction = $connection->beginTransaction();
             $status = true;
             try {
                 $connection->createCommand("CREATE TEMPORARY TABLE " . Profile::tableName() . "_backup (" . implode(',', $attr) . ")")->execute();
                 $connection->createCommand("INSERT INTO " . Profile::tableName() . "_backup SELECT " . implode(',', $attr) . " FROM " . Profile::tableName())->execute();
                 $connection->createCommand("DROP TABLE " . Profile::tableName())->execute();
                 $connection->createCommand("CREATE TABLE " . Profile::tableName() . " (" . implode(',', $attr) . ")")->execute();
                 $connection->createCommand("INSERT INTO " . Profile::tableName() . " SELECT " . implode(',', $attr) . " FROM " . Profile::tableName() . "_backup")->execute();
                 $connection->createCommand("DROP TABLE " . Profile::tableName() . "_backup")->execute();
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollBack();
                 $status = false;
             }
             if ($status) {
                 $model->delete();
             }
         } else {
             try {
                 $model->getDb()->createCommand()->dropColumn(Profile::tableName(), $model->varname)->execute();
             } catch (\yii\db\Exception $e) {
                 Yii::$app->user->setFlash(Module::ALERT_ERROR, Module::t('Error deleteing Profile table column {column}', ['column' => $model->varname]));
             }
             $model->delete();
         }
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!Yii::$app->request->isAjax) {
             $this->redirect(['admin']);
         }
     } else {
         throw new HttpException(400, Module::t('Invalid request.'));
     }
 }