Example #1
0
        private async void SingleSignIn_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(usernameBox.Text) || string.IsNullOrWhiteSpace(passwordBox.Password))
            {
                EmptyField();
                return;
            }

            var credential = new PasswordCredential(App.RL.GetString("CredResName"), usernameBox.Text, passwordBox.Password);
            var connector  = new MUConnector(credential);

            if (await connector.Login())
            {
                App.MainViewModel.connector = connector;
                ResourceLoader rl     = App.RL;
                var            dialog = new MessageDialog(rl.GetString("SingleUseWarning"), "Are You Sure?");
                dialog.Commands.Add(new UICommand("I'm Sure"));
                dialog.Commands.Add(new UICommand("Save Login"));
                var result = await dialog.ShowAsync();

                if (result.Label == "I'm Sure")
                {
                    Frame.Navigate(typeof(FoodTile.Views.MainPage));
                }
                else
                {
                    SaveAndLogin(credential, connector);
                }
            }
        }
Example #2
0
        private async void SignIn_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(usernameBox.Text) || string.IsNullOrWhiteSpace(passwordBox.Password))
            {
                EmptyField();
                return;
            }

            SetLoading();

            var credential = new PasswordCredential(App.RL.GetString("CredResName"), usernameBox.Text, passwordBox.Password);
            var connector  = new MUConnector(credential);

            if (await connector.Login())
            {
                SaveAndLogin(credential, connector);
            }
            else
            {
                await new MessageDialog(App.RL.GetString("LoginFailedMsg"), App.RL.GetString("LoginFailedTitle")).ShowAsync();
            }

            UnsetLoading();
        }
Example #3
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            PasswordVault vault = new PasswordVault();

            try
            {
                var creds = vault.FindAllByResource(App.RL.GetString("CredResName"));
                if (creds.Count > 0)
                {
                    SetLoading();

                    var idVerificationPossible = await UserConsentVerifier.CheckAvailabilityAsync();

                    var localSettings = ApplicationData.Current.LocalSettings.Values;

                    bool goodToGo = true;

                    if (idVerificationPossible == UserConsentVerifierAvailability.Available && (bool)(localSettings[App.RL.GetString("VerifyIdSettingString")] ?? false))
                    {
                        var verified =
                            await
                            UserConsentVerifier.RequestVerificationAsync(
                                "Just need to double check that it's you before we login :)");

                        goodToGo = verified == UserConsentVerificationResult.Verified;

                        if (verified == UserConsentVerificationResult.RetriesExhausted)
                        {
                            foreach (var cred in creds)
                            {
                                vault.Remove(cred);
                            }
                            await
                            new MessageDialog("For your safety, we've removed your saved login data.",
                                              "Too Many Failed Attempts").ShowAsync();
                        }

                        if (!goodToGo)
                        {
                            await new MessageDialog("Because you enabled identity verification, you will not be able to start the app without verification.", "We Couldn't Verify Your Identity").ShowAsync();
                            App.Current.Exit();
                        }
                    }

                    var connector = new MUConnector(creds.First());
                    if (await connector.Login())
                    {
                        App.MainViewModel.connector   = connector;
                        App.MainViewModel.SignOnSaved = true;
                        Frame.Navigate(typeof(FoodTile.Views.MainPage));
                    }
                    else
                    {
                        vault.Remove(creds.First());
                        await new MessageDialog(App.RL.GetString("SavedLoginFailMsg"), App.RL.GetString("SavedLoginFailTitle")).ShowAsync();
                    }


                    UnsetLoading();
                }
            }
            catch
            {
                //Used to handle the case when no credentials are found - safe to move on
            }

            base.OnNavigatedTo(e);
        }
