protected void btnLogin_Click(object sender, System.EventArgs e) { string email = ((TextBox)FindControl("logEmail")).Text; string pword = ((TextBox)FindControl("logPassword")).Text; User u = QueryClass.GetUser(email, pword); if (u.ID != 0) { //User logged in Session.Add("user", u); Response.Redirect("Main"); } else { ((Label)FindControl("errorMessage")).Visible = true; } }
protected void btnRegister_Click(object sender, System.EventArgs e) { if (IsValid) { string email = ((TextBox)FindControl("regEmail1")).Text; string pword = ((TextBox)FindControl("regPassword1")).Text; bool isAdmin = ((CheckBox)FindControl("chkAdmin")).Checked; User u = QueryClass.GetUser(email, pword); //If email already exists make error message visible if (u.Email != null) { ((Label)FindControl("errorMessage2")).Visible = true; } // Create new user with informtaion provided else { u.Email = email; u.Password = pword; u.IsAdmin = isAdmin; Session.Add("tempUser", u); Response.Redirect("Registration"); } } }
protected void btnContinue_Click(object sender, EventArgs e) { User u = QueryClass.GetUser(txtForgottenEmail.Text); //Check if the user email they entered exists if (u.Email != null) { //Hide error message lblEmailMessage.Visible = false; // Author: // URL: https://stackoverflow.com/questions/4559011/sending-asp-net-email-through-gmail/4559071 // Date Used: 06/06/19 // Website Name: Stackover Flow forms // Use: To send an email form gmail rather than using papercut //--------------------------------------------------------------------------- //Accessing gmail account to send email SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "bhpassword"); client.UseDefaultCredentials = false; client.Credentials = credentials; //------------------------------------------------------------------------------ //Add email content including from, to, subject and body MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**"); msg.To.Add(new MailAddress(txtForgottenEmail.Text)); msg.Subject = "Bobblehead - Account Password Retrieval"; //If html does not exist return non-html email msg.Body = GetForgotPasswordMessage(false, u.Password); //create an alternate HTML view that includes images and formatting string html = GetForgotPasswordMessage(true, u.Password); AlternateView view = AlternateView .CreateAlternateViewFromString( html, null, "text/html"); //Adding an image to the email string imgPath = Server.MapPath("../img/bobblebuttlogo.png"); LinkedResource img = new LinkedResource(imgPath); img.ContentId = "logoImage"; view.LinkedResources.Add(img); //add the HTML view to the message and send msg.AlternateViews.Add(view); try { client.Send(msg); //Send to main page with pop message about sent email Response.Redirect("Main?forgotEmail="); } catch { //Display error message for email failing to send lblEmailMessage.Text = "Error sending email"; lblEmailMessage.Visible = true; } } //Reveal error message if no email matches ones registered with bobblebutt else { lblEmailMessage.Text = "This email is not registered at Bobblehead"; lblEmailMessage.Visible = true; } }