Example #1
0
 /**
  * @inheritdoc
  */
 public function loginRequired($checkAjax = true, $checkAcceptHeader = true)
 {
     if ($this->enableSession && (!$checkAjax || !Yii::$app->getRequest()->getIsAjax())) {
         Yii::$app->session->setFlash('flash-warning', HUsers::t('messages', 'This page is restricted to authenticated users'));
     }
     return parent::loginRequired($checkAjax, $checkAcceptHeader);
 }
 /**
  * Si le formulaire est valide, on crée une clé d'identification & on expédie à l'utilisateur un mail de ré-initialisation
  *
  * @return bool
  */
 public function processRequest()
 {
     if ($this->validate()) {
         try {
             /** @var User $user */
             if (!($user = User::findIdentityByEmail($this->email))) {
                 // CHECK_SECURITY
                 // On ne devrait pas avoir ce cas là puisque l'existence du mail dans la base de données a été vérifiée dans lr formulaire
                 // Il s'agit sans doute d'une tentative de piratage
                 return false;
             }
             $user->reset_password_token = Yii::$app->getSecurity()->generateRandomString();
             if (!$user->save()) {
                 Yii::error('Erreur sur $user->save()', __METHOD__);
                 return false;
             }
             Yii::$app->mailer->compose('/mail/askResetPassword', compact('user'))->setFrom(Yii::$app->params['adminEmail'])->setTo(h::safeRecipientEmail($user->email))->setSubject(HUsers::t('titles', 'Your password reset request'))->send();
             return true;
         } catch (Exception $x) {
             Yii::error($x->getMessage(), __METHOD__);
             return false;
         }
     } else {
         return false;
     }
 }
Example #3
0
 /**
  * Validates the password.
  * This method serves as the inline validation for password.
  *
  * @param string $attribute the attribute currently being validated
  * @param array  $params the additional name-value pairs given in the rule
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         /** @var User $user */
         $user = $this->getUser();
         if (!$user || !$user->validateAuthKey($this->password)) {
             $this->addError($attribute, HUsers::t('messages', 'Incorrect email or password'));
         }
     }
 }
 /**
  * Vérifie que le mail existe bien dans la base de données et que le jeton associé correspond à celui du formulaire
  *
  * @param string $attribute the attribute currently being validated
  */
 public function validateEmail($attribute)
 {
     if (!$this->hasErrors()) {
         /** @var User $user */
         $user = $this->getUser();
         if (!$user) {
             $this->addError($attribute, HUsers::t('messages', 'Invalid email address'));
         }
         if ($user->reset_password_token != $this->reset_password_token) {
             $this->addError($attribute, HUsers::t('messages', 'Invalid token, request denied'));
         }
     }
 }
Example #5
0
/**
 * Formulaire pour la création ou la modification de l'objet
 */
use app\modules\users\HUsers;
use yii\helpers\Url;
use yii\widgets\Activeform;
/**
 * @var $this yii\web\View
 * @var $model app\modules\users\models\User
 * @var $form yii\widgets\ActiveForm
 * @var $parameters array
 * @var $roles array [id => name] liste des rôles disponibles
 */
$this->registerJs('
    $(\'#roles_ids\').select2({
        placeholder: "' . HUsers::t('labels', 'Add roles') . '"
    });
');
?>

<div class="role-form">

    <?php 
$form = ActiveForm::begin($parameters);
?>

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

    <?php 
Example #6
0
echo Html::encode($this->title);
?>
</h1>
                </div>

                <div class="panel-body">
                    <?php 
$form = ActiveForm::begin(['id' => 'reset-password-form', 'options' => ['class' => 'form-horizontal', 'role' => 'form'], 'fieldConfig' => ['template' => "{label}\n<div class=\"col-md-6\">{input}</div>\n                                            <div class=\"col-md-6\">{error}</div>", 'labelOptions' => ['class' => 'col-md-4 control-label']]]);
?>

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

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <?php 
echo Html::submitButton(HUsers::t('labels', 'Ask for password reset'), ['class' => 'btn btn-primary', 'name' => 'login-button']);
?>
                        </div>
                    </div>
                    <?php 
ActiveForm::end();
?>
                </div>

            </div>
        </div>
    </div>
</div>
Example #7
0
<?php

/**
 * Formulaire de création
 */
