registration fix

This commit is contained in:
2024-02-05 23:58:48 +03:00
parent 5cfd591140
commit eb1abd41e5
13 changed files with 83 additions and 10 deletions

View File

@ -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']],
];
}

View File

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

View File

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

View File

@ -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'=>'Почтовый адрес уже используется'],

View File

@ -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];
}