private async void LoginWithFacebook()
        {
            try
            {
                var result = await LoginUserService.LoginWithFacebookAsync();

                if (result == null)
                {
                    throw new LoginException("Failed to Login in with Facebook");
                }

                string username = await GetUsernameService.GetUsernameAsync(result.UserId);

                if (string.IsNullOrEmpty(username))
                {
                    await Navigation.PushAsync(new EnterUsernamePage(result));

                    return;
                }

                result.Username = username;
                SaveUserSecurityService.SaveUser(result);
                MessageBus.Publish(new LoginCompleteMessage());
                await Navigation.PushModalAsync(new ScorePredictNavigationPage(new MainPage()));
            }
            catch (LoginException lex)
            {
                DialogService.Alert(lex.Message);
            }
            catch (Exception ex)
            {
                DialogService.Alert("Login Failed. Please try again.");
            }
        }
示例#2
0
        private async void CreateUser()
        {
            try
            {
                var result = await CreateUserService.CreateUserAsync(
                    Username,
                    Password,
                    ConfirmPassword);

                if (result == null)
                {
                    throw new CreateUserException("An error occured creating your user. Please try again");
                }

                SaveUserSecurityService.SaveUser(result);

                await Navigation.PushModalAsync(new ScorePredictNavigationPage(new MainPage()));

                await Navigation.PopToRootAsync(false);
            }
            catch (CreateUserException ex)
            {
                DialogService.Alert(ex.Message);
            }
            catch
            {
                DialogService.Alert("An unknown error occurred. Please try again");
            }
        }
        private async void Login()
        {
            try
            {
                DialogService.ShowLoading("Authenticating...");

                var user = await LoginUserService.LoginAsync(Username, Password);

                if (user == null)
                {
                    throw new LoginException("Invalid Username Password combination");
                }

                if (string.IsNullOrEmpty(user.Username))
                {
                    await Navigation.PushAsync(new EnterUsernamePage(user));

                    return; // end execution
                }

                SaveUserSecurityService.SaveUser(user);
                Username = string.Empty;
                Password = string.Empty;

                MessageBus.Publish(new LoginCompleteMessage());
                await Navigation.PushModalAsync(new ScorePredictNavigationPage(new MainPage()));
            }
            catch (LoginException lex)
            {
                DialogService.Alert(lex.Message);
            }
            catch (Exception ex)
            {
                DialogService.Alert("Login did not succeed. Please try again");
            }
            finally
            {
                DialogService.HideLoading();
            }
        }
示例#4
0
        private async void Save()
        {
            try
            {
                var username = await SetUsernameService.SetUsernameForUserAsync(User.UserId, Username);

                User.Username = username;
                SaveUserSecurityService.SaveUser(User);

                // on success - pop to root and show the mainview as a modal
                await Navigation.PushModalAsync(new MainPage());

                await Navigation.PopToRootAsync(false);
            }
            catch (SaveUsernameException ex)
            {
                DialogService.Alert(ex.Message);
            }
            catch (Exception ex)
            {
                DialogService.Alert("An error occurred. Please try again");
            }
        }