Esempio n. 1
0
        private void Login()
        {
            string server = hostBox.Text.Trim();
            int port = int.Parse(portBox.Text.Trim());
            string userName = userBox.Text.Trim();
            string password = passwordBox.Text.Trim();

            ClientPolicy policy = new ClientPolicy();
            policy.user = userName;
            policy.password = password;
            policy.failIfNotConnected = true;
            policy.timeout = 600000;

            AerospikeClient client = new AerospikeClient(policy, server, port);

            try
            {
                if (userName.Equals("admin") && password.Equals("admin"))
                {
                    Form form = new PasswordForm(client, userName);
                    form.ShowDialog();
                }

                // Query own user.
                User user = client.QueryUser(null, userName);

                if (user != null)
                {
                    bool admin = user.roles.Contains("user-admin");

                    // Initialize Global Data
                    Globals.RefreshRoles(client, user, admin);

                    Form form = new AdminForm(client, user, admin);
                    form.Show();
                }
                else
                {
                    throw new Exception("Failed to find user: " + userName);
                }
            }
            catch (Exception)
            {
                client.Close();
                throw;
            }
        }