예제 #1
0
 /**
  * Authenticates the password.
  * This is the 'authenticate' validator as declared in rules().
  */
 public function authenticate()
 {
     if (!$this->hasErrors()) {
         $user = new User();
         $identity = $user->authenticate($this->username, $this->password);
         switch ($identity->errorCode) {
             case User::ERROR_NONE:
                 $duration = $this->rememberMe ? Module::getInstance()->rememberMeTime : 0;
                 Yii::$app->user->login($identity, $duration);
                 break;
             case User::ERROR_EMAIL_INVALID:
                 $this->addError("username", Module::t("Email is incorrect."));
                 break;
             case User::ERROR_USERNAME_INVALID:
                 $this->addError("username", Module::t("Username is incorrect."));
                 break;
             case User::ERROR_STATUS_NOTACTIV:
                 $this->addError("status", Module::t("Your account is not activated."));
                 break;
             case User::ERROR_STATUS_BAN:
                 $this->addError("status", Module::t("Your account is blocked."));
                 break;
             case User::ERROR_PASSWORD_INVALID:
                 $this->addError("password", Module::t("Password is incorrect."));
                 break;
         }
     }
 }
예제 #2
0
 public function checkexists()
 {
     if (!$this->hasErrors()) {
         // we only want to authenticate when no input errors
         /**@var User $user*/
         if (strpos($this->login_or_email, "@")) {
             $user = User::findOne(['email' => $this->login_or_email]);
             if ($user) {
                 $this->user_id = $user->id;
             }
         } else {
             $user = User::findOne(['username' => $this->login_or_email]);
             if ($user) {
                 $this->user_id = $user->id;
             }
         }
         if ($user === null) {
             if (strpos($this->login_or_email, "@")) {
                 $this->addError("login_or_email", Module::t("Email is incorrect."));
             } else {
                 $this->addError("login_or_email", Module::t("Username is incorrect."));
             }
         }
     }
 }
예제 #3
0
 /**
  * Verify Old Password
  */
 public function verifyOldPassword($attribute, $params)
 {
     $current = User::find()->notsafe()->findByPk(Yii::$app->user->id)->one()->password;
     $cond = Yii::$app->security->validatePassword($this->{$attribute}, $current);
     if (!$cond) {
         $this->addError($attribute, Module::t("Old Password is incorrect."));
     }
 }
예제 #4
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the primary key value. Defaults to null, meaning using the 'id' GET variable
  * @return User
  * @throws NotFoundHttpException
  */
 public function loadUser($id = null)
 {
     if ($this->model === null) {
         if ($id !== null || Yii::$app->request->get('id')) {
             $this->model = User::findOne($id !== null ? $id : Yii::$app->request->get('id'));
         }
         if ($this->model === null) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $this->model;
 }
예제 #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]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['create_at' => $this->create_at, 'lastvisit_at' => $this->lastvisit_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'superuser', $this->superuser])->andFilterWhere(['like', 'status', $this->status]);
     return $dataProvider;
 }
예제 #6
0
 /**  User model relation  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
예제 #7
0
 /** Encrypt password before saving to database */
 public function beforeSave($insert)
 {
     $this->password = Module::encrypting($this->password);
     return parent::beforeSave($insert);
 }
예제 #8
0
 /**
  * Return safe user data.
  * @param $username string user name
  * @return user object or false
  */
 public static function getUserByName($username)
 {
     $_userByName = [];
     if (!isset(self::$userByName[$username])) {
         $_userByName[$username] = User::findOne(['username' => $username]);
     }
     return $_userByName[$username];
 }
예제 #9
0
?>

        <?php 
echo $form->field($model, 'password')->passwordInput(['maxlength' => true]);
?>

        <?php 
echo $form->field($model, 'email')->textInput(['maxlength' => true]);
?>

        <?php 
echo $form->field($model, 'superuser')->dropDownList(User::itemAlias('AdminStatus'));
?>

        <?php 
echo $form->field($model, 'status')->dropDownList(User::itemAlias('UserStatus'));
?>

        <?php 
$profileFields = Profile::getFields();
if ($profileFields) {
    foreach ($profileFields as $field) {
        echo $field->renderField($profile, $form);
    }
}
?>
        <div class="form-group">
            <?php 
echo Html::submitButton($model->isNewRecord ? Module::t('Create') : Module::t('Save'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
        </div>
예제 #10
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @return User
  * @throws HttpException
  */
 public function loadModel()
 {
     if ($this->model === null) {
         if (Yii::$app->request->get('id')) {
             $this->model = User::find()->notsafe()->findbyPk(Yii::$app->request->get('id'))->one();
         }
         if ($this->model === null) {
             throw new NotFoundHttpException('The requested page does not exist.');
         }
     }
     return $this->model;
 }
예제 #11
0
<?php 
\yii\widgets\Pjax::begin();
?>

<?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'id', 'format' => 'raw', 'value' => function ($data) {
    return Html::a(Html::encode($data->id), ["admin/update", "id" => $data->id]);
}], ['attribute' => 'username', 'format' => 'raw', 'value' => function ($data) {
    return Html::a(UHtml::markSearch($data, "username"), ["admin/view", "id" => $data->id]);
}], ['attribute' => 'email', 'format' => 'raw', 'value' => function ($data) {
    return Html::a(UHtml::markSearch($data, "email"), "mailto:" . $data->email);
}], 'create_at', 'lastvisit_at', ['attribute' => 'superuser', 'value' => function ($data) {
    return User::itemAlias("AdminStatus", $data->superuser);
}, 'filter' => User::itemAlias("AdminStatus")], ['attribute' => 'status', 'value' => function ($data) {
    return User::itemAlias("UserStatus", $data->status);
}, 'filter' => User::itemAlias("UserStatus")], ['class' => 'yii\\grid\\ActionColumn', 'header' => Module::t('Actions')]]]);
?>

<?php 
\yii\widgets\Pjax::end();
?>

<?php 
//$this->widget('zii.widgets.grid.CGridView', array(
//    'id'=>'user-grid',
//    'dataProvider'=>$model->search(),
//    'filter'=>$model,
//    'columns'=>array(
//        array(
//            'name' => 'id',
//            'type'=>'raw',
예제 #12
0
파일: view.php 프로젝트: marsoltys/yii2user
?>

<h1><?php 
echo Module::t('View User') . ' "' . $model->username . '"';
?>
</h1>

<?php 
$attributes = ['id', 'username'];
$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]);
    }
}
array_push($attributes, 'password', 'email:email', 'activkey', 'create_at:date', 'lastvisit_at:date', ['attribute' => 'superuser', 'value' => User::itemAlias("AdminStatus", $model->superuser)], ['attribute' => 'status', 'value' => User::itemAlias("UserStatus", $model->status)]);
echo DetailView::widget(['model' => $model, 'attributes' => $attributes]);
예제 #13
0
 private function lastVisit()
 {
     /** @var $lastVisit User*/
     $lastVisit = User::findOne(Yii::$app->user->id);
     $lastVisit->lastvisit_at = date('Y-m-d H:i:s');
     $lastVisit->save();
 }