From ddd14e436cbfb032e4997583435f93da5b825a60 Mon Sep 17 00:00:00 2001 From: glambertessa Date: Fri, 22 May 2020 11:25:21 +0300 Subject: [PATCH 1/2] email required --- backend/modules/card/views/user-card/_form.php | 1 - common/models/UserCard.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index 2726ca1..115c97c 100755 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -4,7 +4,6 @@ use common\classes\Debug; use kartik\select2\Select2; use mihaildev\elfinder\InputFile; use unclead\multipleinput\MultipleInput; -use unclead\multipleinput\examples\models\ExampleModel; use yii\helpers\Html; use yii\widgets\ActiveForm; diff --git a/common/models/UserCard.php b/common/models/UserCard.php index abc862c..ea6c865 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -65,7 +65,7 @@ class UserCard extends \yii\db\ActiveRecord public function rules() { return [ - [['fio', 'status', 'gender'], 'required'], + [['fio', 'status', 'gender', 'email'], 'required'], [['gender', 'status', 'position_id', 'id_user'], 'integer'], [['dob', 'created_at', 'updated_at', 'deleted_at'], 'safe'], [['fio', 'passport', 'photo', 'email', 'resume', 'city'], 'string', 'max' => 255], From 97619ba34745e38d0d108e3318f4b1f87ab4a6a3 Mon Sep 17 00:00:00 2001 From: glambertessa Date: Fri, 22 May 2020 16:42:24 +0300 Subject: [PATCH 2/2] fixed console user generate --- backend/modules/card/models/UserCard.php | 58 ------------------- .../modules/card/views/user-card/_form.php | 2 +- common/models/UserCard.php | 58 +++++++++++++++++++ console/controllers/SqlController.php | 2 +- log.txt | 1 + 5 files changed, 61 insertions(+), 60 deletions(-) create mode 100644 log.txt diff --git a/backend/modules/card/models/UserCard.php b/backend/modules/card/models/UserCard.php index 1aee7a6..ce3bd54 100755 --- a/backend/modules/card/models/UserCard.php +++ b/backend/modules/card/models/UserCard.php @@ -111,64 +111,6 @@ class UserCard extends \common\models\UserCard parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub } - public static function generateUser($email, $status) - { - $user = new User(); - $auth_key = Yii::$app->security->generateRandomString(); - $password = Yii::$app->security->generateRandomString(12); - $password_hash = Yii::$app->security->generatePasswordHash($password); - - $user->username = $email; - $user->auth_key = $auth_key; - $user->password_hash = $password_hash; - $user->email = $email; - if ($status == 1) $user->status = 10; - - $user->save(); - - $auth = Yii::$app->authManager; - $authorRole = $auth->getRole('user'); - $auth->assign($authorRole, $user->id); - - $log = "Логин: " . $email . " Пароль: " . $password . " | "; - file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX); - - return $user->id; - } - - public static function genereateLinlkOnUser($user_card, $user_id) - { - $user_card->id_user = $user_id; - $user_card->save(); - } - - public static function generateUserForUserCard($card_id = null) - { - $userCardQuery = UserCard::find(); - $card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]); - $user_card_array = $userCardQuery->all(); - $user_array = User::find()->all(); - - foreach ($user_card_array as $user_card_value) { - - foreach ($user_array as $user_value) - if ($user_card_value->email == $user_value->email) { - $user_id = $user_value->id; - break; - } else $user_id = NULL; - - if ($user_id) { - UserCard::genereateLinlkOnUser($user_card_value, $user_id); - } else { - $user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status); - UserCard::genereateLinlkOnUser($user_card_value, $user_id); - } - } - - if ($user_card_array) return "data generated successfully"; - else return "no data to generate"; - } - public static function getParameter($params, $key) { try { diff --git a/backend/modules/card/views/user-card/_form.php b/backend/modules/card/views/user-card/_form.php index 115c97c..e05d94e 100755 --- a/backend/modules/card/views/user-card/_form.php +++ b/backend/modules/card/views/user-card/_form.php @@ -52,7 +52,7 @@ use yii\widgets\ActiveForm; 'language' => 'ru', 'controller' => 'elfinder', // вставляем название контроллера, по умолчанию равен elfinder - 'filter' => ['image', 'application/zip', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'], + //'filter' => ['image', 'application/zip', 'application/csv', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'], // фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con.. 'name' => 'UserCard[resume]', 'id' => 'usercard-resume', diff --git a/common/models/UserCard.php b/common/models/UserCard.php index ea6c865..1cde826 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -162,4 +162,62 @@ class UserCard extends \yii\db\ActiveRecord { return ArrayHelper::map(self::find()->all(), 'id', 'fio'); } + + public static function generateUserForUserCard($card_id = null) + { + $userCardQuery = self::find(); + $card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]); + $user_card_array = $userCardQuery->all(); + $user_array = User::find()->all(); + + foreach ($user_card_array as $user_card_value) { + + foreach ($user_array as $user_value) + if ($user_card_value->email == $user_value->email) { + $user_id = $user_value->id; + break; + } else $user_id = NULL; + + if ($user_id) { + UserCard::genereateLinlkOnUser($user_card_value, $user_id); + } else { + $user_id = UserCard::generateUser($user_card_value->email, $user_card_value->status); + UserCard::genereateLinlkOnUser($user_card_value, $user_id); + } + } + + if ($user_card_array) return "data generated successfully"; + else return "no data to generate"; + } + + public static function generateUser($email, $status) + { + $user = new User(); + $auth_key = Yii::$app->security->generateRandomString(); + $password = Yii::$app->security->generateRandomString(12); + $password_hash = Yii::$app->security->generatePasswordHash($password); + + $user->username = $email; + $user->auth_key = $auth_key; + $user->password_hash = $password_hash; + $user->email = $email; + if ($status == 1) $user->status = 10; + + $user->save(); + + $auth = Yii::$app->authManager; + $authorRole = $auth->getRole('user'); + $auth->assign($authorRole, $user->id); + + $log = "Логин: " . $email . " Пароль: " . $password . " | "; + file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX); + + return $user->id; + } + + public static function genereateLinlkOnUser($user_card, $user_id) + { + $user_card->id_user = $user_id; + $user_card->save(); + } } diff --git a/console/controllers/SqlController.php b/console/controllers/SqlController.php index 0e65cb2..2aebf0c 100644 --- a/console/controllers/SqlController.php +++ b/console/controllers/SqlController.php @@ -4,7 +4,7 @@ namespace console\controllers; -use backend\modules\card\models\UserCard; +use common\models\UserCard; use Yii; use yii\console\Controller; diff --git a/log.txt b/log.txt new file mode 100644 index 0000000..0741784 --- /dev/null +++ b/log.txt @@ -0,0 +1 @@ +Логин: test6@test.com Пароль: 6YKuWYVRyJ2I | \ No newline at end of file