Exemple #1
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->setPassword($this->password);
         $user->generateAuthKey();
         $user->save();
         //            $this->sendEmail($user);
         return $user;
     }
     return null;
 }
 public function signIn()
 {
     $attributes = $this->getUserAttributes();
     $password = Yii::$app->security->generateRandomString(6);
     $user = new User(['password' => $password]);
     if ($attributes['emails']) {
         $email = current($attributes['emails']);
         $user->email = $email['value'];
     }
     if ($attributes['name']) {
         $user->first_name = isset($attributes['name']['givenName']) ? $attributes['name']['givenName'] : '';
         $user->last_name = isset($attributes['name']['familyName']) ? $attributes['name']['familyName'] : '';
     }
     $user->generateAuthKey();
     $user->generatePasswordResetToken();
     $transaction = $user->getDb()->beginTransaction();
     if ($user->save()) {
         // create empty profile
         $profile = new UserProfile(['user_id' => $user->getId()]);
         $profile->save();
         if (isset($attributes['image'])) {
             if ($attributes['image']['url']) {
                 // upload facebook images
                 $prepareUrl = substr($attributes['image']['url'], 0, strpos($attributes['image']['url'], '?'));
                 $fname = basename($prepareUrl);
                 $ch = curl_init($attributes['image']['url']);
                 $fp = fopen(Yii::getAlias('@uploads/users/' . $fname), 'wb');
                 curl_setopt($ch, CURLOPT_FILE, $fp);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_exec($ch);
                 curl_close($ch);
                 fclose($fp);
                 $user->avatar = $fname;
             }
         }
         $user->update(false);
         // assign role default ROLE_USER
         $authManager = Yii::$app->authManager;
         $authManager->assign($authManager->getRole(User::ROLE_USER), $user->getId());
         $auth = new UserAuth(['user_id' => $user->id, 'source' => $this->getId(), 'source_id' => (string) $attributes['id']]);
         if ($auth->save()) {
             $transaction->commit();
             // auto login
             Yii::$app->user->login($user);
             return true;
         } else {
             Yii::$app->getSession()->setFlash('error', 'Auth client  "' . $this->getTitle() . '" not connected');
         }
     } else {
         Yii::$app->getSession()->setFlash('error', 'User "' . $attributes['login'] . '" not register');
     }
     return false;
 }
Exemple #3
0
 public function getUser()
 {
     if ($this->_user === false && $this->validate()) {
         $this->_user = User::findIdentity(UsersAuth::getUserId($this->auth_id, $this->service));
     }
     return $this->_user;
 }
