Skip to main content

Put it all together - In-game registration - (Unreal Engine module)

Last updated on September 4, 2025

Connect the UI to upgrade account

  1. Open the UpgradeAccountOptionWidget_Starter class CPP file. Locate the predefined NativeConstruct() and NativeOnActivated() functions. Then, add the highlighted code below. This code checks whether the player account is already a full account or not. If it is, it will skip the upgrade account option menu and redirect to the main menu instead.

    void UUpgradeAccountOptionWidget_Starter::NativeConstruct()
    {
    Super::NativeConstruct();
    // ...
    SetVisibility(
    !RegisterUserInGameSubsystem->IsAllowUpgradeAccount() ||
    RegisterUserInGameSubsystem->IsCurrentUserIsFullAccount() ?
    ESlateVisibility::Hidden :
    ESlateVisibility::Visible);
    }
    void UUpgradeAccountOptionWidget_Starter::NativeOnActivated()
    {
    if (!RegisterUserInGameSubsystem->IsAllowUpgradeAccount() ||
    RegisterUserInGameSubsystem->IsCurrentUserIsFullAccount())
    {
    SkipUpgradeAccount();
    return;
    }

    Super::NativeOnActivated();

    Btn_Upgrade->OnClicked().AddUObject(this, &ThisClass::ProceedToUpgradeAccount);
    Btn_Skip->OnClicked().AddUObject(this, &ThisClass::SkipUpgradeAccount);
    }
  2. Next, open the UpgradeAccountWidget_Starter class CPP file and replace the UpgradeAccount() function with the code below. This function will send additional input validation request before it can proceeed to open the upgrade account verification widget.

    void UUpgradeAccountWidget_Starter::UpgradeAccount()
    {
    const FString Username = Edt_Username->GetText().ToString();
    const FString DisplayName = Edt_DisplayName->GetText().ToString();
    const FString Email = Edt_Email->GetText().ToString();
    const FString Password = Edt_Password->GetText().ToString();
    const FString RetypePassword = Edt_RetypePassword->GetText().ToString();

    ToggleWarningText(false);

    // Basic local input validations.
    if (Username.IsEmpty() || DisplayName.IsEmpty() || Email.IsEmpty() || Password.IsEmpty() || RetypePassword.IsEmpty())
    {
    ToggleWarningText(true, EMPTY_REQUIRED_FIELDS_ERROR);
    return;
    }
    else if (!AccelByteWarsUtility::IsValidEmailAddress(Email))
    {
    ToggleWarningText(true, EMAIL_INPUT_VIOLATION_ERROR);
    return;
    }
    else if (!Password.Equals(RetypePassword, ESearchCase::Type::CaseSensitive))
    {
    ToggleWarningText(true, PASSWORD_NOT_MATCH_ERROR);
    return;
    }

    // Send request to validate inputs.
    FUserInputValidationRequest Request;
    Request.Username = Username;
    Request.DisplayName = DisplayName;
    Request.UniqueDisplayName = DisplayName;
    Request.Password = Password;
    Btn_Upgrade->SetIsEnabled(false);
    RegisterUserInGameSubsystem->ValidateUserInput(
    Request,
    FOnUserInputValidationComplete::CreateWeakLambda(this, [this]
    (bool bIsValid, const FString& ValidationMessage)
    {
    Btn_Upgrade->SetIsEnabled(true);
    if (bIsValid)
    {
    ProceedToVerifyAccount();
    return;
    }

    ToggleWarningText(true, FText::FromString(ValidationMessage));
    }));
    }
  3. Open the VerifyAccountWidget_Starter class CPP file and replace the SendVerificationCode() with the code below to send an email verification code request.

    void UVerifyAccountWidget_Starter::SendVerificationCode(const bool bForceResend)
    {
    ToggleWarningText(false);
    Ws_VerifyAccount->LoadingMessage = SEND_VERIFICATION_CODE_MESSAGE;
    Ws_VerifyAccount->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);

    Btn_Resend->SetIsEnabled(false);
    RegisterUserInGameSubsystem->SendUpgradeAccountVerificationCode(
    UpgradeAccountData.GetEmail(),
    bForceResend,
    FOnSendUpgradeAccountVerificationCodeComplete::CreateWeakLambda(this, [this](bool bWasSuccesful, const FString& ErrorMessage)
    {
    Ws_VerifyAccount->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Not_Empty);

    if (!bWasSuccesful)
    {
    Btn_Resend->SetIsEnabled(true);
    ToggleWarningText(true, FText::FromString(ErrorMessage));
    return;
    }

    StartRequestVerificationCodeCooldown();
    })
    );
    }
  4. Finally, still in the same file, replace the UpgradeAndVerifyAccount() with the code below to upgrade the account using an email verification code.

    void UVerifyAccountWidget_Starter::UpgradeAndVerifyAccount()
    {
    const FString VerificationCode = Edt_VerificationCode->GetText().ToString();
    if (VerificationCode.IsEmpty())
    {
    ToggleWarningText(true, EMPTY_VERIFICATION_CODE_ERROR);
    return;
    }

    ToggleWarningText(false);
    Ws_VerifyAccount->LoadingMessage = UPGRADE_ACCOUNT_MESSAGE;
    Ws_VerifyAccount->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);

    RegisterUserInGameSubsystem->UpgradeAndVerifyAccount(
    AccelByteWarsUtility::GetLocalUserNum(GetOwningPlayer()),
    AccelByteWarsUtility::GetUserId(GetOwningPlayer()),
    UpgradeAccountData.GetUsername(),
    UpgradeAccountData.GetDisplayName(),
    UpgradeAccountData.GetEmail(),
    UpgradeAccountData.GetPassword(),
    VerificationCode,
    FOnUpgradeAndVerifyAccountComplete::CreateWeakLambda(this, [this](bool bWasSuccessful, const FString& ErrorMessage, const FAccountUserData& NewFullAccount)
    {
    Ws_VerifyAccount->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Not_Empty);

    if (!bWasSuccessful)
    {
    ToggleWarningText(true, FText::FromString(ErrorMessage));
    return;
    }

    UpgradeAccountData.Reset();
    OpenToMainMenu();
    })
    );
    }

Resources