fixed console user generate

This commit is contained in:
glambertessa 2020-05-22 16:42:24 +03:00
parent 1894eaba6d
commit 97619ba347
5 changed files with 61 additions and 60 deletions

View File

@ -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 {

View File

@ -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',

View File

@ -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();
}
}

View File

@ -4,7 +4,7 @@
namespace console\controllers;
use backend\modules\card\models\UserCard;
use common\models\UserCard;
use Yii;
use yii\console\Controller;

1
log.txt Normal file
View File

@ -0,0 +1 @@
Логин: test6@test.com Пароль: 6YKuWYVRyJ2I |