예제 #1
0
        private void RedirectPageForLoggedin()
        {
            if (ApiUniversal.Auth.IsLoggedIn)
            {
                return;
            }

            var storage = new Storage.Storage();

            string loggedInName     = storage.LoadFromLocal(StorageKeys.LoggedInName)?.ToString() ?? string.Empty;
            string loggedInPassword = storage.LoadFromLocal(StorageKeys.LoggedInPassword)?.ToString() ?? string.Empty;

            if (string.IsNullOrEmpty(loggedInName) || string.IsNullOrEmpty(loggedInPassword))
            {
                Frame.Navigate(typeof(Login));
                return;
            }

            var  loginScrape = new ApiUniversal.Authentication.LoginScrape(loggedInName, loggedInPassword);
            bool isLoggedIn  = loginScrape.Execute();

            if (!isLoggedIn)
            {
                Frame.Navigate(typeof(Login));
                return;
            }
        }
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            string email    = LoginTextBox.Text;
            string password = PasswordTextBox.Password;

            //do login, if worked, save email and password
            var  loginScrape = new ApiUniversal.Authentication.LoginScrape(email, password);
            bool isLoggedIn  = loginScrape.Execute();

            if (isLoggedIn)
            {
                var storage = new Storage.Storage();
                storage.StoreInLocal(StorageKeys.LoggedInName, email);
                storage.StoreInLocal(StorageKeys.LoggedInPassword, password);

                Frame.Navigate(typeof(MainPage));
            }
            else
            {
                //show message
                ErrorMessage.Visibility = Visibility.Visible;
            }
        }