Beispiel #1
0
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            string  profile;
            JObject j;
            bool    verified = false;
            string  owner    = textBoxAccount.Text;

            if (owner.Contains("@"))
            {
                owner    = ProfileContractHelper.QueryOwner(owner);
                verified = true;
            }
            j       = ProfileContractHelper.QueryByAccount(owner);
            profile = j.ToString();
            string email = j["email"].AsString();

            if (email != "" && !verified)
            {
                JObject j1     = ProfileContractHelper.Query(email);
                string  email1 = j1["email"].AsString();
                verified = email1.Equals(email);
            }
            textBoxProfile.Text          = profile;
            labelVerificationStatus.Text = verified ? "Yes" : "No";
            textBoxAddress.Text          = owner;
        }
        private void buttonSendResponse_Click(object sender, EventArgs e)
        {
            string emailVerifyRespUrl = ProfileContractHelper.EmailVerifyResponseUrl();
            string resp = HttpHelper.Post(emailVerifyRespUrl, responseJson.ToString());

            if (resp == "")
            {
                MessageBox.Show("Failed to get response from verification server", "Error!");
                return;
            }
            try
            {
                JObject j  = JObject.Parse(resp);
                bool    ok = j["result"].AsBoolean();
                if (!ok)
                {
                    MessageBox.Show("Verification failed due to error: " + j["error"].AsString());
                }
                MessageBox.Show("Verification succeed");
            }
            catch (Exception)
            {
                MessageBox.Show("Received invalid response from verification server", "Error!");
                return;
            }
        }
        private void RefreshCurrentAccountProfile()
        {
            string  owner    = comboBoxAccounts.Text;
            JObject j        = ProfileContractHelper.QueryByAccount(owner);
            string  profile  = j.ToString();
            string  email    = j["email"].AsString();
            bool    verified = false;

            if (email != "")
            {
                JObject j1     = ProfileContractHelper.Query(email);
                string  email1 = j1["email"].AsString();
                verified = email1.Equals(email);
            }
            textBoxProfile.Text          = profile;
            labelVerificationStatus.Text = verified ? "Yes" : "No";
            linkLabelVerifyLink.Visible  = !verified && email != "";
            if (linkLabelVerifyLink.Visible)
            {
                emailVerifyReqParams = new Dictionary <string, string>()
                {
                    { "email", email },
                    { "owner", owner },
                };
            }
        }
 private void buttonEdit_Click(object sender, EventArgs e)
 {
     if (editing)
     {
         try
         {
             JObject j = JObject.Parse(textBoxProfile.Text);
             if (j["email"] == null)
             {
                 MessageBox.Show("The email address is missing in the profile", "Error!");
                 return;
             }
             j["pubkey"] = GetCurrentAccountPublicKey().ToHexString();
             ProfileContractHelper.Register(j.ToString(), comboBoxAccounts.Text);
         }
         catch (Exception)
         {
             MessageBox.Show("The profile should be a valid json object", "Error!");
             return;
         }
     }
     else
     {
         savedProfile = textBoxProfile.Text;
     }
     ToggleEditMode();
 }
        private string CheckCurrentAccountProfile()
        {
            JObject profile = ProfileContractHelper.QueryByAccount(comboBoxAccounts.Text);
            string  email   = profile["email"].AsString();

            if (email == "")
            {
                MessageBox.Show("Your current account has no valid email binding yet, register one first", "Error!");
                return("");
            }
            return(email);
        }
 private void buttonGrant_Click(object sender, EventArgs e)
 {
     if (textBoxEmail.Text.Length < 3 || textBoxAccount.Text.Length < 26)
     {
         MessageBox.Show("Invalid input", "Error!");
         return;
     }
     if (ProfileContractHelper.Grant(textBoxEmail.Text, textBoxAccount.Text))
     {
         this.DialogResult = DialogResult.OK;
     }
 }
        private void ProfileForm_Load(object sender, EventArgs e)
        {
            if (plugin_profile.api.CurrentWallet != null)
            {
                emailVerifyReqUrl = ProfileContractHelper.EmailVerifyRequestUrl();
                Wallet wallet = plugin_profile.api.CurrentWallet;
                foreach (var account in wallet.GetAccounts())
                {
                    var    addrOut = account.ScriptHash;
                    string addrStr = Wallet.ToAddress(addrOut);
                    comboBoxAccounts.Items.Add(addrStr);
                }
                comboBoxAccounts.SelectedIndex = 0;
                comboBoxAccounts.Refresh();

                buttonEdit.Enabled  = true;
                buttonQuery.Enabled = true;
            }
        }
        private void buttonVerifyResponse_Click(object sender, EventArgs e)
        {
            if (!CheckEmailAddressInput())
            {
                return;
            }
            string  myEmail = CheckCurrentAccountProfile();
            JObject j       = ParseChallengeMessageSend(textBoxChallengeSend.Text.Trim(), myEmail);

            if (j == null)
            {
                return;
            }
            string challenge = j["challenge"].AsString();
            string message   = textBoxResponseReceived.Text.Trim();

            string[] parts = message.Split('\n');
            if (parts.Length != 2)
            {
                MessageBox.Show("Received response message is invalid", "Error!");
                return;
            }
            try
            {
                JObject j1       = JObject.Parse(parts[0]);
                string  purpose  = j1["purpose"].AsString();
                string  from     = j1["from"].AsString();
                string  to       = j1["to"].AsString();
                string  address  = j1["address"].AsString();
                string  response = j1["response"].AsString();
                if (purpose != "NEO email address verification response" || response.Length != 16)
                {
                    MessageBox.Show("Received response message is invalid", "Error!");
                    return;
                }
                if (from != textBoxPeerEmail.Text)
                {
                    MessageBox.Show("Received response message is not send from email addree to be verified", "Error!");
                    return;
                }
                if (to != myEmail)
                {
                    MessageBox.Show("Received response message is not send to current selected account", "Error!");
                    return;
                }
                JObject j2        = ProfileContractHelper.QueryByAccount(address);
                string  peerEmail = j2["email"].AsString();
                if (peerEmail != from)
                {
                    MessageBox.Show("Received response message is send from email address different than its profile", "Error!");
                    return;
                }
                string pubkey = j2["pubkey"].AsString();
                if (!VerifySignature(parts[0], parts[1], pubkey))
                {
                    MessageBox.Show("Received response message has invalid signature!", "Error!");
                    return;
                }
                if (response != challenge)
                {
                    MessageBox.Show("Received response message has invalid response code than your original generated challenge code", "Error!");
                    return;
                }
                MessageBox.Show("The email address has pass all verication test successfully");
            }
            catch (Exception)
            {
                MessageBox.Show("Received challenge message is invalid", "Error!");
                return;
            }
        }