Sign In Register

How can we help you today?

Start a new topic
Answered

calling functions depending on action, under Authentication Request

Hey,


So i am trying to send an email for password resets and i have the following problems:


- i send an action over to the authentication request, yet i don't think it actually receives it from my unity code properly. The normal behaviour of the authentication takes place rather than the overriding one, however if i add the action to the test harness it runs the wanted code:


I get an error in unity saying the password and username are requires, they shouldn't be required as i want to run the behaviour below rather than the normal authentication


unity code:

public void ForgottonPassword()

    {

        //Create a data object

        GameSparks.Core.GSRequestData scriptData = new GameSparks.Core.GSRequestData();

        scriptData.Add("action", "passwordRecoveryRequest");

        //Add a string variable with the key 'email'

        scriptData.AddString("email", "example@gamesparks.com");

        new GameSparks.Api.Requests.AuthenticationRequest().SetScriptData(scriptData).Send((response) =>

        {

            if (!response.HasErrors)

            {

                Debug.Log("Forgotton Password COMPLETE");

            }

            else

            {

                Debug.Log("Password Reset Error" + response.Errors.JSON.ToString());

            }

        });

    }


authentication Request: 

// ====================================================================================================

//

// Cloud Code for AuthenticationRequest, write your code here to customise the GameSparks platform.

//

// For details of the GameSparks Cloud Code API see https://portal.gamesparks.net/docs.htm   

//

// ====================================================================================================

  var status = "Started";


    if(Spark.data.scriptData){ //Checking if there is any scriptData passed in, if not then carry on the authentication as normal


        var action = Spark.data.scriptData.action;


        if("passwordRecoveryRequest" === action){

            startRecovery(Spark.data.scriptData); //Start recovery sequence


        } else if ("resetPassword" === action){

            resetPassword(Spark.data.scriptData); //Start reset sequence

        }


        else

        {

            status = "invalid action"; // action variable isn't valid, check spelling or value

        }


        Spark.setScriptError("action", status); // set an error to prevent the AuthenticationRequest being processed


    }


Best Answer

Hi James,


Sorry for the late reply. I think the call you require is SetScriptData() rather than scriptData.Add I've linked the relevant tutorial here: https://docs.gamesparks.com/sdk-center/unity.html#sending-json this should show you how to send custom data to an event.


Hope this helps,

 - Steve

1 Comment

Answer

Hi James,


Sorry for the late reply. I think the call you require is SetScriptData() rather than scriptData.Add I've linked the relevant tutorial here: https://docs.gamesparks.com/sdk-center/unity.html#sending-json this should show you how to send custom data to an event.


Hope this helps,

 - Steve

Login to post a comment