Example #1
0
 public function run()
 {
     /** @var User $user */
     $user = Yii::$app->user->identity;
     if ($user === null) {
         throw new ServerErrorHttpException("No user identity found");
     }
     $user->setScenario(User::SCENARIO_PROFILE_UPDATE);
     if ($user->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             // perform AJAX validation
             echo ActiveForm::validate($user);
             Yii::$app->end();
             return '';
         }
         if ($user->username_is_temporary && count($user->getDirtyAttributes(['username'])) === 1) {
             $user->username_is_temporary = false;
         }
         if ($user->save()) {
             $returnUrl = RedirectHelper::getPostedReturnUrl();
             if ($returnUrl !== null) {
                 return $this->controller->redirect($returnUrl);
             } else {
                 Yii::$app->session->setFlash('success', Yii::t('users', 'Your profile sucessfully updated.'));
             }
         }
     }
     return $this->controller->render($this->viewFile, ['profileWidgetOptions' => $this->profileWidgetOptions, 'user' => $user]);
 }
        </div>


    </div>

<?php 
if (\DevGroup\Users\UsersModule::module()->enableSocialNetworks === true) {
    ?>
    <div class="login-form__social-networks">
        <div class="m-form__line">
            <div class="m-form__col">
                <div class="title-soc-login"><?php 
    echo Yii::t('users', 'Login using social network');
    ?>
:</div>
            </div>
        </div>
        <div class="m-form__line">
            <div class="m-form__col">
                <?php 
    echo \DevGroup\Users\widgets\SocialNetworksWidget::widget(['baseAuthUrl' => ['@social', 'returnUrl' => RedirectHelper::getReturnUrl()]]);
    ?>
            </div>
        </div>
    </div>
    <?php 
}
?>

<?php 
ActiveForm::end();
<?php

/** @var \yii\web\View $this */
/** @var array $formOptions */
/** @var \DevGroup\Users\models\User $user */
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>
<div class="user-profile-form">
<?php 
$form = ActiveForm::begin($formOptions);
$returnUrl = \DevGroup\Frontend\RedirectHelper::getReturnUrl();
echo Html::hiddenInput('returnUrl', $returnUrl);
$usernameOptions = ['class' => 'user-profile-form__username'];
if ($user->username_is_temporary) {
    $usernameOptions['class'] .= ' input-edit';
    echo $form->field($user, 'username', ['options' => $usernameOptions]);
} else {
    $usernameOptions['class'] .= ' input-stat';
    echo Html::tag('label', $user->getAttributeLabel('username'));
    echo Html::tag('div', $user->username, $usernameOptions);
}
$module = \DevGroup\Users\UsersModule::module();
$attributes = ['email' => true, 'phone' => false];
foreach ($attributes as $attribute => $changeOnlyOnce) {
    if (in_array($attributes, $module->disabledUserAttributes) === false) {
        echo '<div class="m-form__line"><div class="m-form__col">';
        $options = ['class' => "user-profile-form__{$attribute}"];
        if (empty($user->{$attribute}) || $changeOnlyOnce === false) {
            $options['class'] .= ' input-edit';
            echo $form->field($user, $attribute, ['options' => $options]);
Example #4
0
 protected function redirectToProfileUpdate()
 {
     $url = ['@profile-update'];
     $url['returnUrl'] = RedirectHelper::getReturnUrl();
     $this->successUrl = Url::to($url);
 }