public void NewPasswordLogin() { DataController.SaveValue("password", password.text); Debug.Log(password.text); var loginRequest = new AuthenticationRequest(); GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(); data.AddString("password", DataController.GetValue <string>("password")); data.AddString("action", "resetPassword"); data.AddString("token", token.text); loginRequest.SetScriptData(data); loginRequest.SetUserName(DataController.GetValue <string>("username")); loginRequest.SetPassword(password.text); loginRequest.Send(response => { if (response.Errors.GetString("action").Contains("complete")) { Warning.SetActive(true); PopUpMessage.ActivatePopUp(delegate { }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning5")); UIController.SetActivePanel(UI_Element.Login); } if (response.Errors.GetString("action").Contains("invalid")) { Warning.SetActive(true); PopUpMessage.ActivatePopUp(delegate { }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning4") + LocalisationSystem.GetLocalisedValue("password_error")); UIController.SetActivePanel(UI_Element.ConfirmResetPassword); } Debug.Log("well done " + response.Errors.JSON.ToString()); if (!response.HasErrors) { Debug.Log("Error reseting password.../n" + response.Errors.JSON.ToString()); } }); }
/// <summary> /// User Login /// </summary>> /// <param name="username"></param> /// <param name="password"></param> /// <param name="eventName"></param> public static void Login(string username, string password, string eventName) { if (DataController.GetValue <string>("LastValidusername") != username) { if (DataController.GetValue <string>("LastValidusername") != "") { Login(DataController.GetValue <string>("LastValidusername"), DataController.GetValue <string>("LastValidPassword"), null); } } DataController.SaveValue("username", username); StatsList = new List <long>(); EquipmentList = new List <long>(); OtherStuffList = new List <long>(); StatsList = new List <long>(); EquipmentList = new List <long>(); PrimaryStuffList = new List <long>(); if (DataController.GetValue <int>("Rating") >= 0) { var newRequest = new GameSparks.Api.Requests.LogEventRequest();// DataController.GetValue<int>("Rating")); newRequest.SetEventKey("RATING_UPDATE").SetEventAttribute("Rating", DataController.GetValue <int>("Rating")).Send(response => { }); } var newRequest1 = new GameSparks.Api.Requests.LeaderboardDataRequest(); newRequest1.SetLeaderboardShortCode("LeaderboardRating").SetEntryCount(35).Send(response => { Debug.Log(response.BaseData.JSON); LeaderBoardsScript.Ranks = new List <long?>(); LeaderBoardsScript.Names = new List <string>(); LeaderBoardsScript.Ratings = new List <long?>(); foreach (var gd in response.BaseData.GetGSDataList("data")) { LeaderBoardsScript.Ranks.Add(gd.GetLong("rank")); LeaderBoardsScript.Names.Add(gd.GetString("userName")); LeaderBoardsScript.Ratings.Add(gd.GetLong("Rating")); //Debug.Log(gd.GetString("userName")); //Debug.Log(gd.GetLong("Rating")); } }); Debug.Log("Authentication..."); var loginRequest = new AuthenticationRequest(); GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(); if (DataController.GetValue <int>("GSNotSynced" + username) > 0 && DataController.GetValue <string>("LastValidusername") == username) { foreach (string attr in ServerNamz) { Debug.Log(DataController.GetValue <int>(attr + "Mine")); StatsList.Add((long)DataController.GetValue <int>(attr + "Mine")); } data.AddNumberList("Stats", StatsList); foreach (string TypeItem in Equipment.ForInvLoad) { foreach (string Name in EquipmentNames) { EquipmentList.Add((long)DataController.GetValue <int>(Name + TypeItem + "ammount")); } } data.AddNumberList("Equipment", EquipmentList); int tempNum = 0; foreach (int num in CelebrationAnimation.Prices) { Debug.Log(num); if (DataController.GetValue <int>("WinAnimNumberMine" + tempNum + "ammount") > 0) { OtherStuffList.Add(1); } else { OtherStuffList.Add(0); } tempNum += 1; } PrimaryStuffList.Add(DataController.GetValue <int>("Exp")); PrimaryStuffList.Add(DataController.GetValue <int>("Bread")); PrimaryStuffList.Add(DataController.GetValue <int>("SkillPoints")); PrimaryStuffList.Add(DataController.GetValue <int>("Rating")); Debug.Log(DataController.GetValue <int>("SkillPoints")); data.AddNumberList("OtherStuffList", OtherStuffList); data.AddNumberList("PrimaryStuffList", PrimaryStuffList); } loginRequest.SetUserName(username); loginRequest.SetPassword(password); loginRequest.SetScriptData(data); loginRequest.Send(response => { if (!response.HasErrors) { GameSparks.Core.GSData GSList = response.ScriptData; foreach (string atributeName in ServerNamz) { DataController.SaveValue(atributeName + "Mine", (int)GSList.GetInt(atributeName)); } foreach (string TypeItem in Equipment.ForInvLoad) { foreach (string Name in EquipmentNames) { if (GSList.GetGSData("BoughtOrNot").ContainsKey(Name + TypeItem)) { if (GSList.GetGSData("BoughtOrNot").GetInt(Name + TypeItem) > 0) { DataController.SaveValue(Name + TypeItem + "ammount", 1); } else { DataController.SaveValue(Name + TypeItem + "ammount", 0); } } else { DataController.SaveValue(Name + TypeItem + "ammount", 0); } } } foreach (var vg in GSList.GetGSDataList("VirtualGoodsList")) { foreach (string modifier in EqModifiers) { if (vg.GetGSData("currencyCosts").GetInt(modifier) != null) { DataController.SaveValue(vg.GetString("name") + modifier, (int)vg.GetGSData("currencyCosts").GetInt(modifier)); //Debug.Log(vg.GetString("name")); } } //Debug.Log(vg.GetString("name")); DataController.SaveValue(vg.GetString("name") + "Price", (int)vg.GetGSData("currencyCosts").GetInt("Bread")); DataController.SaveValue(vg.GetString("name") + "SellPrice", (int)vg.GetGSData("currencyCosts").GetInt("BreadPrice")); } int tempNum = 0; long?value = GSList.GetLong("Anim" + tempNum); while (value != null) { DataController.SaveValue("WinAnimNumberMine" + tempNum + "ammount", (int)value); tempNum += 1; value = GSList.GetLong("Anim" + tempNum); } for (int i = tempNum; i < CelebrationAnimation.Prices.Count; i++) { DataController.SaveValue("WinAnimNumberMine" + i + "ammount", 0); } long?Exp = GSList.GetLong("TotalExp"); DataController.SaveValue("Exp", (int)Exp); long?Bread = GSList.GetLong("TotalBread"); DataController.SaveValue("Bread", (int)Bread); long?SkillPoints = GSList.GetLong("TotalSkillPoints"); DataController.SaveValue("SkillPoints", (int)SkillPoints); long?Rating = GSList.GetLong("Rating"); DataController.SaveValue("Rating", (int)Rating); Debug.Log(DataController.GetValue <int>("SkillPoints")); DataController.SaveValue("GSNotSynced" + username, 0); Debug.Log("Player authenticated! \n Name:" + response.DisplayName + response.ScriptData.JSON);// + response.ScriptData);//.ScriptData.JSON.ToString()); IsUserLoggedIn = false; EventManager.TriggerEvent(eventName, response.DisplayName); DataController.SaveValue("LastValidPassword" + username, password); DataController.SaveValue("LastValidusername", username); } else { ResetPassword.instance.Warning.SetActive(true); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.Login); }, LocalisationSystem.GetLocalisedValue("loginerror1")); Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString()); EventManager.TriggerEvent(eventName, ""); } }); }
public void GetToken() { DataController.SaveValue("username", username.text); var loginRequest = new AuthenticationRequest(); GameSparks.Core.GSRequestData data = new GameSparks.Core.GSRequestData(); data.AddString("action", "passwordRecoveryRequest"); data.AddString("email", email.text); loginRequest.SetScriptData(data); loginRequest.SetUserName(DataController.GetValue <string>("username")); loginRequest.SetPassword(""); loginRequest.Send(response => { if (!response.HasErrors) { Warning.SetActive(true); Warning.GetComponentsInChildren <Button>()[1].gameObject.SetActive(false); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1")); } else { Debug.Log("Error authenticating player.../n" + response.Errors.JSON.ToString()); Debug.Log(response.Errors.GetString("action")); if (response.Errors.ContainsKey("action")) { Warning.SetActive(true); //Warning.GetComponentsInChildren<Button>()[1].gameObject.SetActive(false); if (response.Errors.GetString("action").Contains("complete")) { Debug.Log("warn1"); UIController.SetActivePanel(UI_Element.ConfirmResetPassword); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ConfirmResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning1")); } else if (response.Errors.GetString("action").Contains("email") || response.Errors.GetString("action").Contains("invalid")) { Debug.Log("warn2"); PopUpMessage.ActivatePopUp(delegate { UIController.SetActivePanel(UI_Element.ResetPassword); }, LocalisationSystem.GetLocalisedValue("resetpasswordwarning2")); } else { Debug.Log("exception"); } } } }); }