Exemple #4
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 /**
  * @param $client
  *
  * TODO
  */
 public function onAuthSuccess(ClientInterface $client)
 {
     $attributes = $client->getUserAttributes();
     /* @var $auth UserAuth */
     $auth = UserAuth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one();
     if (Yii::$app->user->isGuest) {
         if ($auth) {
             $user = $auth->user;
             Yii::$app->user->login($user);
         } else {
             if (isset($attributes['email']) && User::find()->where(['email' => $attributes['email']])->exists()) {
                 Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]);
             } else {
                 if ($client->signIn()) {
                     $this->redirect('/profile');
                 }
             }
         }
     } else {
         if (!$auth) {
             $auth = new UserAuth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]);
             $auth->save();
         }
     }
 }
 public function actionInit()
 {
     $auth = Yii::$app->authManager;
     // disable user
     /*$disable = $auth->createRole(User::ROLE_DISABLE);
       $disable->description = 'User Disable';
       $auth->add($disable);*/
     // banned user
     /*$banned = $auth->createRole(User::ROLE_BANNED);
       $banned->description = 'User Banned';
       $auth->add($banned);*/
     // add user login permission
     $userPermission = $auth->createPermission(User::PERMISSION_USER_LOGIN);
     $userPermission->description = 'Permission User Login';
     $auth->add($userPermission);
     // add default user role
     $user = $auth->createRole(User::ROLE_USER);
     $user->description = 'User Default Role';
     $auth->add($user);
     $auth->addChild($user, $userPermission);
     // add login to admin panel permission
     $adminPermission = $auth->createPermission(User::PERMISSION_ADMIN_LOGIN);
     $adminPermission->description = 'Permission Admin Login';
     $auth->add($adminPermission);
     // add "admin" role
     $admin = $auth->createRole(User::ROLE_ADMIN);
     $admin->description = 'User Super Admin';
     $auth->add($admin);
     $auth->addChild($admin, $user);
     $auth->addChild($admin, $adminPermission);
     // Create user admin assign roles
     User::createSuperAdmin();
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable(UserProfile::tableName(), ['user_id' => $this->primaryKey(), 'phone' => $this->string(10), 'site' => $this->string(255), 'description' => $this->string(2048), 'birthday' => $this->date()], $tableOptions);
     $this->addForeignKey('fk_profile_user', UserProfile::tableName(), 'user_id', User::tableName(), 'id', 'CASCADE', 'RESTRICT');
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable(Book::tableName(), ['id' => $this->primaryKey(), 'user_id' => $this->integer(), 'name' => $this->string(32)->notNull(), 'preview' => $this->string(255)->notNull(), 'date' => $this->integer(), 'created_at' => $this->integer(), 'updated_at' => $this->integer()], $tableOptions);
     $this->addForeignKey('fk_book', Book::tableName(), 'user_id', User::tableName(), 'id', 'CASCADE', 'RESTRICT');
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable(UserAuth::tableName(), ['id' => $this->primaryKey(), 'user_id' => $this->integer(11)->notNull(), 'source' => $this->string(255)->notNull(), 'source_id' => $this->string(255)->notNull()], $tableOptions);
     $this->addForeignKey('fk-auth-user_id-user-id', UserAuth::tableName(), 'user_id', User::tableName(), 'id', 'CASCADE', 'CASCADE');
 }
 public function actionView($id)
 {
     $modelUser = User::findOne(['id' => $id, 'status' => User::STATUS_ACTIVE]);
     $modelUserProfile = UserProfile::findOne(['user_id' => $modelUser->id]);
     $queryProducts = CatalogProducts::find()->where(['published' => true]);
     $queryProducts->andWhere(['createdby' => $modelUser->id]);
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $queryProducts->count()]);
     $elements = $queryProducts->orderBy('publishedon' . ' ' . 'desc')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('viewOwner', ['modelUser' => $modelUser, 'modelUserProfile' => $modelUserProfile, 'elements' => $elements, 'pagination' => $pagination]);
 }
 /**
  * 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('Password reset token cannot be blank.');
     }
     $this->_user = User::findByPasswordResetToken($token);
     if (!$this->_user) {
         throw new InvalidParamException('Wrong password reset token.');
     }
     parent::__construct($config);
 }
Exemple #13
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, 'createdon' => $this->createdon, 'updatedon' => $this->updatedon]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
 /**
  * Регистрация
  * @return array|string|Response
  */
 public function actionSignup()
 {
     $user = new models\User(['scenario' => 'signup']);
     $profile = new models\Profile(['scenario' => 'signup']);
     if ($user->load(Yii::$app->request->post()) && $profile->load(Yii::$app->request->post())) {
         if ($user->validate() && $profile->validate()) {
             $user->populateRelation('profile', $profile);
             if ($user->save(false)) {
                 if ($this->module->requireEmailConfirmation === true) {
                     Yii::$app->consoleRunner->run('users/control/send-email ' . $user->email . ' signup "' . Yii::t('users', 'SUBJECT_SIGNUP') . '"');
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITHOUT_LOGIN', ['url' => Url::toRoute('resend')]));
                 } else {
                     Yii::$app->user->login($user);
                     Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_SIGNUP_WITH_LOGIN'));
                 }
                 return $this->redirect(['login']);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_SIGNUP'));
                 return $this->refresh();
             }
         } else {
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($user);
             }
         }
     }
     return $this->render('signup', ['user' => $user, 'profile' => $profile]);
 }
 /**
  * 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(['id' => $this->id, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     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(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
 public function up()
 {
     $authManager = $this->getAuthManager();
     $this->db = $authManager->db;
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
     }
     $this->createTable($authManager->ruleTable, ['name' => $this->string(64)->notNull(), 'data' => $this->text(), 'created_at' => $this->integer(), 'updated_at' => $this->integer(), 'PRIMARY KEY (name)'], $tableOptions);
     $this->createTable($authManager->itemTable, ['name' => $this->string(64)->notNull(), 'type' => $this->integer()->notNull(), 'description' => $this->text(), 'rule_name' => $this->string(64), 'data' => $this->text(), 'created_at' => $this->integer(), 'updated_at' => $this->integer(), 'PRIMARY KEY (name)', 'FOREIGN KEY (rule_name) REFERENCES ' . $authManager->ruleTable . ' (name) ON DELETE SET NULL ON UPDATE CASCADE'], $tableOptions);
     $this->createIndex('idx-auth_item-type', $authManager->itemTable, 'type');
     $this->createTable($authManager->itemChildTable, ['parent' => $this->string(64)->notNull(), 'child' => $this->string(64)->notNull(), 'PRIMARY KEY (parent, child)', 'FOREIGN KEY (parent) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE', 'FOREIGN KEY (child) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
     $this->createTable($authManager->assignmentTable, ['item_name' => $this->string(64)->notNull(), 'user_id' => $this->integer(11)->notNull(), 'created_at' => $this->integer(), 'PRIMARY KEY (item_name, user_id)', 'FOREIGN KEY (item_name) REFERENCES ' . $authManager->itemTable . ' (name) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
     $this->addForeignKey('fk_auth_assignment_user', $authManager->assignmentTable, 'user_id', User::tableName(), 'id', 'CASCADE', 'RESTRICT');
 }
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $this->setGroup($this->group);
     if ($this->scenario == 'update') {
         // Сохраняем профиль
         $this->profile->save(false);
         // Сохраняем данные юридического лица
         if ($this->profile->legal_person) {
             if (!$this->person->user_id) {
                 $this->person->user_id = $this->id;
             }
             $this->person->save(false);
         }
     }
 }
 /**
  * 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()) {
             $mailer = \Yii::$app->mailer();
             $mailer->htmlLayout = '@common/modules/users/mails/layouts/html';
             $mailer->textLayout = '@common/modules/users/mails/layouts/text';
             $mailer->viewPath = '@common/modules/users/mails/views';
             return $mailer->compose('ru/recovery', ['user' => $user])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot'])->setTo($this->email)->setSubject('Password reset for ' . \Yii::$app->name)->send();
         }
     }
     return false;
 }
 /**
  * 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->setPassword($this->password);
         $user->generateAuthKey();
         // start transaction
         $transaction = $user->getDb()->beginTransaction();
         if ($user->save()) {
             // create empty profile
             $profile = new UserProfile(['user_id' => $user->getId()]);
             $profile->save();
             // assign disable user role ROLE_DISABLE
             $authManager = Yii::$app->authManager;
             $authManager->assign($authManager->getRole(User::ROLE_DISABLE), $user->getId());
             // end transaction
             $transaction->commit();
             return $user;
         }
     }
     return null;
 }
Exemple #21
0
?>

<div class="slide-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <div class="row">
        <div class="col-xs-4">
            <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

            <?php 
echo $form->field($model, 'user_id')->dropDownList(User::getUsersList());
?>

            <?php 
echo $form->field($model, 'date')->widget(DatePicker::className(), ['clientOptions' => []]);
?>

            <div class="row">
                <div class="col-xs-8">
                    <?php 
echo $form->field($model, 'imageFile')->fileInput();
?>
                </div>
                <div class="col-xs-4">
                   <?php 
echo ThumbHelper::getImg($model->img, 180, 38);
Exemple #22
0
                <?php 
echo $form->field($model, 'first_name')->textInput();
?>
                <?php 
echo $form->field($model, 'last_name')->textInput();
?>

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

                <?php 
echo $form->field($model, 'role')->widget(Select2::classname(), ['data' => User::getRolesList(), 'language' => 'en', 'options' => ['placeholder' => 'Select a role ...'], 'pluginOptions' => ['allowClear' => true]]);
?>

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

                <div class="row">
                    <div class="col-xs-8">
                        <?php 
echo $form->field($model, 'photoFile')->fileInput();
?>
                    </div>
                    <div class="col-xs-4">
                        <?php 
echo ThumbHelper::getImg($model->avatar, 100, 100, ['class' => 'pull-right']);
Exemple #23
0
 public function getAuthor()
 {
     $model = User::find()->select('username')->where('id=:id', [':id' => $this->user_id])->one();
     return $model ? $model->username : '';
 }
Exemple #24
0
<?php

use yii\helpers\Html;
use common\themes\admin\widgets\ActiveForm;
use yii\bootstrap\Tabs;
use common\modules\users\models\User;
use common\modules\filemanager\widgets\Image;
use andreosoft\summernote\Summernote;
?>

<?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data', 'boxTitle' => $options['title'], 'buttonUndo' => $options['buttonUndo']]]);
echo Tabs::widget(['options' => ['class' => 'nav-tabs-custom'], 'items' => [['label' => \Yii::t('users/main', 'Main'), 'content' => $form->field($model, 'username')->textInput(['maxlength' => 255]) . $form->field($model, 'email')->textInput(['maxlength' => 255]) . $form->field($model, 'status')->dropDownList(User::getStatusArray()) . $form->field($model, 'role')->dropDownList(User::getRoleArray()) . Html::a('Изменить пароль', ['new-password', 'id' => $model->id], ['class' => 'btn btn-primary'])], ['label' => \Yii::t('users/main', 'Profile'), 'content' => $form->field($modelProfile, 'fullname')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'phone')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'website')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'skype')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'image')->widget(Image::className())], ['label' => \Yii::t('users/main', 'Adress'), 'content' => $form->field($modelProfile, 'country')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'state')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'zip')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'city')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'address')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'geopoint_latitude')->textInput(['maxlength' => 255]) . $form->field($modelProfile, 'geopoint_longitude')->textInput(['maxlength' => 255])], ['label' => \Yii::t('users/main', 'About'), 'content' => $form->field($modelProfile, 'about')->widget(Summernote::className(), ['editorOptions' => ['height' => 200]])]]]);
?>

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

Exemple #25
0
<div class="comments-admin-form">

    <?php 
$form = ActiveForm::begin(['enableClientValidation' => true, 'options' => ['class' => 'modal-ajax-update', 'data-list' => 'comments-list']]);
?>
    <div class="row">
        <div class="col-lg-12">
            <?php 
echo $form->field($model, 'object')->dropDownList(Comments::getObjects(1), array('prompt' => ''));
?>
            <?php 
echo $form->field($model, 'object_id')->textInput();
?>
            <?php 
echo $form->field($model, 'user_id')->dropDownList(\common\modules\users\models\User::getUsersRoleUser(), ['prompt' => 'Выберите пользователя']);
?>
            <?php 
echo $form->field($model, 'date_create')->textInput(['class' => 'datepicker form-control']);
?>
            <?php 
echo $form->field($model, 'text')->textarea(['rows' => 5]);
?>
            <?php 
echo $form->field($model, 'show_main')->checkbox();
?>
            <?php 
echo $form->field($model, 'note')->textarea(['rows' => 3]);
?>
            <?php 
echo $form->field($model, 'status')->dropDownList(Comments::getStatusList(), array('prompt' => ''));
Exemple #26
0
 public static function changeRole($role_name, $user_id)
 {
     $auth = Yii::$app->getAuthManager();
     $role = $auth->getRole($role_name);
     $activeRole = current($auth->getRolesByUser($user_id));
     if ($activeRole->name == $role_name) {
         return true;
     }
     // if super user id = 1
     // role not change
     if ($user_id == 1) {
         Yii::$app->getSession()->setFlash('warning', Yii::t('users', 'Can not change user role for super admin'));
         return false;
     }
     if ($role) {
         $model = new User();
         $transaction = $model->getDb()->beginTransaction();
         $auth->revokeAll($user_id);
         $auth->assign($role, $user_id);
         $transaction->commit();
     }
     return true;
 }
Exemple #27
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('profile');
 }
 /**
  * Заблокировать пользователей
  * @return array|string|Response
  * @throws ForbiddenHttpException
  */
 public function actionBanned()
 {
     if (!Yii::$app->user->can('user-banned')) {
         throw new ForbiddenHttpException(Yii::t('users.rbac', 'ACCESS_DENIED'));
     }
     $users = models\User::findIdentities(Yii::$app->request->get('ids'));
     $model = new \nepster\users\models\Banned();
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         if ($model->validate()) {
             if ($model->bannedUsers($users)) {
                 Yii::$app->session->setFlash('success', Yii::t('users', 'SUCCESS_UPDATE'));
                 return $this->redirect(['index']);
             } else {
                 Yii::$app->session->setFlash('danger', Yii::t('users', 'FAIL_UPDATE'));
             }
             return $this->refresh();
         } else {
             if (Yii::$app->request->isAjax) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 return ActiveForm::validate($model);
             }
         }
     }
     return $this->render('banned', ['model' => $model, 'users' => $users]);
 }
 /**
  * Поиск пользователя
  * @return \nepster\users\models\User
  */
 public function getUser($username)
 {
     $scope = $this->scenario == 'admin' ? 'control' : null;
     /*
     $validator = new \yii\validators\EmailValidator();
     
     // Поиск пользователя по e-mail
     if ($validator->validate($username)) {
         return User::findByEmail($username, [$scope]);
     }
     // Поиск пользователя по телефону
     else if(strncasecmp($username, "+", 1) === 0) {
         $username = str_replace('+', '', $username);
         return User::findByPhone($username, [$scope]);
     }
     
     return User::findByUsername($username, [$scope]);
     */
     // Поиск пользователя по телефону
     if (strncasecmp($username, "+", 1) === 0) {
         $username = str_replace('+', '', $username);
         return User::findByPhone($username, [$scope]);
     } else {
         return User::findByEmail($username, [$scope]);
     }
 }
