Ejemplo n.º 1
0
        private async Task RunLogin(string User, string Password, string URL, bool StayConnected)
        {
            try
            {
                api.SetStoreUrl(URL);
                var LoginResult = await api.CheckLogin(User, Password);

                if (!LoginResult)
                {
                    throw new LoginException("The credentials you entered are incorrect");
                }
                if (LoginResult && StayConnected)
                {
                    NavigationService.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative));
                }
                else if (LoginResult && !StayConnected)
                {
                    if (Convert.ToBoolean(SaveStore.IsChecked))
                    {
                        var StoreName = await api.GetStoreName();

                        if (!UserSettings.Contains("store_url_" + StoreName))
                        {
                            UserSettings.Add("store_url_" + StoreName, URL);
                        }
                    }
                    if (Convert.ToBoolean(StayConnect.IsChecked))
                    {
                        var EncryptedPass   = ProtectedData.Protect(System.Text.Encoding.Unicode.GetBytes(Password), null);
                        var EncryptedString = Convert.ToBase64String(EncryptedPass);
                        UserSettings.Add(User, EncryptedString);
                        if (UserSettings.Contains("stay_connected"))
                        {
                            UserSettings.Remove("stay_connected");
                        }
                        UserSettings.Add("stay_connected", true);
                    }
                    if (UserSettings.Contains("current_user"))
                    {
                        UserSettings.Remove("current_user");
                    }
                    UserSettings.Add("current_user", User);
                    if (UserSettings.Contains("current_url"))
                    {
                        UserSettings.Remove("current_url");
                    }
                    UserSettings.Add("current_url", URL);
                    NavigationService.Navigate(new Uri("/Pages/Dashboard.xaml", UriKind.Relative));
                }
            }catch (LoginException le)
            {
                HideLoading();
                MessageBox.Show(le.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        private async Task LoginToExisting(string url, string user, string pass, TextView Error)
        {
            try{
                api.SetStoreUrl(url);
                await api.CheckLogin(user, pass);

                Intent myIntent = new Intent(this, typeof(Dashboard));
                StartActivity(myIntent);
                Finish();
                dialog.Dismiss();
            }

            catch (LoginException ex)
            {
                Console.WriteLine(ex.Message);
                dialog.Dismiss();
                Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                Error.Text = ex.Message;
            }
        }
Ejemplo n.º 3
0
        private void MyStoresList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (MyStoresList.SelectedIndex == -1)
            {
                return;
            }
            else
            {
                StackPanel   Sp   = new StackPanel();
                PhoneTextBox User = new PhoneTextBox();
                User.Hint = "Username";
                PasswordBox Pass = new PasswordBox();
                Pass.Password = "******";
                Sp.Children.Add(User);
                Sp.Children.Add(Pass);
                CustomMessageBox messageBox = new CustomMessageBox()
                {
                    Caption            = "Change Store",
                    Message            = "Want to change to " + urls[MyStoresList.SelectedIndex] + "?",
                    LeftButtonContent  = "Yes",
                    RightButtonContent = "No"
                };

                messageBox.Dismissed += (s1, e1) =>
                {
                    switch (e1.Result)
                    {
                    case CustomMessageBoxResult.LeftButton:
                        CustomMessageBox LoginBox = new CustomMessageBox()
                        {
                            Caption            = "Login to " + urls[MyStoresList.SelectedIndex],
                            Message            = "Enter your credentials",
                            Content            = Sp,
                            LeftButtonContent  = "Login",
                            RightButtonContent = "Cancel"
                        };
                        LoginBox.Dismissed += async(s2, e2) =>
                        {
                            switch (e2.Result)
                            {
                            case CustomMessageBoxResult.LeftButton:

                                string Url = "";
                                UrlsMap.TryGetValue(urls[MyStoresList.SelectedIndex], out Url);
                                api.SetStoreUrl(Url);
                                var loginResult = await api.CheckLogin(User.Text, Pass.Password);

                                if (loginResult)
                                {
                                    StoreUrl    = Url;
                                    loginResult = false;
                                    ChangeStore = true;
                                    UserName    = User.Text;
                                    var TaskReload = InitializeStore();
                                    MyStoresList.SelectedIndex = -1;
                                }
                                else
                                {
                                    MessageBox.Show("The credentials seem to be incorrect");
                                    MyStoresList.SelectedIndex = -1;
                                }
                                break;

                            case CustomMessageBoxResult.RightButton:
                                MyStoresList.SelectedIndex = -1;
                                LoginBox.Dismiss();
                                break;

                            default:
                                break;
                            }
                        };

                        LoginBox.Show();
                        break;

                    case CustomMessageBoxResult.RightButton:
                        MyStoresList.SelectedIndex = -1;
                        messageBox.Dismiss();
                        break;

                    default:
                        break;
                    }
                };

                messageBox.Show();
            }
        }
Ejemplo n.º 4
0
        private async Task ProcessLogin(EditText SiteUrl, EditText email, EditText passwordField, Button loginB, NopCore api,
                                        CheckBox SaveUrl, ISharedPreferences prefs, ISharedPreferencesEditor editor, CheckBox StayConnected, TextView ErrorMessage,
                                        Boolean newStore, Spinner Urls)
        {
            string url = "";

            if (newStore)
            {
                url = SiteUrl.Text.ToString();
            }
            else
            {
                url = Urls.SelectedItem.ToString();
            }

            string user     = email.Text.ToString();
            string password = passwordField.Text.ToString();

            try
            {
                hideSoftKeyboard(this, loginB);
                dialog = ProgressDialog.Show(this, "", "Connecting. Please wait... ", true);

                api.SetStoreUrl(url);
                var LoginSuccess = false;
                LoginSuccess = await api.CheckLogin(user, password);

                if (LoginSuccess)
                {
                    Intent intent = new Intent(this, typeof(Dashboard));

                    editor.PutString("current_user", user);
                    var Associate = Intent.GetBooleanExtra("associate", false);
                    if ((SaveUrl.Checked || Associate) && !prefs.GetString("store_url_" + api.GetStoreName(), "").Equals(url) && newStore)
                    {
                        editor.PutString("store_url_" + api.GetStoreName(), url);
                        editor.PutString("current_url", url);
                    }

                    if (StayConnected.Checked)
                    {
                        editor.PutBoolean("stay_connected", true);
                    }

                    editor.PutBoolean("login_state", true);
                    editor.Apply();
                    dialog.Dismiss();
                    Processing = false;
                    if (Associate)
                    {
                        Dashboard.DashboardA.Finish();
                    }

                    StartActivity(intent);
                    Finish();
                }
                else
                {
                    throw new LoginException("The credentials seem to be incorrect");
                }
            }

            catch (LoginException ex)
            {
                Console.WriteLine(ex.Message);
                loginB.Text = "Login";
                api         = new NopCore();
                dialog.Dismiss();
                Processing        = false;
                ErrorMessage.Text = ex.Message;
            }
            catch (WrongUrlException wue)
            {
                Console.WriteLine(wue.Message);
                loginB.Text = "Login";
                api         = new NopCore();
                dialog.Dismiss();
                Processing        = false;
                ErrorMessage.Text = wue.Message;
            }
        }