public function actionSignup()
{
if(!Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new SignupForm();
if($model->load(\Yii::$app->request->post()) && $model->validate())
{
$user = new User();
$user->login = $model->login;
$user->username = $model->username;
$user->surname= $model->surname;
$user->email = $model->email;
$user->password = \Yii::$app->security->generatePasswordHash($model->password);
if($user->save())
{
return $this->goHome();
}
// нужно добавить следующие три строки:
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->getId());
}
return $this->render('signup', compact('model'));
}
public function actionSignup()
{
if(!Yii::$app->user->isGuest)
{
return $this->goHome();
}
$model = new SignupForm();
if($model->load(\Yii::$app->request->post()) && $model->validate())
{
$user = new User();
$user->login = $model->login;
$user->username = $model->username;
$user->surname= $model->surname;
$user->email = $model->email;
$user->password = \Yii::$app->security->generatePasswordHash($model->password);
$user->save(false);
// нужно добавить следующие три строки:
$auth = Yii::$app->authManager;
$authorRole = $auth->getRole('user');
$auth->assign($authorRole, $user->getId());
return $user;
}
return $this->render('signup', compact('model'));
}