commit
38069c57d4
@ -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 {
|
||||
|
@ -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;
|
||||
|
||||
@ -53,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',
|
||||
|
@ -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],
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
namespace console\controllers;
|
||||
|
||||
|
||||
use backend\modules\card\models\UserCard;
|
||||
use common\models\UserCard;
|
||||
use Yii;
|
||||
use yii\console\Controller;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user