Greetings, help me, registration error:
Unknown Property β yii\base\UnknownPropertyException Setting unknown property: finance\entities\User\User::email_confirm_token 1. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\base\Component.php at line 209 200 $behavior->$name = $value; 201 return; 202 } 203 } 204 205 if (method_exists($this, 'get' . $name)) { 206 throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name); 207 } 208 209 throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name); 210 } 211 212 /** 213 * Checks if a property is set, ie defined and not null. 214 * 215 * This method will check in the following order and act accordingly: 216 * 217 * - a property defined by a setter: return whether the property is set 218 * - a property of a behavior: return whether the property is set 2. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\db\BaseActiveRecord.php at line 321 β yii\base\Component::__set('email_confirm_token', 'hKAL0BCUdVDkr8Nl2w4Y4e9yEQesdPcr') 3. in C:\Users\acer\OpenServer\domains\finance\finance\entities\User\User.php at line 42 β yii\db\BaseActiveRecord::__set('email_confirm_token', 'hKAL0BCUdVDkr8Nl2w4Y4e9yEQesdPcr') 36 $user = new User(); 37 $user->username = $username; 38 $user->email = $email; 39 $user->setPassword($password); 40 $user->created_at = time(); 41 $user->status = self::STATUS_WAIT; 42 $user->email_confirm_token = Yii::$app->security->generateRandomString(); 43 $user->generateAuthKey(); 44 return $user; 45 } 46 47 public function confirmSignup(): void 48 { 4. in C:\Users\acer\OpenServer\domains\finance\finance\services\auth\SignupService.php at line 21 β finance\entities\User\User::requestSignup('sveta', 'ddd@mail.ru', '60592swallow') 15 } 16 public function signup(SignupForm $form): void 17 { 18 $user = User::requestSignup( 19 $form->username, 20 $form->email, 21 $form->password 22 ); 23 24 $this->save($user); 25 26 $sent = $this->mailer 27 ->compose( 5. in C:\Users\acer\OpenServer\domains\finance\frontend\controllers\auth\SignupController.php at line 45 β finance\services\auth\SignupService::signup(finance\forms\auth\SignupForm) 39 */ 40 public function actionRequest() 41 { 42 $form = new SignupForm(); 43 if ($form->load(Yii::$app->request->post()) && $form->validate()) { 44 try { 45 $this->service->signup($form); 46 Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); 47 return $this->goHome(); 48 } catch (\DomainException $e) { 49 Yii::$app->errorHandler->logException($e); 50 Yii::$app->session->setFlash('error', $e->getMessage()); 51 } 6. frontend\controllers\auth\SignupController::actionRequest() 7. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\base\InlineAction.php at line 57 β call_user_func_array([frontend\controllers\auth\SignupController, 'actionRequest'], []) 8. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\base\Controller.php at line 157 β yii\base\InlineAction::runWithParams([]) 9. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\base\Module.php at line 528 β yii\base\Controller::runAction('request', []) 10. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\web\Application.php at line 103 β yii\base\Module::runAction('auth/signup/request', []) 11. in C:\Users\acer\OpenServer\domains\finance\vendor\yiisoft\yii2\base\Application.php at line 386 β yii\web\Application::handleRequest(yii\web\Request) 12. in C:\Users\acer\OpenServer\domains\finance\frontend\web\index.php at line 17 β yii\base\Application::run() 11 require __DIR__ . '/../../common/config/main.php', 12 require __DIR__ . '/../../common/config/main-local.php', 13 require __DIR__ . '/../config/main.php', 14 require __DIR__ . '/../config/main-local.php' 15); 16 17(new yii\web\Application($config))->run(); Here is the user code User.php:
public static function requestSignup(string $username, string $email, string $password): self { $user = new User(); $user->username = $username; $user->email = $email; $user->setPassword($password); $user->created_at = time(); $user->status = self::STATUS_WAIT; $user->email_confirm_token = Yii::$app->security->generateRandomString(); $user->generateAuthKey(); return $user; } public function confirmSignup(): void { if (!$this->isWait()) { throw new \DomainException('User is already active.'); } $this->status = self::STATUS_ACTIVE; $this->email_confirm_token = null; } public static function signupByNetwork($network, $identity): self { $user = new User(); $user->created_at = time(); $user->status = self::STATUS_ACTIVE; $user->generateAuthKey(); $user->networks = [Network::create($network, $identity)]; return $user; } Here is the UserReposytory.php code:
public function getByEmailConfirmToken($token): User { return $this->getBy(['email_confirm_token' => $token]); } public function getByEmail($email): User { return $this->getBy(['email' => $email]); } Here is the SignupService.php code:
public function confirm ($token): void { if (empty($token)) { throw new \DomainException('Empty confirm token.'); } $user = $this->getByEmailConfirmToken($token); $user->confirmSignup(); $this->save($user); } private function getByEmailConfirmToken(string $token): User { if (!$user = User::findOne(['email_confirm_token' => $token])) { throw new \DomainException('User is not found.'); } return $user; } private function save(User $user): void { if (!$user->save()) { throw new \RuntimeException('Saving error.'); } } Here is the SignupController.php code:
public function actionRequest() { $form = new SignupForm(); if ($form->load(Yii::$app->request->post()) && $form->validate()) { try { $this->service->signup($form); Yii::$app->session->setFlash('success', 'Check your email for further instructions.'); return $this->goHome(); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } } return $this->render('request', [ 'model' => $form, ]); } /** * @param $token * @return mixed */ public function actionConfirm($token) { try { $this->service->confirm($token); Yii::$app->session->setFlash('success', 'Your email is confirmed.'); return $this->redirect(['auth/auth/login']); } catch (\DomainException $e) { Yii::$app->errorHandler->logException($e); Yii::$app->session->setFlash('error', $e->getMessage()); } return $this->goHome(); }