コード例 #1
0
ファイル: SmtpUtilityTest.cs プロジェクト: sakapon/KLibrary-2
        public void SendTest()
        {
            string from = "*****@*****.**";

            string[] to      = new[] { "*****@*****.**" };
            string[] cc      = new[] { "*****@*****.**" };
            string   subject = "SmtpUtility のテスト";
            string   body    = "SmtpUtility のテストです。\r\n\r\n3 行目です。\r\n";

            SmtpUtility.Send(from, to, cc, subject, body);

            Assert.Inconclusive("電子メールを受信したことを確認してください。");
        }
コード例 #2
0
        private async void okButton_Click(object sender, System.EventArgs e)
        {
            okButton.Visible     = false;
            cancelButton.Visible = false;
            loadingPictureBox.Start();
            loadingPictureBox.Visible = true;

            string email = emailTextBox.Text;

            using (SqlDataReader dataReader = await SqlUtility.Read("SELECT [email], [name] FROM [users] WHERE [email] = @email;",
                                                                    new string[] { email }, delegate(SqlException ex1)
            {
                StopLoading();
            }))
            {
                if (dataReader == null)
                {
                    return;
                }

                if (!await dataReader.ReadAsync())
                {
                    StopLoading();
                    MessageBox.Show("Email not linked to any account!", ChatAppForm.TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                string resetCode = new Random().Next(0x100000, 0xffffff + 1).ToString("X").ToLower();
                if (!await SmtpUtility.Send(email, "Password reset",
                                            "Hello " + dataReader.GetString(1) + ",\n\n"
                                            + "Please use the following reset code to reset the password of your account.\n\n"
                                            + "Reset code: #" + resetCode, delegate(SmtpException ex2)
                {
                    StopLoading();
                }))
                {
                    return;
                }

                StopLoading();
                SwitchTo(new ResetCodePage(email, resetCode), SWITCH_LEFT);
            }
        }
コード例 #3
0
ファイル: SignUpPage.cs プロジェクト: manojmkhanna/chat-app
        private async void signUpButton_Click(object sender, EventArgs e)
        {
            signUpButton.Visible = false;
            cancelButton.Visible = false;
            loadingPictureBox.Start();
            loadingPictureBox.Visible = true;

            string email = emailTextBox.Text;

            using (SqlDataReader dataReader = await SqlUtility.Read("SELECT [email] FROM [users] WHERE [email] = @email;",
                                                                    new string[] { email }, OnException))
            {
                if (dataReader == null)
                {
                    return;
                }

                if (!Validate(emailTextBox, await dataReader.ReadAsync(), "Email should not be linked to another account!"))
                {
                    StopLoading();
                    return;
                }
            }

            string name             = nameTextBox.Text,
                   verificationCode = new Random().Next(0x100000, 0xffffff + 1).ToString("X").ToLower();

            if (!await SmtpUtility.Send(email, "Welcome",
                                        "Hello " + name + ",\n\n"
                                        + "Welcome to Chat App! Please verify your account using the following verification code.\n\n"
                                        + "Verification code: #" + verificationCode, delegate(SmtpException ex)
            {
                StopLoading();
            }))
            {
                return;
            }

            loadingPictureBox.Pause();

            EmailVerificationForm verificationForm = new EmailVerificationForm(verificationCode);

            verificationForm.ShowDialog();
            verificationForm.Dispose();
            if (verificationForm.DialogResult != DialogResult.OK)
            {
                StopLoading();
                SwitchToSignIn();
                return;
            }

            loadingPictureBox.Resume();

            if (await SqlUtility.Write("INSERT INTO [users] ([email], [name], [password]) VALUES (@email, @name, @password);",
                                       new string[] { email, name, passwordTextBox.Text }, OnException) != 1)
            {
                return;
            }

            StopLoading();
            MessageBox.Show("Sign up successful!", ChatAppForm.TITLE, MessageBoxButtons.OK, MessageBoxIcon.Information);
            SwitchToSignIn();
        }