Put it all together - In-game registration - (Unreal Engine module)
Last updated on October 24, 2024
Connect the UI to upgrade account
Open the
UpgradeAccountOptionWidget_Starter
class CPP file. Locate the predefinedNativeConstruct()
andNativeOnActivated()
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);
}Next, open the
VerifyAccountWidget_Starter
class CPP file and replace theSendVerificationCode()
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();
})
);
}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.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
The files used in this tutorial section are available in the Unreal Byte Wars GitHub repository.
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/RegisterUserInGame/UI/UpgradeAccountOptionWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/RegisterUserInGame/UI/UpgradeAccountOptionWidget_Starter.cpp
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/RegisterUserInGame/UI/VerifyAccountWidget_Starter.h
- AccelByteWars/Source/AccelByteWars/TutorialModules/Access/RegisterUserInGame/UI/VerifyAccountWidget_Starter.cpp