use app\modules\users\HUsers;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\modules\users\models\User */
$this->title = HUsers::t('titles', 'Create a new user');
$this->params['breadcrumbs'][] = ['label' => HUsers::t('labels', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
$formParameters = [];
?>
<div class="row panel panel-default">
    <div class="panel-heading">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    </div>

    <div class="panel-body">
        <?php 
echo $this->render('_form', ['model' => $model, 'parameters' => $formParameters]);
?>
    </div>
</div>
Example #8
0
echo $form->field($model, 'password')->passwordInput();
?>

                <?php 
echo $form->field($model, 'rememberMe')->checkbox(null, false);
?>

                <div class="form-group">
                    <div class="col-md-6 col-md-offset-4">
                        <?php 
echo Html::submitButton(HUsers::t('labels', 'Login'), ['class' => 'btn btn-primary', 'name' => 'login-button']);
?>
                        <a class="btn btn-link" href="<?php 
echo Url::toRoute('/users/auth/ask-password-reset', true);
?>
">
                            <?php 
echo HUsers::t('labels', 'Forgot password ?');
?>
                        </a>
                    </div>
                </div>
                <?php 
ActiveForm::end();
?>
            </div>

        </div>
    </div>
</div>
Example #9
0
                <?php 
echo HUsers::t('labels', 'Create a new role');
?>
            </a>
        </div>

        <?php 
if ($count) {
    ?>
            <?php 
    echo LinkPager::widget(['pagination' => $dataProvider->getPagination()]);
    ?>

            <ul class="list-group">
                <?php 
    echo GridListHeader::widget(['columns' => [["width" => 5, "label" => HUsers::t('labels', 'Roles')], ["width" => 5, "label" => HUsers::t('labels', 'Users')], ["width" => 2, "label" => HLib::t('labels', 'Actions'), "cssClass" => "object-actions text-right"]]]);
    ?>

                <?php 
    foreach ($roles as $model) {
        ?>
                    <li class="list-group-item">
                        <div class="row">
                            <div class="col-sm-5">
                                <?php 
        echo $model->name;
        ?>
                            </div>

                            <div class="col-sm-5">
                                <?php 
Example #10
0
?>

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

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

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

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <?php 
echo Html::submitButton(HUsers::t('labels', 'Register'), ['class' => 'btn btn-primary', 'name' => 'login-button']);
?>
                        </div>
                    </div>
                    <?php 
ActiveForm::end();
?>
                </div>

            </div>
        </div>
    </div>
</div>
Example #11
0
 /**
  * Inscription d'un utilisateur / affichage initial du formulaire
  *
  * @return string|\yii\web\Response
  */
 public function actionRegister()
 {
     $model = new AuthUser(['scenario' => User::SCENARIO_CREATE]);
     if (Yii::$app->request->isPost) {
         // Traitement du formulaire
         if ($model->load(Yii::$app->request->post()) && $model->registerUser()) {
             Yii::$app->session->setFlash('flash-success', HUsers::t('messages', 'Your user account is registered'));
             return $this->goBack();
         } else {
             Yii::$app->session->setFlash('flash-warning', HUsers::t('messages', 'The registration failed'));
         }
     }
     // Affichage ou ré-affichage
     return $this->render('register', compact('model'));
 }
Example #12
0
 /**
  * Si on met à jour un email depuis le backend admin, il faut s'assurer que la nouvelle adresse mail sn'est pas déjà prise
  *
  * @param string $attribute the attribute currently being validated
  */
 public function validateUpdatedEmail($attribute)
 {
     if (!$this->hasErrors()) {
         if ($newEmail = hArray::getValue($this->getDirtyAttributes(), 'email')) {
             if (User::findIdentityByEmail($newEmail)) {
                 $this->addError($attribute, HUsers::t('messages', 'This user already exists'));
             }
         }
     }
 }
Example #13
0
<div class="row panel panel-default">
    <div class="panel-heading">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    </div>

    <div class="panel-body">

        <?php 
echo ViewButtons::widget(['modelId' => $model->id, 'controllerPath' => '/users/roles']);
?>

        <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['name']]);
?>

        <?php 
echo DetailView::widget(['model' => $model, 'attributes' => [['label' => HUsers::t('labels', 'Users'), 'value' => ViewModelsList::widget(['models' => $model->users, 'labelMethod' => function (User $user) {
    return $user->name . ' (' . $user->email . ')';
}, 'controllerRoute' => '/users/users']), 'format' => 'html']]]);
?>

        <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['created_at', 'updated_at']]);
?>

    </div>
</div>
Example #14
0
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model app\modules\users\models\User */
$this->title = HUsers::t('titles', 'View user') . ' : ' . $model->name;
$this->params['breadcrumbs'][] = ['label' => HUsers::t('labels', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => Url::toRoute(['/users/users/view', 'id' => $model->id])];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="row panel panel-default">
    <div class="panel-heading">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    </div>

    <div class="panel-body">

        <?php 
echo ViewButtons::widget(['modelId' => $model->id, 'controllerPath' => '/users/users']);
?>

        <?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'name', 'email:email', ['label' => HUsers::t('labels', 'Roles'), 'value' => implode(', ', $model->getRolesNames())], 'reset_password_token', 'created_at', 'updated_at']]);
?>

    </div>
</div>
Example #15
0
<?php

/**
 * Formulaire de mise à jour
 */
use app\modules\users\HUsers;
use yii\helpers\Html;
/**
 * @var $this yii\web\View
 * @var $model app\modules\users\models\Role
 */
$this->title = HUsers::t('titles', 'Update a role');
$formParameters = [];
?>
<div class="row panel panel-default">
    <div class="panel-heading">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    </div>

    <div class="panel-body">
        <?php 
echo $this->render('_form', ['model' => $model, 'parameters' => $formParameters]);
?>
    </div>
</div>
Example #16
0
<?php

/**
 * Formulaire de création
 */
use app\modules\users\HUsers;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model app\modules\users\models\Role */
$this->title = HUsers::t('titles', 'Create a new role');
$formParameters = [];
?>
<div class="row panel panel-default">
    <div class="panel-heading">
        <h1><?php 
echo Html::encode($this->title);
?>
</h1>

        <div class="header-note bg-warning">
            Attention : ajouter un rôle n'aura aucun effet tant qu'il n'est pas implémenté dans le code de
            l'application
        </div>
    </div>

    <div class="panel-body">
        <?php 
echo $this->render('_form', ['model' => $model, 'parameters' => $formParameters]);
?>
    </div>
</div>