diff --git a/backend/modules/card/controllers/UserCardController.php b/backend/modules/card/controllers/UserCardController.php index 3c95b01..0b54b0f 100755 --- a/backend/modules/card/controllers/UserCardController.php +++ b/backend/modules/card/controllers/UserCardController.php @@ -138,6 +138,7 @@ class UserCardController extends Controller public function actionCreate() { $model = new UserCard(); + $model->scenario = UserCard::SCENARIO_CREATE_FROM_ADMIN; if ($model->load(Yii::$app->request->post()) && $model->save()) { UserCard::generateUserForUserCard($model->id); diff --git a/common/config/main.php b/common/config/main.php index b7e657a..379c641 100755 --- a/common/config/main.php +++ b/common/config/main.php @@ -39,7 +39,7 @@ return [ 'marginBottom' => 5, // Margin bottom pixel 'quality' => 95, // JPEG image save quality 'transparency' => 70, // Water mark image transparency ( other than PNG ) - 'targetType' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats ( bit-field ) + //'targetType' => IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP, // Target image formats ( bit-field ) 'targetMinPixel' => 200 // Target image minimum pixel size ] ] diff --git a/common/mail/signup-html.php b/common/mail/signup-html.php index 8bfe78e..9f4dcfb 100644 --- a/common/mail/signup-html.php +++ b/common/mail/signup-html.php @@ -4,7 +4,7 @@ /* @var $user common\models\User */ ?> -Hello = $user->username ?>, +
Здравствуйте, = $user->username ?>
, -You have successfully registered! +Благодорим за регистрацию. diff --git a/common/mail/signup-text.php b/common/mail/signup-text.php index 8bfe78e..89d3531 100644 --- a/common/mail/signup-text.php +++ b/common/mail/signup-text.php @@ -4,7 +4,7 @@ /* @var $user common\models\User */ ?> -Hello = $user->username ?>, +Здравствуйте, = $user->username ?>, -You have successfully registered! +Благодорим за регистрацию. diff --git a/common/models/Manager.php b/common/models/Manager.php index 2256a8c..63f61b2 100644 --- a/common/models/Manager.php +++ b/common/models/Manager.php @@ -34,7 +34,7 @@ class Manager extends \yii\db\ActiveRecord [['user_id'], 'integer'], [['user_id'], 'required'], ['user_id', 'unique', 'message' => 'Уже является менеджером'], - [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_id' => 'id']], + [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']], ]; } diff --git a/common/models/Status.php b/common/models/Status.php index c772852..267db07 100755 --- a/common/models/Status.php +++ b/common/models/Status.php @@ -72,4 +72,9 @@ class Status extends \yii\db\ActiveRecord { return $this->hasMany(UserCard::class, ['status' => 'id']); } + + public static function getByName($name) + { + return Status::find()->where(['name' => $name])->one()->id ?? false; + } } diff --git a/common/models/User.php b/common/models/User.php index 583ab01..3bbd01c 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -240,8 +240,31 @@ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface return $this->hasOne(UserCard::class, ['id_user' => 'id']); } - public function getProjectUser() + public function getProjectUser(): \yii\db\ActiveQuery { return $this->hasMany(ProjectUser::class, ['user_id' => 'id']); } + + /** + * @param string $email + * @param int $status + * @return UserCard|false + */ + public static function createSimpleProfile(string $email, int $status = 18): UserCard | bool + { + $user = User::find()->where(['email' => $email])->one(); + if ($user) { + $profile = new UserCard(); + $profile->id_user = $user->id; + $profile->status = $status; + $profile->fio = $email; + if ($profile->save()) { + return $profile; + } + + return false; + } + + return false; + } } diff --git a/common/models/UserCard.php b/common/models/UserCard.php index f6db69f..6f41f0b 100755 --- a/common/models/UserCard.php +++ b/common/models/UserCard.php @@ -62,6 +62,8 @@ class UserCard extends \yii\db\ActiveRecord const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text'; const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text'; + const SCENARIO_CREATE_FROM_ADMIN = 'create_from_admin'; + const AT_PROJECT_BUSY = 1; const AT_PROJECT_FREE = 0; @@ -114,7 +116,8 @@ class UserCard extends \yii\db\ActiveRecord public function rules() { return [ - [['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'], + [['fio', 'status', ], 'required'], + [['gender', 'email', 'level', 'position_id'], 'required', 'on' => self::SCENARIO_CREATE_FROM_ADMIN], [['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp', 'resume_tariff', 'at_project'], 'integer'], [['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short', 'test_task_getting_date', 'test_task_complete_date'], 'safe'], ['email', 'unique', 'message'=>'Почтовый адрес уже используется'], diff --git a/common/models/email/RegistrationEmail.php b/common/models/email/RegistrationEmail.php index 46ab942..d333f01 100644 --- a/common/models/email/RegistrationEmail.php +++ b/common/models/email/RegistrationEmail.php @@ -13,7 +13,7 @@ class RegistrationEmail extends Email public function __construct(User $user) { $this->sendTo = $user->email; - $this->subject = 'Account registration at ' . Yii::$app->name; + $this->subject = 'Регистрация в ' . Yii::$app->name; $this->mailLayout = ['html' => 'signup-html', 'text' => 'signup-text']; $this->params = ['user' => $user]; } diff --git a/composer.json b/composer.json index f23ceb5..5ef50e2 100755 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "minimum-stability": "stable", "require": { - "php": ">=7.4.0", + "php": ">=8.0", "yiisoft/yii2": "~2.0.6", "yiisoft/yii2-bootstrap": "~2.0.0", "yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0", diff --git a/console/controllers/SqlController.php b/console/controllers/SqlController.php index 2273546..a5dd185 100755 --- a/console/controllers/SqlController.php +++ b/console/controllers/SqlController.php @@ -5,12 +5,32 @@ namespace console\controllers; use common\models\Reports; +use common\models\User; use common\models\UserCard; use Yii; use yii\console\Controller; class SqlController extends Controller { + public $email = ""; + + /** + * @param $actionID + * @return string[] + */ + public function options($actionID) + { + return ['email']; + } + + /** + * @return string[] + */ + public function optionAliases() + { + return ['e' => 'email']; + } + public function actionSalary() { $sql = "UPDATE user_card SET salary=REPLACE( `salary`, ' ', '' )"; @@ -50,4 +70,14 @@ class SqlController extends Controller echo "script completed successfully\n"; } + + public function actionCreateProfile() + { + if ($profile = User::createSimpleProfile($this->email, 17)) { + echo "Профиль $profile->id успешно создан\n"; + return; + } + + echo "Пользователь $this->email не найден\n"; + } } \ No newline at end of file diff --git a/frontend/models/SignupForm.php b/frontend/models/SignupForm.php index 8fa8cd8..d34604b 100755 --- a/frontend/models/SignupForm.php +++ b/frontend/models/SignupForm.php @@ -2,6 +2,7 @@ namespace frontend\models; use common\classes\Debug; +use common\models\Status; use Yii; use yii\base\Model; use common\models\User; @@ -14,6 +15,7 @@ class SignupForm extends Model public $username; public $email; public $password; + public $is_partner = 0; /** @@ -35,6 +37,8 @@ class SignupForm extends Model ['password', 'required'], ['password', 'string', 'min' => 6], + + ['is_partner', 'integer'] ]; } @@ -60,6 +64,8 @@ class SignupForm extends Model $authorRole = $auth->getRole('user'); $auth->assign($authorRole, $user->id); + User::createSimpleProfile($user->email, $this->is_partner ? Status::getByName("Партнер") : Status::getByName("Аутстафинг")); + return $user->save() ? $user : null; } } diff --git a/frontend/modules/api/controllers/RegisterController.php b/frontend/modules/api/controllers/RegisterController.php index ec1d810..6877d7f 100644 --- a/frontend/modules/api/controllers/RegisterController.php +++ b/frontend/modules/api/controllers/RegisterController.php @@ -57,6 +57,11 @@ class RegisterController extends ApiController * type="string", * description="Пароль пользователя", * ), + * @OA\Property( + * property="is_partner", + * type="integer", + * description="Является ли пользователь Партнером. Возможные значения 0 или 1. По умолчанию 0", + * ), * ), * ), * ),