Exemplo n.º 1
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->real_name = $this->real_name;
         $user->setPassword($this->password);
         $user->save();
         return $user;
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Exemplo n.º 4
0
 /**
  * Creates a form model given a token.
  *
  * @param  string                          $token
  * @param  array                           $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($token, $config = [])
 {
     if (empty($token) || !is_string($token)) {
         throw new InvalidParamException(Yii::t('maddoger/admin', 'Password reset token cannot be blank.'));
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException(Yii::t('maddoger/admin', 'Wrong password reset token.'));
     }
     parent::__construct($config);
 }
Exemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'status' => $this->status, 'last_visit_at' => $this->last_visit_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'access_token', $this->access_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'real_name', $this->real_name])->andFilterWhere(['like', 'avatar', $this->avatar]);
     return $dataProvider;
 }
 /**
  * Sends an email with a link, for resetting the password.
  *
  * @return boolean whether the email was send
  */
 public function sendEmail()
 {
     /* @var $user User */
     $user = User::findOne(['status' => User::STATUS_ACTIVE, 'email' => $this->email]);
     if ($user) {
         if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
             $user->generatePasswordResetToken();
         }
         if ($user->save()) {
             return \Yii::$app->mailer->compose('passwordResetToken', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject(\Yii::t('maddoger/admin', 'Password reset for {app}', ['app' => \Yii::$app->name]))->send();
         }
     }
     return false;
 }
Exemplo n.º 7
0
?>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-title"><?php 
echo Yii::t('maddoger/admin', 'Status');
?>
</div>
                </div>
                <div class="panel-body">
                    <?php 
echo $form->field($model, 'role')->dropDownList(User::getRoleList());
?>
                    <?php 
echo $form->field($model, 'status')->dropDownList(User::getStatusList());
?>
                </div>
            </div>
        </div>
    </div>

    <div class="form-group">
        <div class="btn-group">
            <?php 
echo Html::submitButton(Yii::t('maddoger/admin', 'Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
            <?php 
echo Html::submitButton(Yii::t('maddoger/admin', 'Save and exit'), ['name' => 'redirect', 'value' => 'exit', 'class' => 'btn btn-default']);
?>
            <?php 
Exemplo n.º 8
0
 /**
  * @return string
  */
 public function actionInstall()
 {
     //Check users count
     if (User::find()->count() > 0) {
         return $this->redirect(['index']);
     }
     $this->layout = 'base';
     $model = new SignupForm();
     if ($model->load(Yii::$app->request->post()) && ($user = $model->signup())) {
         //Update roles
         RoleController::updateRoles(true, $user->id, $this->module->superUserRole);
         return $this->redirect(['index']);
     } else {
         return $this->render('signup', ['model' => $model]);
     }
 }
Exemplo n.º 9
0
<?php

use maddoger\admin\models\User;
use yii\grid\GridView;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $searchModel maddoger\admin\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('maddoger/admin', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <div class="panel panel-default">
        <div class="panel-body">

            <p>
                <?php 
echo Html::a('<i class="glyphicon glyphicon-plus"></i> ' . Yii::t('maddoger/admin', 'Create user'), ['create'], ['class' => 'btn btn-success']);
?>
            </p>

            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'username', 'email:email', 'real_name', ['attribute' => 'role', 'filter' => User::getRoleList(), 'value' => 'roleDescription'], ['attribute' => 'status', 'filter' => User::getStatusList(), 'value' => 'statusDescription'], ['class' => 'yii\\grid\\ActionColumn']]]);
?>
        </div>
    </div>

</div>