SnapDotNet.Apps.ViewModels.StartViewModel.SignIn C# (CSharp) Method

SignIn() private method

Attempts to sign the user into Snapchat.
private SignIn ( Page nextPage ) : void
nextPage Windows.UI.Xaml.Controls.Page
return void
		private async void SignIn(Page nextPage)
		{
//			Uncomment this to force login with a foreign Auth Token
//
//			App.SnapChatManager.Account = new Account
//			{
//				Friends = new ObservableCollection<Friend>(),
//				AddedFriends = new ObservableCollection<AddedFriend>(),
//				BestFriends = new ObservableCollection<string>(),
//				Snaps = new ObservableCollection<Snap>(),
//				AuthToken = "",
//				Username = "alexerax"
//			};
//			App.SnapChatManager.AuthToken = "";
//			App.SnapChatManager.Username = "alexerax";
//			await App.SnapChatManager.UpdateAllAsync(() => { }, App.Settings);
//			App.CurrentFrame.Navigate((typeof (MainPage)));
//#if WINDOWS_PHONE_APP
//			await
//					App.MobileService.GetTable<User>()
//						.InsertAsync(new User
//						{
//							AuthExpired = false,
//							NewUser = true,
//							DeviceIdent = App.DeviceIdent,
//							SnapchatAuthToken = App.SnapChatManager.AuthToken,
//							SnapchatUsername = App.SnapChatManager.Username
//						});
//#endif
//			return;

			try
			{
				if (string.IsNullOrEmpty(CurrentUsername) || string.IsNullOrEmpty(CurrentPassword))
				{
					var dialog =
						new MessageDialog(App.Loader.GetString("InvalidCredentialsBody"), App.Loader.GetString("InvalidCredentialsHeader"));
					await dialog.ShowAsync();
					return;
				}

#if WINDOWS_PHONE_APP
				// Tell UI we're Signing In
				StatusBar.GetForCurrentView().ProgressIndicator.Text = App.Loader.GetString("SigningIn");
				await StatusBar.GetForCurrentView().ProgressIndicator.ShowAsync();
#endif
				ProgressModalVisibility = Visibility.Visible;
				ProgressModalIsVisible = true;

				// Try and log into SnapChat
				await App.SnapChatManager.Endpoints.AuthenticateAsync(CurrentUsername, CurrentPassword);

				// This is unnecessary here and slows down the sign in process significantly. xoxo, Matt
				/*try
				{
					await App.SnapChatManager.UpdateAllAsync(() => { }, App.Settings);
				}
				catch (InvalidHttpResponseException exception)
				{
					if (exception.Message == "Unauthorized")
					{
						var dialog = new MessageDialog(App.Loader.GetString("UnauthorizedBody"), App.Loader.GetString("UnauthorizedHeader"));
						dialog.ShowAsync();
					}
				}*/

#if WINDOWS_PHONE_APP
				// Register device for Push Notifications
				await
					App.MobileService.GetTable<User>()
						.InsertAsync(new User
						{
							AuthExpired = false,
							NewUser = true,
							DeviceIdent = App.DeviceIdent,
							SnapchatAuthToken = App.SnapChatManager.AuthToken,
							SnapchatUsername = App.SnapChatManager.Username
						});
#endif
			}
			catch (InvalidCredentialsException)
			{
				var dialog =
					new MessageDialog(App.Loader.GetString("InvalidCredentialsBody"), App.Loader.GetString("InvalidCredentialsHeader"));
				dialog.ShowAsync();
			}
			catch (InvalidHttpResponseException exception)
			{
				var dialog =
					new MessageDialog(String.Format("{0} \n {1}.", App.Loader.GetString("InvalidHttpBody"), exception.Message),
						App.Loader.GetString("InvalidHttpHeader"));
				dialog.ShowAsync();
			}
			finally
			{
				// Tell UI we're not Signing In no mo'
#if WINDOWS_PHONE_APP
				StatusBar.GetForCurrentView().ProgressIndicator.Text = String.Empty;
				StatusBar.GetForCurrentView().ProgressIndicator.HideAsync();
#endif
				ProgressModalVisibility = Visibility.Collapsed;
				ProgressModalIsVisible = false;
			}
			if ( App.SnapChatManager.Account == null || 
				!App.SnapChatManager.Account.Logged ||
				!App.SnapChatManager.IsAuthenticated())
			{
#if WINDOWS_PHONE_APP
				CurrentPassword = "";
				//App.CurrentFrame.Navigate(typeof(StartPage), "removeBackStack");
#endif

				return;
			}

			App.CurrentFrame.Navigate(nextPage == null ? typeof(MainPage) : nextPage.GetType(), "removeBackStack");
		}