/// <summary> /// Saves the user data. /// </summary> private void Save() { // If already saving information if (this.IsBusy) { return; } // Validate that the notification type is valid if (this.NotificationTypeIndex < 0) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidNotificationTypes, Localization.DialogDismiss); return; } // Prepare the data to be send to the server var request = new Json.JsonObject { { "notification_types", this.NotificationTypeIndex } }; // Send request to the server this.IsBusy = true; WebHelper.SendAsync( Uris.GetUpdateUserInfoUri(), request.AsHttpContent(), this.ProcessSaveResult, () => this.IsBusy = false); }
/// <summary> /// Handles state updates within the editor extension. /// </summary> /// <param name="state">the state that triggered this event.</param> /// <param name="status">a generic message about the status.</param> /// <param name="json">a generic container for additional JSON encoded info.</param> public void StateUpdateHandler(EdExStates state, string status, string json) { switch (state) { case EdExStates.OnMenuItemClicked: //Debug.Log(string.Format("MenuItem: {0} Clicked", status)); break; case EdExStates.OnHttpReq: object temp; if (!string.IsNullOrEmpty(json) && Json.PlayFabSimpleJson.TryDeserializeObject(json, out temp)) // Json.JsonWrapper.DeserializeObject(json);) { Json.JsonObject deserialized = temp as Json.JsonObject; object useSpinner = false; object blockUi = false; if (deserialized.TryGetValue("useSpinner", out useSpinner) && bool.Parse(useSpinner.ToString())) { ProgressBar.UpdateState(ProgressBar.ProgressBarStates.spin); } if (deserialized.TryGetValue("blockUi", out blockUi) && bool.Parse(blockUi.ToString())) { AddBlockingRequest(status); } } break; case EdExStates.OnHttpRes: ProgressBar.UpdateState(ProgressBar.ProgressBarStates.off); ProgressBar.UpdateState(ProgressBar.ProgressBarStates.success); ClearBlockingRequest(status); break; case EdExStates.OnError: // deserialize and add json details // clear blocking requests ProgressBar.UpdateState(ProgressBar.ProgressBarStates.error); ClearBlockingRequest(); Debug.LogError(string.Format("PlayFab EditorExtensions: Caught an error:{0}", status)); break; case EdExStates.OnWarning: ProgressBar.UpdateState(ProgressBar.ProgressBarStates.warning); ClearBlockingRequest(); Debug.LogWarning(string.Format("PlayFab EditorExtensions: {0}", status)); break; case EdExStates.OnSuccess: ClearBlockingRequest(); ProgressBar.UpdateState(ProgressBar.ProgressBarStates.success); break; } }
/// <summary> /// Performs the user password change. /// </summary> private void ChangePassword() { // If already changing password if (this.IsBusy) { return; } // Validate that the current password is present if (this.PasswordCurrent.Length <= 2) { // TODO: Localize App.DisplayAlert("Error", "Debe de proporcionar una contraseña actual valida", "OK"); return; } // Validate that the new password is present if (this.PasswordNew.Length <= 2) { // TODO: Localize App.DisplayAlert("Error", "Debe de proporcionar una contraseña nueva valida", "OK"); return; } // Validate that the password and confirmation coincide if (this.PasswordNew != this.PasswordConfirm) { // TODO: Localize App.DisplayAlert("Error", "La contraseña y su confirmacion no coinciden", "OK"); return; } // Prepare the data to be send to the server var passwordChangeForm = new Json.JsonObject { { "username", this.login }, { "old_password", this.PasswordCurrent }, { "password", this.PasswordNew } }; var builder = new StringBuilder(); Json.Json.Write(passwordChangeForm, builder); Debug.WriteLine("Request: " + builder); var request = new StringContent(builder.ToString(), Encoding.UTF8, "application/json"); // Send request to the server this.IsBusy = true; WebHelper.PatchAsync( new Uri(Uris.ChangePassword), request, this.ProcessChangePasswordResults, () => this.IsBusy = false); }
/// <summary> /// Performs the user password recovery. /// </summary> private void RecoverPassword() { // If already recovering password if (this.IsBusy) { return; } // Validate that the user name is a valid email // TODO: Change to email or phone number var login = this.Login.Trim().ToLower(); var isEmail = Regex.IsMatch( login, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); if (!isEmail) { // TODO: Localize App.DisplayAlert("Error", "Debe de proporcionar un email valido", "OK"); return; } // Prepare the data to be send to the server var passwordRecoveryForm = new Json.JsonObject { { "username", login }, { "name", "XXX" }, { "password", "***" } }; var builder = new StringBuilder(); Json.Json.Write(passwordRecoveryForm, builder); Debug.WriteLine("Request: " + builder); var request = new StringContent(builder.ToString(), Encoding.UTF8, "application/json"); // Send request to the server this.IsBusy = true; WebHelper.PutAsync( new Uri(Uris.RecoverPassword), request, this.ProcessPasswordRecoveryResults, () => this.IsBusy = false); }
/// <summary> /// Logs in the user with the provided credentials. /// </summary> private void Login() { // Login the user System.Diagnostics.Debug.WriteLine("{0}:{1}", this.UserName, this.Password); // If already logging in if (this.IsBusy) { return; } // Validate that the user name is a valid email var user = this.UserName.Trim().ToLower(); var isEmail = Regex.IsMatch( user, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); if (!isEmail) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidUserLogin, Localization.DialogDismiss); return; } // Validate that the password is present if (this.Password.Length <= 2) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidPassword, Localization.DialogDismiss); return; } // Prepare the data to be send to the server var deviceId = ((App)Application.Current).DeviceId; var request = new Json.JsonObject { { "grant_type", "password" }, { "username", user }, { "password", this.Password }, { "scope", "user submit-report" }, { "device", deviceId } }; // If push token exists var pushToken = ((App)Application.Current).PushToken; if (!string.IsNullOrEmpty(pushToken)) { request.Add("push_token", pushToken); } // Setup error handlers // - If session is already opened by another device, request user consent var handlers = new Dictionary <System.Net.HttpStatusCode, Action <JsonValue> > { { System.Net.HttpStatusCode.Conflict, resp => this.RetryLogin(request, resp) } }; // Send request to the server this.IsBusy = true; WebHelper.SendAsync( Uris.GetLoginUri(), request.AsHttpContent(), this.ProcessLoginResult, () => this.IsBusy = false, handlers); }
public static Config ConvertObject(string version, string json) { var v = new Client.Version(2, 0, 0, Client.VersionType.alpha, 0); if (!string.IsNullOrWhiteSpace(version)) { Client.Version.TryParse(version, out v); } Debug.WriteLine($"Config version change: {v} => {Constant.Verison}"); switch (v.ToString()) { case "2.0.0-alpha.0": { var o = Json.JsonSerializer.Convert <v200a1.ScriptObject>(json); Object.KeyObjects keys = new Object.KeyObjects(); if (o?.Keys?.Keys != null) { foreach (var item in o.Keys.Keys) { if (item == null) { continue; } keys.Add(new Object.KeyObject() { Ignore = item.Ignore, Key = item.Key, Scripts = new Object.KeyScript(item.Script?.Scripts) }); } } return(ConvertObject("2.0.0-alpha.1", Json.JsonSerializer.Convert(new v200a2.ScriptObject() { Language = o.Language, Keys = keys, Settings = o.Settings }))); } case "2.0.0-alpha.1": { var o = Json.JsonSerializer.Convert <v200a2.ScriptObject>(json); var settings = new Json.JsonObject(); if (o.Settings != null) { foreach (var item in o.Settings) { settings.Add(item.Key, ConvertKeys(item.Value)); } Json.Keys ConvertKeys(v200a2.JsonObject.Keys keys) { var ks = new Json.Keys(); foreach (var item in keys) { ks.Add(item.Key, ConvertKey(item.Value)); } return(ks); } Json.Key ConvertKey(v200a2.JsonObject.Key key) => new Json.Key { SubKeys = ConvertKeys(key.SubKeys), Values = ConvertValues(key.Values) }; Json.Values ConvertValues(v200a2.JsonObject.Values values) { var vs = new Json.Values(); foreach (var item in values) { vs.Add(item.Key, new Json.Value(item.Value?.Data)); } return(vs); } } return(ConvertObject("2.0.0-alpha.2", Json.JsonSerializer.Convert(new v200a3.ScriptObject() { Language = o.Language, Keys = o.Keys, Settings = settings }))); } case "2.0.0-alpha.2": { var o = Json.JsonSerializer.Convert <v200a3.ScriptObject>(json); return(new Config() { Keys = o.Keys, Configs = o.Settings, Language = o.Language }); } default: return(Json.JsonSerializer.Convert <Config>(json)); } }
/// <summary> /// Performs the user registration. /// </summary> private void Register() { // If already registering if (this.isRegistering) { return; } // Validate that the user full name is not empty if (this.FullName.Length < 2) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidFullName, Localization.DialogDismiss); return; } // Validate that the user name is a valid email var login = this.UserName.Trim().ToLower(); var isEmail = Regex.IsMatch( login, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase); if (!isEmail) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidUserLogin, Localization.DialogDismiss); return; } // Validate that the password is present if (this.Password.Length <= 2) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidPassword, Localization.DialogDismiss); return; } // Validate that the password and confirmation coincide if (this.Password != this.PasswordConfirm) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidConfirmation, Localization.DialogDismiss); return; } // Validate that the notification type is valid if (this.NotificationTypeIndex < 0) { App.DisplayAlert( Localization.ErrorDialogTitle, Localization.ErrorInvalidNotificationTypes, Localization.DialogDismiss); return; } // Prepare the data to be send to the server var registrationForm = new Json.JsonObject { { "username", login }, { "name", this.FullName.Trim() }, { "password", this.Password }, { "notification_types", this.NotificationTypeIndex } }; var builder = new StringBuilder(); Json.Json.Write(registrationForm, builder); Debug.WriteLine("Request: " + builder); var request = new StringContent(builder.ToString(), Encoding.UTF8, "application/json"); // Send request to the server this.isRegistering = true; WebHelper.PostAsync( new Uri(Uris.Register), request, this.ProcessRegistrationResults, () => this.isRegistering = false); }