protected virtual void OnAuthFailure() { ExceptionUtility.Try(() => { if (this.IsShowing) { //cancel reconnecting ConnectionManager.CancelReconnecting(); //clear cache Caches.ClearCachesForAuthFailure(); MainThreadUtility.InvokeOnMain(() => { //show alert ProgressUtility.Dismiss(); AlertUtility.ShowAlert(StringLiterals.AuthFailure, StringLiterals.AuthFailureMessage); //nav to login screen this.NavigateUserConfig(); }); } }); }
private async void SubmitForm() { try { _connectingManually = true; if (this._navBarView.DoneButtonEnabled) { //var oldUsername = User.Current?.Username; //var oldPassword = User.Current?.Password; //var oldServerUri = User.Current?.ServerUri; var username = this._tableViewController.Username; var password = this._tableViewController.Password; var serverUri = this._tableViewController.ServerUri; //set default if no server uri provided if (String.IsNullOrEmpty(serverUri)) { serverUri = AppSettings.GetAppSettingValue(AppSettings.DefaultAppServerUriAppSettingName, String.Empty); this._tableViewController.ServerUri = serverUri; } //translate server alias to a uri serverUri = ServerAliases.AliasToUri(serverUri); bool newUser = false; bool newServer = false; if (User.Current == null) { User.Current = new User(); } else { //check if current user is different from prev user newUser = ((User.Current.Username != null) && User.Current.Username.Trim().ToLower() != username.Trim().ToLower()); newServer = ((User.Current.ServerUri != null) && User.Current.ServerUri.Trim().ToLower() != serverUri.Trim().ToLower()); } if (newServer || newUser) { await this.LogoutInternal(); } User.Current.Username = username; User.Current.Password = password; User.Current.ServerUri = serverUri; if (User.Current != null) { await ProgressUtility.SafeShow("Connecting to Server", async() => { //if reconnect process is running, cancel it if (ConnectionManager.IsReconnecting) { await ConnectionManager.CancelReconnecting(); } //here, if we are voluntarily connecting to a new server or new user, we must suppress the automatic reconnect attempt on closing connection if (newUser || newServer) { ConnectionManager.Deinitialize(); } WebSocketsClient.ResetWebSocketsClientUrl(new WebSocketsClientIos(), serverUri); ConnectionManager.Initialize(); var deviceListVc = DeviceListViewController.CreateInstance(); //test connection var response = await ServiceContainer.UserService.RequestConnection(username, password); ProgressUtility.Dismiss(); this.ShowError(response); if (response != null && response.IsSuccessful) { //only save the changes after successful login //User.Current.Save(); //this.NavigateTo(deviceListVc, inCurrentNavController: false); //PresentViewController(new AquamonixNavController(deviceListVc), true, null); LogUtility.Enabled = true; } else { if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.ConnectionTimeout) { if (DataCache.HasDevices) { deviceListVc.ShowConnectionError = true; this.NavigateTo(deviceListVc, inCurrentNavController: false); } else { AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.UnableToEstablishConnection); ConnectionManager.CancelReconnecting(); } } // Edited // if (response?.ErrorBody != null && response.ErrorBody.ErrorType == ErrorResponseType.AuthFailure) { AlertUtility.ShowErrorAlert(StringLiterals.ConnectionError, StringLiterals.AuthFailureMessage); Caches.ClearCachesForAuthFailure(); } this.LoadData(); } }); } } } catch (Exception e) { LogUtility.LogException(e); } }
protected override void HandleViewDidAppear(bool animated) { base.HandleViewDidAppear(animated); //UIApplication.SharedApplication.KeyWindow.AddSubview(ReconnectingOverlay.Instance); //LocationUtility.DistanceInMetersFrom(13.736717, 100.523186); if (_attemptAutoLogin) { var deviceListVc = DeviceListViewController.CreateInstance(); if (User.Current == null || !User.Current.HasConfig) { //redirect to Config VC //this.NavigationController.PushViewController(ViewControllerFactory.GetViewController<UserConfigViewController>(), true); NavigateUserConfig(); } else { ProgressUtility.SafeShow("Connecting", async() => { var userConfigVc = UserConfigViewController.CreateInstance(); var response = await ServiceContainer.UserService.RequestConnection( User.Current.Username, User.Current.Password); MainThreadUtility.InvokeOnMain(() => { ProgressUtility.Dismiss(); //on connection error, redirect to config if (response != null && response.IsSuccessful) { //redirect to device list this.NavigateTo(deviceListVc, inCurrentNavController: false); //this.PresentViewController(new AquamonixNavController(deviceListVc), true, null); } else { //this.NavigateTo(userConfigVc, inCurrentNavController: false); if (response?.ErrorBody != null && response.ErrorBody.ErrorType == Aquamonix.Mobile.Lib.Domain.Responses.ErrorResponseType.AuthFailure) { Caches.ClearCachesForAuthFailure(); } //is device cache valid? if (DataCache.HasDevices) { //redirect to device list deviceListVc.ShowConnectionError = true; this.NavigateTo(deviceListVc, inCurrentNavController: false); } else { //redirect to user config userConfigVc.ShowConnectionError = true; this.NavigateTo(userConfigVc, inCurrentNavController: false); } } }); }); } } else { this.PresentViewController(new StartViewController(true), false, null); } }