Example #4
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            BackgroundTaskDeferral _defferal = taskInstance.GetDeferral();
            var appdata = ApplicationData.Current.LocalSettings;

            if (!(bool)(appdata.Values["TileUpdates"] ?? false) && !(bool)(appdata.Values["UseToasts"] ?? false))   // if task isn't needed, kill it
            {
                _defferal.Complete();
                return;
            }

            PasswordVault      vault = new PasswordVault();
            PasswordCredential cred;

            try
            {
                cred = vault.FindAllByResource("MYUW").First(); // Make sure this matches CredResName
            }
            catch
            {
                _defferal.Complete();
                return;
            }

            var connector = new MUConnector(cred);

            if (await connector.Login())
            {
                //double lastValue = (float)(appdata.Values["LastValue"] ?? -1); //shit's stored as a float...  avoids invalid cast

                float lastValue = -1;

                if (appdata.Values.ContainsKey("LastValue"))
                {
                    float?lv = appdata.Values["LastValue"] as float?;  // stupid workarounds for float precision
                    lastValue = lv.Value;
                }
                var hfs = await connector.GetHfsData();

                var term = await connector.GetTermInfo();

                double average = hfs.resident_dining.balance / term.AdjustedDaysRemaining(LoadSavedDates());

                if ((bool)(appdata.Values["TileUpdates"] ?? false))
                {
                    var bindingContent    = new TileBindingContentAdaptive();
                    var medBindingContent = new TileBindingContentAdaptive();
                    var items             = bindingContent.Children;
                    var medItems          = medBindingContent.Children;

                    medItems.Add(new TileText()
                    {
                        Text  = $"{hfs.resident_dining.balance:C} remaining",
                        Style = TileTextStyle.Body
                    });

                    items.Add(new TileText()
                    {
                        Text  = $"{hfs.resident_dining.balance:C} remaining",
                        Style = TileTextStyle.Subtitle
                    });

                    var line2 = new TileText()
                    {
                        Text  = $"{term.AdjustedDaysRemaining(LoadSavedDates())} days",
                        Style = TileTextStyle.Caption
                    };

                    var line3 = new TileText()
                    {
                        Text  = $"${average:0.00} per day",
                        Style = TileTextStyle.Caption
                    };

                    items.Add(line2);
                    items.Add(line3);
                    medItems.Add(line2);
                    medItems.Add(line3);

                    var tileBinding = new TileBinding()
                    {
                        Content     = bindingContent,
                        DisplayName = "FoodTile",
                        Branding    = TileBranding.NameAndLogo
                    };

                    var medTileBinding = new TileBinding()
                    {
                        Content     = medBindingContent,
                        DisplayName = "FoodTile",
                        Branding    = TileBranding.NameAndLogo
                    };

                    var content = new TileContent()
                    {
                        Visual = new TileVisual
                        {
                            TileMedium = medTileBinding,
                            TileWide   = tileBinding,
                            TileLarge  = tileBinding
                        }
                    };

                    var note    = new TileNotification(content.GetXml());
                    var updater = TileUpdateManager.CreateTileUpdaterForApplication();

                    updater.Update(note);
                }

                if (hfs.resident_dining.balance != lastValue)
                {
                    if ((bool)(appdata.Values["UseToasts"] ?? false))
                    {
                        var toastContent = new ToastContent()
                        {
                            Visual = new ToastVisual()
                            {
                                TitleText = new ToastText()
                                {
                                    Text = $"Dining Balance ${hfs.resident_dining.balance:0.00}"
                                },
                                BodyTextLine1 = new ToastText()
                                {
                                    Text = $"New daily average ${average:0.00}"
                                },
                                BodyTextLine2 = new ToastText()
                                {
                                    Text = $"{term.AdjustedDaysRemaining(LoadSavedDates())} days remaining in quarter"
                                }
                            }
                        };

                        var note  = ToastNotificationManager.CreateToastNotifier();
                        var toast = new ToastNotification(toastContent.GetXml());
                        note.Show(toast);
                    }
                    appdata.Values["LastValue"] = hfs.resident_dining.balance;
                }
            }
            connector.Dispose();
            _defferal.Complete();
        }