Exemple #30
0
    <?php 
echo GridView::widget(['options' => ['boxTitle' => $this->title, 'buttonCreate' => Url::to(['create', 'class' => $class]), 'buttonUndo' => Url::home(), 'buttonDelete' => Url::to(['batch-delete'])], 'id' => 'main-grid', 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname()], 'username', 'email', ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    if ($model->status === User::STATUS_ACTIVE) {
        $class = 'label-success';
        $lable = User::getStatusArray()[$model->status];
    } elseif ($model->status === User::STATUS_INACTIVE) {
        $class = 'label-default';
        $lable = User::getStatusArray()[$model->status];
    } elseif ($model->status === User::STATUS_BANNED) {
        $class = 'label-danger';
        $lable = User::getStatusArray()[$model->status];
    } elseif ($model->status === User::STATUS_DELETED) {
        $class = 'label-warning';
        $lable = User::getStatusArray()[$model->status];
    }
    return '<span class="label ' . $class . '">' . $lable . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status', User::getStatusArray(), ['class' => 'form-control', 'prompt' => 'Выберите статус'])], ['attribute' => 'role', 'format' => 'html', 'value' => function ($model) {
    if ($model->role === User::ROLE_ADMIN) {
        $class = 'label-danger';
        $lable = User::getRoleArray()[$model->role];
    } elseif ($model->role === User::ROLE_MANAGER) {
        $class = 'label-primary';
        $lable = User::getRoleArray()[$model->role];
    } elseif ($model->role === User::ROLE_USER) {
        $class = 'label-default';
        $lable = User::getRoleArray()[$model->role];
    }
    return '<span class="label ' . $class . '">' . $lable . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'role', User::getRoleArray(), ['class' => 'form-control', 'prompt' => 'Выберите роль'])], ['class' => 'common\\themes\\admin\\widgets\\ActionColumn']]]);