Ejemplo n.º 1
0
        private async void AttemptHumAuthentication(object sender, RoutedEventArgs e)
        {
            if (_authenticating)
            {
                return;
            }
            ProgressRingHum.Visibility = Visibility.Visible;

            _authenticating = true;
            Credentials.Update(UserNameHum.Text, UserPasswordHum.Password, ApiType.Hummingbird);
            try
            {
                var response = await new AuthQuery(ApiType.Hummingbird).GetRequestResponse(false);
                if (string.IsNullOrEmpty(response))
                {
                    throw new Exception();
                }
                if (response.Contains("\"error\": \"Invalid credentials\""))
                {
                    throw new Exception();
                }
                Settings.SelectedApiType = ApiType.Hummingbird;
                Credentials.SetAuthToken(response);
                Credentials.SetAuthStatus(true);
            }
            catch (Exception)
            {
                Credentials.SetAuthStatus(false);
                Credentials.Update(string.Empty, string.Empty, ApiType.Hummingbird);
                var msg = new MessageDialog("Unable to authorize with provided credentials.");
                await msg.ShowAsync();

                ProgressRingHum.Visibility = Visibility.Collapsed;
                _authenticating            = false;
                return;
            }
            try
            {
                await Utils.RemoveProfileImg();

                await ViewModelLocator.Hamburger.UpdateProfileImg();
            }
            catch (Exception)
            {
                //
            }
            await DataCache.ClearApiRelatedCache();

            ViewModelLocator.AnimeList.LogIn();
            await ViewModelLocator.Main.Navigate(PageIndex.PageAnimeList);

            ViewModelLocator.Hamburger.SetActiveButton(HamburgerButtons.AnimeList);

            _authenticating = false;
        }
Ejemplo n.º 2
0
        //prepare for big copy pasteeee...

        #region MAL

        private async void AttemptAuthentication(object sender, RoutedEventArgs e)
        {
            if (_authenticating)
            {
                return;
            }
            ProgressRing.Visibility = Visibility.Visible;
            _authenticating         = true;
            Credentials.Update(UserName.Text, UserPassword.Password, ApiType.Mal);
            try
            {
                var response = await new AuthQuery(ApiType.Mal).GetRequestResponse(false);
                if (string.IsNullOrEmpty(response))
                {
                    throw new Exception();
                }
                var doc = XDocument.Parse(response);
                Settings.SelectedApiType = ApiType.Mal;
                Credentials.SetId(int.Parse(doc.Element("user").Element("id").Value));
                Credentials.SetAuthStatus(true);
            }
            catch (Exception)
            {
                Credentials.SetAuthStatus(false);
                Credentials.Update(string.Empty, string.Empty, ApiType.Mal);
                var msg = new MessageDialog("Unable to authorize with provided credentials.");
                await msg.ShowAsync();

                ProgressRing.Visibility = Visibility.Collapsed;
                _authenticating         = false;
                return;
            }
            try
            {
                await Utils.RemoveProfileImg();

                await ViewModelLocator.Hamburger.UpdateProfileImg();
            }
            catch (Exception)
            {
                //
            }
            await DataCache.ClearApiRelatedCache();

            ViewModelLocator.AnimeList.LogIn();
            await ViewModelLocator.Main.Navigate(PageIndex.PageAnimeList);

            ViewModelLocator.Hamburger.SetActiveButton(HamburgerButtons.AnimeList);

            _authenticating = false;
        }
Ejemplo n.º 3
0
        private async void AttemptAuthentication()
        {
            if (Authenticating)
            {
                return;
            }
            Authenticating = true;
            Credentials.Update(UserNameInput, PasswordInput, CurrentApiType);
#if ANDROID
            Query.RefreshClientAuthHeader();
#endif
            PasswordInput = string.Empty;
            RaisePropertyChanged(() => PasswordInput);
            try
            {
                if (CurrentApiType == ApiType.Mal)
                {
                    var response = await new AuthQuery(ApiType.Mal).GetRequestResponse(false);
                    if (string.IsNullOrEmpty(response))
                    {
                        throw new Exception();
                    }
                    var doc = XDocument.Parse(response);
                    Settings.SelectedApiType = ApiType.Mal;
                    Credentials.SetId(int.Parse(doc.Element("user").Element("id").Value));
                    Credentials.SetAuthStatus(true);
                    ResourceLocator.TelemetryProvider.TelemetryTrackEvent(TelemetryTrackedEvents.LoggedInMyAnimeList);
                }
                else //hummingbird
                {
                    var response = await new AuthQuery(ApiType.Hummingbird).GetRequestResponse(false);
                    if (string.IsNullOrEmpty(response))
                    {
                        throw new Exception();
                    }
                    if (response.Contains("\"error\": \"Invalid credentials\""))
                    {
                        throw new Exception();
                    }
                    Settings.SelectedApiType = ApiType.Hummingbird;
                    Credentials.SetAuthToken(response);
                    Credentials.SetAuthStatus(true);
                    ResourceLocator.TelemetryProvider.TelemetryTrackEvent(TelemetryTrackedEvents.LoggedInHummingbird);
                }
            }
            catch (Exception e)
            {
                Credentials.SetAuthStatus(false);
                Credentials.Update(string.Empty, string.Empty, ApiType.Mal);
                ResourceLocator.MessageDialogProvider.ShowMessageDialog("Unable to authorize with provided credentials.", "Authorization failed.");
                Authenticating = false;
                return;
            }
            try
            {
                await ViewModelLocator.GeneralHamburger.UpdateProfileImg();
            }
            catch (Exception)
            {
                //
            }
            ViewModelLocator.GeneralMain.HideOffContentCommand.Execute(null);
            await DataCache.ClearApiRelatedCache();

            ViewModelLocator.GeneralMain.Navigate(PageIndex.PageAnimeList);
            ViewModelLocator.GeneralHamburger.SetActiveButton(HamburgerButtons.AnimeList);

            Authenticating = false;
        }