public void LogError(string errorMsg) { MembershipUser user = Membership.GetUser(); try { using (var context = new thescruffsterDataContext()) { Mishap m = new Mishap { Date = DateTime.Now, Error = errorMsg, UserName = user.UserName }; context.Mishaps.InsertOnSubmit(m); context.SubmitChanges(); } } catch (Exception except) { Label lblError = (Label)Login1.FindControl("lblError"); lblError.Visible = true; lblError.Text = except.Message.ToString(); return; } }
protected void CreateUser_OnClick(object sender, EventArgs e) { try { using (var dbEntities = new thescruffsterDataContext()) { //check to make sure the email address is valid var query = from row in dbEntities.SecretSantas select row; foreach (var secretsanta in query) { if (secretsanta.Email == Email.Text.ToLower().Trim()) { // if email is valid //check if brownley already registered if (UserExists(Email.Text.ToLower().Trim())) { ErrorMessage.Text = "That account already exists. Login to the right to access your secret santa account."; return; } else { //create secret santa account MembershipUser newUser = Membership.CreateUser(Email.Text.Trim(), Password.Text.Trim()); Guid uid = (Guid)newUser.ProviderUserKey; Roles.AddUserToRole(Email.Text.Trim(), "secretsanta"); secretsanta.UserID = uid; dbEntities.SubmitChanges(); if (Membership.ValidateUser(Email.Text.Trim(), Password.Text.Trim())) { //login newly created user FormsAuthentication.RedirectFromLoginPage(Email.Text.Trim(), false); } Response.Redirect("~/secretsanta/shhhh.aspx"); } } } //entered invalid email address ErrorMessage.Text = "You entered an invalid email address. Is there another email address?"; return; } } catch (MembershipCreateUserException mce) { string pwdError = mce.StatusCode.ToString(); ErrorMessage.Text = pwdError; return; } catch (Exception ex) { ErrorMessage.Text = ex.Message.ToString(); } }
protected void Page_Load(object sender, EventArgs e) { thescruffsterDataContext dbEntities = new thescruffsterDataContext(); Guid uid = SecretSantaData.GetUserID(); var ss = dbEntities.SecretSantas.SingleOrDefault(x => x.UserID == uid); if (!Page.IsPostBack) { LoginName ln = new LoginName(); //if you have an account and have chosen a brownley // display brownley along with their wishlist //if brownley is null then logging in for first time if (ss.BrownleyID != null) { historyPanel.Visible = true; DisplayAccountInfo(ss.BrownleyID, ss.Name); txtWishList.Focus(); } else { btnChoose.Text = "Spin the Brownley Wheel"; } } int month = DateTime.Today.Month; int day = DateTime.Today.Day; SetCalendar(day, month); HtmlGenericControl h = (HtmlGenericControl)vwLogin.FindControl("loginname"); h.InnerHtml = ss.Name + "!"; var brownleyRow = dbEntities.Brownleys.SingleOrDefault(x => x.Name == ss.Name); txtWishList.Text = brownleyRow.WishList; }
protected void Button1_Click(object sender, EventArgs e) { string username = txtusername.Text.Trim(); string password = Membership.GeneratePassword(6, 1); try { MembershipUser mu = Membership.GetUser(username); if (mu != null) { mu.ChangePassword(mu.ResetPassword(), password); } else { lblmessage.Text = "Username " + txtusername.Text + " could not be found"; return; } } catch (MembershipPasswordException mpe) { lblmessage.Text = mpe.Message.ToString(); return; } catch (Exception ex) { lblmessage.Text = ex.Message.ToString(); return; } lblmessage.Text = "Password successfully reset to : " + "<b>" + password + "</b>"; thescruffsterDataContext db = new thescruffsterDataContext(); var name = db.SecretSantas.SingleOrDefault(x => x.Email == username).Name.Trim().ToLower(); string nickname; switch (name) { case "tanja": nickname = "Sistah"; break; case "christoph": nickname = "Big Nasty"; break; case "jade": nickname = "Love"; break; case "shelly": nickname = "Sis in law"; break; case "delisa": nickname = "Sis in law"; break; case "adam": nickname = "Twin"; break; case "ray": nickname = "Bro in law"; break; default: nickname = name; break; } // SendEmail(username, password, nickname); }
private void SendEmail(string username, string password, string nickname) { try { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); var ssEmail = username; var ssPassword = password; System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(ssEmail); message.IsBodyHtml = true; message.To.Add(mailTo); if (!String.IsNullOrEmpty(ssEmail)) { message.Bcc.Add(new System.Net.Mail.MailAddress("*****@*****.**")); } message.Subject = "Secret Santa Password Reset"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + "<div style='width:585px;height:137px'><img src='http://www.thescruffster.com/styles/santa_logo.jpg' border='0' /></div>" + "<div style='padding:20px;border:solid 1pt #952a20'>" + "<span style='padding:10px'>Hey " + nickname + "! Your new password was reset to:</span>" + "<div style='padding:10px'>" + password + "</div>" + "<div style='padding:10px;margin-bottom:10px'><a href='http://www.thescruffster.com/secretsanta'>Brownley Secret Santa</a></div>" + "<div style='padding:10px'>Merry Christmas!<br>" + "[email protected]</div>"; mailClient.Send(message); message.Dispose(); } catch (Exception e) { thescruffsterDataContext db = new thescruffsterDataContext(); MembershipUser user = Membership.GetUser(); Mishap m = new Mishap { Date = DateTime.Now, Error = e.Message.ToString(), UserName = user.UserName }; try { db.Mishaps.InsertOnSubmit(m); db.SubmitChanges(); } catch (Exception except) { try { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); var Email = "*****@*****.**"; System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(Email); message.IsBodyHtml = true; message.To.Add(mailTo); message.Subject = "Secret Santa Password Reset Error"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + except.StackTrace + "</div>"; mailClient.Send(message); message.Dispose(); } catch (Exception ex) { } } } }
public static string AutoSave() { string _secretsanta; thescruffsterDataContext dbEntities = new thescruffsterDataContext(); try { //put the thread to sleep for 5 seconds to keep the wheel spinning Thread.Sleep(5000); //get user id of secretsanta to update with chosen brownleyID Guid uid = SecretSantaData.GetUserID(); MembershipUser user = Membership.GetUser(); string username = user.UserName; //choose from the next availailable list of names //do not choose yourself or your spouse! //add brownleyID to secretsanta tbl var secretsantaRow = dbEntities.SecretSantas.Single(x => x.Email == username); var brownleyQuery = from b in dbEntities.Brownleys where b.Name != secretsantaRow.Name where b.Name != secretsantaRow.Spouse where b.IsChosen == false select new { Bid = b.BrownleyID, Bname = b.Name, WishList = b.WishList }; string wishlist = brownleyQuery.FirstOrDefault().WishList; int ID = brownleyQuery.FirstOrDefault().Bid; string name = brownleyQuery.FirstOrDefault().Bname; var secretsanta = dbEntities.SecretSantas.SingleOrDefault(x => x.UserID == uid); secretsanta.BrownleyID = ID; var brownley = dbEntities.Brownleys.SingleOrDefault(y => y.BrownleyID == ID); brownley.IsChosen = true; dbEntities.SubmitChanges(); var secretSantaName = dbEntities.SecretSantas.Single(z => z.Name == name); _secretsanta = "<font color='red'><b>Shhhhh!</b></font> - You are <b>" + name + "</b>'s Secret Santa. <p>"; //return wishlist if one exists if (String.IsNullOrEmpty(wishlist)) { wishlist = name + " has not created a wish list yet." + " An email containing " + name + "'s list will be sent to you once submitted." + " You can also view " + name + "'s list in your account below."; } _secretsanta += "<font color='blue'>" + name + "'s Wish List</font>: " + wishlist; } catch (Exception ex) { MembershipUser user = Membership.GetUser(); try { Mishap m = new Mishap { Date = DateTime.Now, Error = ex.Message.ToString(), UserName = user.UserName }; dbEntities.Mishaps.InsertOnSubmit(m); dbEntities.SubmitChanges(); } catch (Exception except) { try { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); var Email = "*****@*****.**"; System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(Email); message.IsBodyHtml = true; message.To.Add(mailTo); message.Subject = "Secret Santa AutoSave Error"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + except.StackTrace + "</div>"; mailClient.Send(message); message.Dispose(); } catch (Exception e) { _secretsanta = "Error"; return(_secretsanta + ": " + e.Message.ToString()); } } _secretsanta = "Error"; return(_secretsanta + ": " + ex.Message.ToString()); } //return name of secret santa along with wish list return(_secretsanta); }
public static string EditWishList(string text) { try { thescruffsterDataContext dbEntities = new thescruffsterDataContext(); if (!String.IsNullOrEmpty(text)) { // this satifies GetBrownley() var uid = SecretSantaData.GetUserID(); var ss = dbEntities.SecretSantas.SingleOrDefault(x => x.UserID == uid); var brownleyRow = dbEntities.Brownleys.SingleOrDefault(x => x.Name == ss.Name); brownleyRow.WishList = text; try { brownleyRow.WishList = text; dbEntities.SubmitChanges(); text = brownleyRow.WishList; } catch (Exception dbex) { return("Error: " + dbex.Message.ToString()); } //if brownley is already chosen, find their secret santa and send an email //containing wish list if (brownleyRow.IsChosen) { var ssEmail = dbEntities.SecretSantas.SingleOrDefault(x => x.BrownleyID == brownleyRow.BrownleyID).Email; var ssName = dbEntities.SecretSantas.SingleOrDefault(x => x.BrownleyID == brownleyRow.BrownleyID).Name; System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); //send an email to secretsanta when wishlist is created or updated System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(ssEmail); message.IsBodyHtml = true; message.To.Add(mailTo); message.Bcc.Add(new System.Net.Mail.MailAddress("*****@*****.**")); message.Subject = "Secret Santa Wish List"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + "<div style='width:585px;height:137px'><img src='http://www.thescruffster.com/styles/santa_logo.jpg' border='0' /></div>" + "<div style='padding:20px;border:solid 1pt #952a20'>" + "<span style='padding:10px'>Hi " + ssName + "! " + brownleyRow.Name + " has updated their wish list:</span>" + "<div style='padding:10px'>" + brownleyRow.WishList + "</div>" + "<div style='padding:10px;margin-bottom:10px'>You can also login to your account to view: <a href='http://www.thescruffster.com/secretsanta'>Brownley Secret Santa</a></div>" + "<div style='padding:10px'>Merry Christmas!<br>" + "[email protected]</div>"; mailClient.Send(message); message.Dispose(); } } } catch (Exception ex) { MembershipUser user = Membership.GetUser(); Mishap m = new Mishap { Date = DateTime.Now, Error = ex.Message.ToString(), UserName = user.UserName }; try { using (thescruffsterDataContext db = new thescruffsterDataContext()) { db.Mishaps.InsertOnSubmit(m); db.SubmitChanges(); } } catch (Exception except) { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); var Email = "*****@*****.**"; System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(Email); message.IsBodyHtml = true; message.To.Add(mailTo); message.Subject = "Secret Santa Edit WishList Error"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + except.StackTrace + "</div>"; mailClient.Send(message); message.Dispose(); } } return(text); }
public void DisplayAccountInfo(int?ssBrownleyId, string name) { try { using (var dbEntities = new thescruffsterDataContext()) { //get name of brownley var brownley = dbEntities.Brownleys.SingleOrDefault(x => x.BrownleyID == ssBrownleyId); //get recipient wish list string b = brownley.Name; string w = brownley.WishList; if (String.IsNullOrEmpty(w)) { w = b + " has not yet submitted a wish list."; } // get your wish list var myrow = dbEntities.Brownleys.SingleOrDefault(y => y.Name == name); string mywish = myrow.WishList; if (String.IsNullOrEmpty(mywish)) { mywish = "No wish list submitted"; } //make wheel and button invisible //add secret santa account info accountpanel.Visible = true; lblMyAccount.Visible = true; mywishpanel.Visible = true; historyPanel.Visible = true; staticImg.Style.Add("visibility", "hidden"); btnChoose.Visible = false; recepientname.InnerHtml = b; recepientwishlabel.InnerHtml = b + "'s Wish List:"; recepientwishdata.InnerHtml = w; txtWishList.Text = mywish; } } catch (Exception e) { MembershipUser user = Membership.GetUser(); Mishap m = new Mishap { Date = DateTime.Now, Error = e.Message.ToString(), UserName = user.UserName }; try { using (var dbEntities = new thescruffsterDataContext()) { dbEntities.Mishaps.InsertOnSubmit(m); dbEntities.SubmitChanges(); } } catch (Exception except) { System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(); var Email = "*****@*****.**"; System.Net.Mail.MailAddress mailFrom = new System.Net.Mail.MailAddress("*****@*****.**"); System.Net.Mail.MailAddress mailTo = new System.Net.Mail.MailAddress(Email); message.IsBodyHtml = true; message.To.Add(mailTo); message.Subject = "Secret Santa Display Account Info Error"; message.From = mailFrom; message.Body = "<div style='width:585px; position:relative;height:auto;font-family:arial;font-size:12px'>" + except.StackTrace + "</div>"; mailClient.Send(message); message.Dispose(); } } }