Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ void USequenceAuthenticator::InitializeSequence(const FCredentials_BE& Credentia

void USequenceAuthenticator::PlayFabLoginRPC(const FString& UsernameIn, const FString& PasswordIn, const TSuccessCallback<FString>& OnSuccess, const FFailureCallback& OnFailure)
{
if (!USequenceAuthenticator::ValidateUsername(UsernameIn).IsEmpty())
{
OnFailure(FSequenceError(InvalidArgument, USequenceAuthenticator::ValidateUsername(UsernameIn)));
return;
}
if (!USequenceAuthenticator::ValidatePassword(PasswordIn).IsEmpty())
{
OnFailure(FSequenceError(InvalidArgument, USequenceAuthenticator::ValidatePassword(PasswordIn)));
return;
}

const TFunction<void(FString)> OnSuccessResponse = [OnSuccess, OnFailure](const FString& Response)
{
if (const FPlayFabLoginUserResponse ParsedResponse = USequenceSupport::JSONStringToStruct<FPlayFabLoginUserResponse>(Response); ParsedResponse.IsValid())
Expand All @@ -597,6 +608,22 @@ void USequenceAuthenticator::PlayFabLoginRPC(const FString& UsernameIn, const FS

void USequenceAuthenticator::PlayFabNewAccountLoginRPC(const FString& UsernameIn, const FString& EmailIn, const FString& PasswordIn, const TSuccessCallback<FString>& OnSuccess, const FFailureCallback& OnFailure)
{
if (!USequenceAuthenticator::ValidateUsername(UsernameIn).IsEmpty())
{
OnFailure(FSequenceError(InvalidArgument, USequenceAuthenticator::ValidateUsername(UsernameIn)));
return;
}
if (!USequenceAuthenticator::ValidatePassword(PasswordIn).IsEmpty())
{
OnFailure(FSequenceError(InvalidArgument, USequenceAuthenticator::ValidatePassword(PasswordIn)));
return;
}
if (!USequenceAuthenticator::ValidateEmail(EmailIn).IsEmpty())
{
OnFailure(FSequenceError(InvalidArgument, USequenceAuthenticator::ValidateEmail(EmailIn)));
return;
}

const TFunction<void(FString)> OnSuccessResponse = [OnSuccess, OnFailure](const FString& Response)
{
if (const FPlayFabRegisterUserResponse ParsedResponse = USequenceSupport::JSONStringToStruct<FPlayFabRegisterUserResponse>(Response); ParsedResponse.IsValid())
Expand Down Expand Up @@ -639,6 +666,51 @@ void USequenceAuthenticator::PlayFabRPC(const FString& Url, const FString& Conte
->ProcessAndThen(OnSuccess, OnFailure);
}

FString USequenceAuthenticator::ValidateUsername(const FString& Username)
{
if (Username.IsEmpty())
{
return "Username cannot be empty";
}
return "";
}

FString USequenceAuthenticator::ValidateEmail(const FString& Email)
{
if (Email.IsEmpty())
{
return "Email cannot be empty";
}

int32 AtIndex;

if (!Email.FindChar('@', AtIndex) || AtIndex == 0)
{
return TEXT("Email is invalid, given " + Email);
}

if (!Email.FindChar('.', AtIndex) || AtIndex == 0)
{
return TEXT("Email is invalid, given " + Email);
}


return "";
}

FString USequenceAuthenticator::ValidatePassword(const FString& Password)
{
if (Password.IsEmpty())
{
return "Password cannot be empty";
}
if (Password.Len() < 8)
{
return "Password must be at least 8 characters long";
}
return "";
}

void USequenceAuthenticator::EmailLoginCode(const FString& CodeIn)
{
if (this->ReadAndResetIsFederating())
Expand Down Expand Up @@ -769,7 +841,7 @@ void USequenceAuthenticator::FederatePlayFabNewAccount(const FString& UsernameIn

const FFailureCallback OnFailure = [this](const FSequenceError& Error)
{
UE_LOG(LogTemp, Error, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
UE_LOG(LogTemp, Warning, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
this->CallFederateFailure(Error.Message);
};

Expand All @@ -787,7 +859,7 @@ void USequenceAuthenticator::FederatePlayFabLogin(const FString& UsernameIn, con

const FFailureCallback OnFederateFailure = [this](const FSequenceError& Error)
{
UE_LOG(LogTemp, Error, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
UE_LOG(LogTemp, Warning, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
this->CallFederateFailure(Error.Message);
};

Expand All @@ -807,7 +879,7 @@ void USequenceAuthenticator::FederatePlayFabLogin(const FString& UsernameIn, con

const FFailureCallback OnFailure = [this](const FSequenceError& Error)
{
UE_LOG(LogTemp, Error, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
UE_LOG(LogTemp, Warning, TEXT("Error Federating PlayFab Account: %s"), *Error.Message);
this->CallFederateFailure(Error.Message);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum EErrorType
TestFail,
TimeMismatch,
FailedToParseIntentTime,
InvalidArgument,
};

class SEQUENCEPLUGIN_API FSequenceError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
*/
void PlayFabAuthenticateWithSessionTicket(const FString& SessionTicket);

static FString ValidatePassword(const FString& Password);
/**
* Used to complete Email based authentication, whether it be for normal Authentication OR Federation
* @param CodeIn Received Code from email
Expand Down Expand Up @@ -385,6 +386,8 @@ class SEQUENCEPLUGIN_API USequenceAuthenticator : public UObject, public INative
static FString GeneratePlayFabRegisterUrl();

static void PlayFabRPC(const FString& Url, const FString& Content, const TSuccessCallback<FString>& OnSuccess, const FFailureCallback& OnFailure);

static FString ValidateUsername(const FString& Username);
static FString ValidateEmail(const FString& Email);

//PlayFab RPC//
};
Loading
Loading