[Thu May 15 16:51:56 2025] [::1]:47566 [500]: POST /api/api-signup/stage-two-credentials/21
[Thu May 15 16:51:56 2025] [::1]:47566 Closing

declare(strict_types=1);

namespace app\models\forms;

use Yii;
use yii\base\Model;
use yii\base\InvalidArgumentException;
use yii\base\Exception as BaseException;
use yii\db\Exception as DbException;

use app\models\User;
use app\helpers\ExceptionLogger;
use app\helpers\ParamHelper;

class SignupStageTwoForm extends Model
{
	public string $fullname;
	public string $password;
	public string $passwordRepeat;
	
	// @var ParamHelper to class property.
	private int $_userNameMaxLength;
	private int $_userPasswordMinLength;
	private int $_userPasswordMaxLength;
	
	// @var app\models\User
	private ?User $_user = null;
	
	public function __construct(int $userId = null, array $config = [])
	{
		if ($userId === null)
		{
			throw new InvalidArgumentException(\Yii::t('app', 'User ID cannot be null.'));
		}
		
		$this->_user = User::findIdentity($userId);
		if (!$this->_user)
		{
			throw new InvalidArgumentException(\Yii::t('app', 'Unable to find account.'));
		}
		
		// @var ParamHelper to class property.
		$this->_userNameMaxLength = ParamHelper::get('user.nameMaxLength');
		$this->_userPasswordMinLength = ParamHelper::get('user.passwordMinLength');
		$this->_userPasswordMaxLength = ParamHelper::get('user.passwordMaxLength');
		
		/**
		* Call to parent constructor
		* The parent constructor should be called last to ensure proper object 
		* initialization and handling of configuration settings.
		*/
		parent::__construct($config);
	}
	
	public function rules(): array
	{
		return [
			[['password', 'passwordRepeat'], 'required'],
			
			['fullname', 'string', 'min' => 1, 'max' => $this->_userNameMaxLength],
			// Accept letters with some special characters.
			['fullname', 'match', 'pattern' => '/^[\p{L} .\'-]+$/u', 
				'message' => \Yii::t('app', 'Names can only contain letters, spaces, and certain characters.'),
				'skipOnEmpty' => true,// Important: skip validation if fullName is empty
			],
			
			['password', 'string', 'min' => $this->_userPasswordMinLength, 'max' => $this->_userPasswordMaxLength],
			['passwordRepeat', 'compare', 'compareAttribute' => 'password', 'message' => 'Passwords do not match.'],
		];
	}
	
	/**
	* Process verification
	* @return User|false
	*/
	public function process(): User|false
	{
		if (!$this->validate())
		{
			return false;
		}
		
		$user = $this->_user;
		if (!$user)
		{
			return false;
		}
		
		try
		{
			$user = $this->_user;
			$user->fullname = $this->fullname ?: null;
			$user->setPassword($this->password);
			$user->status = User::STATUS_ACTIVE;
			$user->advanceSignupPhase();// Set signup_phase to the next stage/step...
			
			if (!$user->save(false))
			{
				throw new YiiDbException('Failed to save user data to the database.');
			}
			
			return $user;
		}
		catch (\Throwable $e)
		{
			// Use the ExceptionLogger to handle and log the exception.
			ExceptionLogger::log($e, 'signup_stageTwo_form_error_');
		}
		
		return false;
	}
}

	public function actionStageTwoCredentials(?int $userId): array
	{
		$request = \Yii::$app->request;
		if (!$request->isPost)
		{
			throw new YiiBadRequestHttpException('Only POST requests are allowed.');
		}
		
		//\Yii::error("Request Post: " . json_encode($request->post()), __METHOD__);
		
		$model = new SignupStageTwoForm((int) $userId);
		if (!($model->load($request->bodyParams, '') && $model->validate()))
		{
			return [
				'success' => false,
				'message' => 'Some information you entered is invalid or missing. Please review and try again.',
				'errors'  => $model->getErrors(),
			];
		}
		
		// $model->process() @returns User $user|false bool
		$user = $model->process();
		if (!$user)
		{
			return [
				'success' => false,
				'message' => 'Failed to save user credentials',
				'errors'  => $model->getErrors(),
			];
		}
		
		return [
			'success' => true,
			'data' => [
				//'userId' => $user->id,
				'signup_phase' => $user->signup_phase,
			],
		];
	}

So what is wrong with this code?? Why do i keep getting a error message "Unable to find account."