public void AppInit(NavigationService navServiceParam, NavigationContext navContextParam) { // This is the primary location for special logic when entering the app. // Here is where we determine to go to the home screen or login screen. // And it will be the starting point for ALL tile entries // Instaniate here and not in the constructor // If you do it in the constructor the MainFrame will be null. navService = new MyNavigationService(navServiceParam as NavigationService); if(isStartup) { isStartup = false; popup.IsOpen = true; NavigationContext navContext = (navContextParam as NavigationContext); var settings = IsolatedStorageSettings.ApplicationSettings; User savedUser; //settings.Remove("appUser"); settings.TryGetValue<User>("appUser", out savedUser); if (savedUser == null) { popup.IsOpen = false; GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } else { CapitalServiceClient client = new CapitalServiceClient(); client.LoginCompleted += (s, e) => { try { popup.IsOpen = false; if (e.Result != null) { User = e.Result; // Needed for Notification/Tile/Toast Config Messenger.Default.Send(new ToastMessage()); if (navContext.QueryString.ContainsKey("Statement")) { int id = Convert.ToInt32(navContext.QueryString["Statement"]); LoadStatement(id); } else { GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Home", OnStack = false }); } } else { GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } } catch(Exception) { //MessageBox.Show(ex.Message); GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } }; client.LoginAsync(savedUser); } } }
private void UserLogin() { object focusObj = FocusManager.GetFocusedElement(); if (focusObj != null && focusObj is TextBox) { var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); (focusObj as TextBox).IsEnabled = false; (focusObj as TextBox).IsEnabled = true; return; } else if (focusObj != null && focusObj is PasswordBox) { var binding = (focusObj as PasswordBox).GetBindingExpression(PasswordBox.PasswordProperty); binding.UpdateSource(); (focusObj as PasswordBox).IsEnabled = false; (focusObj as PasswordBox).IsEnabled = true; return; } if (!ModelValidation()) { return; } CapitalServiceClient service = service = new CapitalServiceClient(); try { IsBusy = true; // Encrypt Password before sending across the wire string key = "BLANDDIESEL"; UTF8Encoding encoding = new UTF8Encoding(); byte[] keyByte = encoding.GetBytes(key); HMACSHA256 sha256 = new HMACSHA256(keyByte); byte[] passwordbytes = encoding.GetBytes(password); byte[] hashMessage = sha256.ComputeHash(passwordbytes); loginUser.Password = ConvertToString(hashMessage); loginUser.Devices = new System.Collections.ObjectModel.ObservableCollection<Device>(); byte[] uniqueId = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"); loginUser.Devices.Add(new Device { // Get Phone Data UniqueDeviceId = BitConverter.ToString(uniqueId), Manufacturer = DeviceStatus.DeviceManufacturer, Model = DeviceStatus.DeviceHardwareVersion, DeviceName = DeviceStatus.DeviceName, }); service.LoginCompleted += (s, e) => { if (e.Error == null) { if (e.Result != null) { var settings = IsolatedStorageSettings.ApplicationSettings; settings.Remove("appUser"); settings.Add("appUser", e.Result); Messenger.Default.Send<SetUserMessage>(new SetUserMessage { User = e.Result }); Messenger.Default.Send<NavigationMessage>(new NavigationMessage { Destination = "Home", Source = this.GetType().Name, OnStack = false }); } } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; service.LoginAsync(loginUser); } catch (Exception) { service.Abort(); } finally { service.CloseAsync(); } }