Example #1
0
        private void cbxUsername_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbxUsername.SelectedIndexChanged -= cbxUsername_SelectedIndexChanged;

            if (cbxUsername.SelectedIndex > 0 &&
                cbxUsername.SelectedItem is SavedLogin)
            {
                SavedLogin sl = (SavedLogin)cbxUsername.SelectedItem;
                cbxUsername.Text          = sl.Username;
                cbxUsername.Items[0]      = sl.Username;
                cbxUsername.SelectedIndex = 0;
                txtPassword.Text          = sl.Password;
                cbxLocation.SelectedIndex = sl.StartLocationType;
                if (sl.StartLocationType == -1)
                {
                    cbxLocation.Text = sl.CustomStartLocation;
                }
                if (sl.GridID == "custom_login_uri")
                {
                    cbxGrid.SelectedIndex  = cbxGrid.Items.Count - 1;
                    txtCustomLoginUri.Text = sl.CustomURI;
                }
                else
                {
                    foreach (var item in cbxGrid.Items)
                    {
                        if (item is Grid && ((Grid)item).ID == sl.GridID)
                        {
                            cbxGrid.SelectedItem = item;
                            break;
                        }
                    }
                }
            }

            cbxUsername.SelectedIndexChanged += cbxUsername_SelectedIndexChanged;
        }
Example #2
0
        public static SavedLogin FromOSD(OSD data)
        {
            if (!(data is OSDMap))
            {
                return(null);
            }
            OSDMap     map = (OSDMap)data;
            SavedLogin ret = new SavedLogin();

            ret.Username  = map["username"];
            ret.Password  = map["password"];
            ret.GridID    = map["grid"];
            ret.CustomURI = map["custom_url"];
            if (map.ContainsKey("location_type"))
            {
                ret.StartLocationType = map["location_type"];
            }
            else
            {
                ret.StartLocationType = 1;
            }
            ret.CustomStartLocation = map["custom_location"];
            return(ret);
        }
Example #3
0
        private void InitializeConfig()
        {
            // Initilize grid dropdown
            int gridIx = -1;

            cbxGrid.Items.Clear();
            for (int i = 0; i < instance.GridManger.Count; i++)
            {
                cbxGrid.Items.Add(instance.GridManger[i]);
                if (MainProgram.CommandLine.Grid == instance.GridManger[i].ID)
                {
                    gridIx = i;
                }
            }
            cbxGrid.Items.Add("Custom");

            if (gridIx != -1)
            {
                cbxGrid.SelectedIndex = gridIx;
            }


            Settings s = instance.GlobalSettings;

            cbRemember.Checked = s["remember_login"];

            // Setup login name
            string savedUsername;

            if (string.IsNullOrEmpty(MainProgram.CommandLine.Username))
            {
                savedUsername = s["username"];
            }
            else
            {
                savedUsername = MainProgram.CommandLine.Username;
            }

            cbxUsername.Items.Add(savedUsername);

            try
            {
                if (s["saved_logins"] is OSDMap)
                {
                    OSDMap savedLogins = (OSDMap)s["saved_logins"];
                    foreach (string loginKey in savedLogins.Keys)
                    {
                        SavedLogin sl = SavedLogin.FromOSD(savedLogins[loginKey]);
                        cbxUsername.Items.Add(sl);
                    }
                }
            }
            catch
            {
                cbxUsername.Items.Clear();
                cbxUsername.Text = string.Empty;
            }

            cbxUsername.SelectedIndex = 0;

            // Fill in saved password or use one specified on the command line
            if (string.IsNullOrEmpty(MainProgram.CommandLine.Password))
            {
                txtPassword.Text = s["password"].AsString();
            }
            else
            {
                txtPassword.Text = MainProgram.CommandLine.Password;
            }


            // Setup login location either from the last used or
            // override from the command line
            if (string.IsNullOrEmpty(MainProgram.CommandLine.Location))
            {
                // Use last location as default
                if (s["login_location_type"].Type == OSDType.Unknown)
                {
                    cbxLocation.SelectedIndex = 1;
                    s["login_location_type"]  = OSD.FromInteger(1);
                }
                else
                {
                    cbxLocation.SelectedIndex = s["login_location_type"].AsInteger();
                    cbxLocation.Text          = s["login_location"].AsString();
                }
            }
            else
            {
                switch (MainProgram.CommandLine.Location)
                {
                case "home":
                    cbxLocation.SelectedIndex = 0;
                    break;

                case "last":
                    cbxLocation.SelectedIndex = 1;
                    break;

                default:
                    cbxLocation.SelectedIndex = -1;
                    cbxLocation.Text          = MainProgram.CommandLine.Location;
                    break;
                }
            }


            // Set grid dropdown to last used, or override from command line
            if (string.IsNullOrEmpty(MainProgram.CommandLine.Grid))
            {
                cbxGrid.SelectedIndex = s["login_grid"].AsInteger();
            }
            else if (gridIx == -1) // --grid specified but not found
            {
                MessageBox.Show(string.Format("Grid specified with --grid {0} not found", MainProgram.CommandLine.Grid),
                                "Grid not found",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning
                                );
            }

            // Restore login uri from settings, or command line
            if (string.IsNullOrEmpty(MainProgram.CommandLine.LoginUri))
            {
                txtCustomLoginUri.Text = s["login_uri"].AsString();
            }
            else
            {
                txtCustomLoginUri.Text = MainProgram.CommandLine.LoginUri;
                cbxGrid.SelectedIndex  = cbxGrid.Items.Count - 1;
            }

            // Start logging in if autologin enabled from command line
            if (MainProgram.CommandLine.AutoLogin)
            {
                BeginLogin();
            }
        }
