Ejemplo n.º 1
0
        protected void Email(object sender, EventArgs e)
        {
            //http://stackoverflow.com/questions/27764692/validating-recaptcha-2-no-captcha-recaptcha-in-asp-nets-server-side
            string EncodedResponse = Request.Form["g-Recaptcha-Response"];
            bool   IsCaptchaValid  = (ReCaptchaClass.Validate(EncodedResponse) == "True" ? true : false);

            if (IsCaptchaValid)
            {
                var    fromAddress  = new MailAddress(ConfigurationManager.AppSettings["clubEmail"], "InfoSec Club");
                var    toAddress    = new MailAddress(ConfigurationManager.AppSettings["adminEmail"], "Vivi Langga");
                string fromPassword = ConfigurationManager.AppSettings["clubEmailPass"];
                string subject      = "Contacted from website";
                string body         = "From: " + txtName.Text + "\nPhone: " + txtPhone.Text + "\nEmail: " + txtEmail.Text + "\nComment: " + txtComment2.Value;

                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential(fromAddress.Address, fromPassword)
                };
                using (var message = new MailMessage(fromAddress, toAddress)
                {
                    Subject = subject,
                    Body = body
                })
                {
                    smtp.Send(message);
                }
                clearAll();
                ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Contact_Success", "alert('Your message has been sent, please expect a response within 24 hours')", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Contact_Fail", "alert('I don't allow robots to contact me')", true);
            }
        }
Ejemplo n.º 2
0
        protected void register(object sender, EventArgs e)
        {
            //http://stackoverflow.com/questions/27764692/validating-recaptcha-2-no-captcha-recaptcha-in-asp-nets-server-side
            string EncodedResponse = Request.Form["g-Recaptcha-Response"];
            bool   IsCaptchaValid  = (ReCaptchaClass.Validate(EncodedResponse) == "True" ? true : false);

            if (IsCaptchaValid)
            {
                //Valid Request

                if (tb_EMAIL.Text.Length > 9 && tb_EMAIL.Text.Substring(tb_EMAIL.Text.Length - 9).Equals("@sjsu.edu"))
                {
                    if (tb_passphrase.Text.Equals("") || tb_passphrase.Text.Equals(null))
                    {
                        ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Invalid Password", "alert('A password is required')", true);
                    }
                    else
                    {
                        string confirmationString = RandomString(50);
                        if (registerUser(confirmationString) == true)
                        {
                            sendConfirmationEmail(confirmationString);
                            ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Success", "alert('An Email has been sent to you sjsu.edu inbox. Please visit your inbox to verify your account')", true);
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Success", "alert('There is already an account under that Student ID')", true);
                        }
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "Invalid Email", "alert('You must be a student to join the club. Please provide a sjsu.edu email')", true);
                }
            }
        }