Example #4
0
        private void SaveConfig()
        {
            Settings   s  = instance.GlobalSettings;
            SavedLogin sl = new SavedLogin();

            string username = cbxUsername.Text;

            if (cbxUsername.SelectedIndex > 0 && cbxUsername.SelectedItem is SavedLogin)
            {
                username = ((SavedLogin)cbxUsername.SelectedItem).Username;
            }

            if (cbxGrid.SelectedIndex == cbxGrid.Items.Count - 1) // custom login uri
            {
                sl.GridID    = "custom_login_uri";
                sl.CustomURI = txtCustomLoginUri.Text;
            }
            else
            {
                sl.GridID    = (cbxGrid.SelectedItem as Grid).ID;
                sl.CustomURI = string.Empty;
            }

            string savedLoginsKey = string.Format("{0}%{1}", username, sl.GridID);

            if (!(s["saved_logins"] is OSDMap))
            {
                s["saved_logins"] = new OSDMap();
            }

            if (cbRemember.Checked)
            {
                sl.Username = s["username"] = username;

                if (LoginOptions.IsPasswordMD5(txtPassword.Text))
                {
                    sl.Password   = txtPassword.Text;
                    s["password"] = txtPassword.Text;
                }
                else
                {
                    sl.Password   = Utils.MD5(txtPassword.Text);
                    s["password"] = Utils.MD5(txtPassword.Text);
                }
                if (cbxLocation.SelectedIndex == -1)
                {
                    sl.CustomStartLocation = cbxLocation.Text;
                }
                else
                {
                    sl.CustomStartLocation = string.Empty;
                }
                sl.StartLocationType = cbxLocation.SelectedIndex;
                ((OSDMap)s["saved_logins"])[savedLoginsKey] = sl.ToOSD();
            }
            else if (((OSDMap)s["saved_logins"]).ContainsKey(savedLoginsKey))
            {
                ((OSDMap)s["saved_logins"]).Remove(savedLoginsKey);
            }

            s["login_location_type"] = OSD.FromInteger(cbxLocation.SelectedIndex);
            s["login_location"]      = OSD.FromString(cbxLocation.Text);

            s["login_grid"]     = OSD.FromInteger(cbxGrid.SelectedIndex);
            s["login_uri"]      = OSD.FromString(txtCustomLoginUri.Text);
            s["remember_login"] = cbRemember.Checked;
        }