protected void ForgotPasswordLinkButton_Click(object sender, EventArgs e) { try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginRead(); Root root = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false); if (root == null) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } CustomerContact lookup = new CustomerContact(Email.Text, null); if (!root.customersByEmail.TryGetKey(lookup, ref lookup)) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } session.Commit(); MailMessage message = new MailMessage("*****@*****.**", Email.Text); message.Subject = "Your password to VelocityWeb"; message.Body = "Password is: " + lookup.password; SmtpClient client = new SmtpClient("smtpout.secureserver.net", 80); System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("*****@*****.**", "xxxx"); client.Credentials = SMTPUserInfo; client.Send(message); ErrorMessage.Text = "Email with your password was send to: " + Email.Text; } } catch (System.Exception ex) { ErrorMessage.Text = ex.ToString(); } }
protected void LoginButton_Click(object sender, EventArgs e) { if (Password.Text.Length == 0) { ErrorMessage.Text = "Enter your password."; return; } try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginUpdate(); Root velocityDbroot = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false); if (velocityDbroot == null) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } CustomerContact lookup = new CustomerContact(Email.Text, null); if (!velocityDbroot.customersByEmail.TryGetKey(lookup, ref lookup)) { ErrorMessage.Text = "The entered email address is not registered with this website"; session.Abort(); return; } if (lookup.password != Password.Text) { ErrorMessage.Text = "The entered password does not match the registered password"; session.Abort(); return; } session.Commit(); Session["UserName"] = lookup.UserName; Session["Email"] = Email.Text; Session["FirstName"] = lookup.FirstName; Session["LastName"] = lookup.LastName; FormsAuthentication.RedirectFromLoginPage(Email.Text, false); } } catch (System.Exception ex) { ErrorMessage.Text = ex.ToString() + ex.Message; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Session["EmailVerification"] = -1; Session["EmailVerificationEmail"] = "none"; Page.Header.Title = "VelocityDB - Register"; continueUrl = Request.QueryString["ReturnUrl"]; HowFoundRadioButtonList.DataSource = AllHowFound(); HowFoundRadioButtonList.SelectedIndex = 0; HowFoundRadioButtonList.DataBind(); DataCache.UnauthorizedPerformanceCounter = true; try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginUpdate(); Root velocityDbroot = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false); if (velocityDbroot == null) { Placement placementRoot = new Placement(Root.PlaceInDatabase, 1, 1, 1000, 1000, true); velocityDbroot = new Root(session, 10000); velocityDbroot.Persist(placementRoot, session); } else { string user = this.User.Identity.Name; if (user != null && user.Length > 0) { CustomerContact lookup = new CustomerContact(user, null); if (velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer)) { EmailVerificationValidator.Enabled = false; CompanyName.Text = existingCustomer.company; FirstName.Text = existingCustomer.firstName; LastName.Text = existingCustomer.lastName; Email.Text = existingCustomer.email; Address.Text = existingCustomer.address; AddressLine2.Text = existingCustomer.addressLine2; City.Text = existingCustomer.city; ZipCode.Text = existingCustomer.zipCode; State.Text = existingCustomer.state; Country.SelectedValue = existingCustomer.countryCode; Phone.Text = existingCustomer.phone; Fax.Text = existingCustomer.fax; MobilePhone.Text = existingCustomer.mobile; SkypeName.Text = existingCustomer.skypeName; Website.Text = existingCustomer.webSite; UserName.Text = existingCustomer.userName; Password.Text = existingCustomer.password; PasswordConfirm.Text = existingCustomer.password; HowFoundRadioButtonList.SelectedIndex = (int)existingCustomer.howFoundVelocityDb; HowFoundTextBox.Text = existingCustomer.howFoundOther; } else if (Request.IsLocal) EmailVerificationValidator.Enabled = false; } } session.Commit(); } } catch (System.Exception ex) { errors.Text = ex.ToString(); } } }
protected void RegisterButton_Click(object sender, EventArgs e) { try { using (SessionNoServer session = new SessionNoServer(dataPath, 2000, true, true)) { session.BeginUpdate(); CustomerContact customer = new CustomerContact(CompanyName.Text, FirstName.Text, LastName.Text, Email.Text, Address.Text, AddressLine2.Text, City.Text, ZipCode.Text, State.Text, Country.SelectedItem.Text, Country.SelectedItem.Value, Phone.Text, Fax.Text, MobilePhone.Text, SkypeName.Text, Website.Text, UserName.Text, Password.Text, HowFoundTextBox.Text, HowFoundRadioButtonList.SelectedIndex, session); Root root = (Root)session.Open(Root.PlaceInDatabase, 1, 1, false); CustomerContact lookup; string user = this.User.Identity.Name; if (user != null && user.Length > 0) { lookup = new CustomerContact(user, null); root.customersByEmail.TryGetKey(lookup, ref existingCustomer); } else { lookup = new CustomerContact(customer.email, customer.userName); if (!root.customersByEmail.TryGetKey(lookup, ref existingCustomer)) root.customersByUserName.TryGetKey(lookup, ref existingCustomer); } if (existingCustomer != null) { existingCustomer.Update(); if (existingCustomer.email != customer.email) { string verifiedEmail = (string)Session["EmailVerificationEmail"]; int emailVerification = (int)Session["EmailVerification"]; if (Request.IsLocal == false) { if (emailVerification < 0 || verifiedEmail != customer.email) { errors.Text = "Email was not verified for new user registration"; session.Abort(); return; } int enteredVerificationNumber; int.TryParse(EmailVerification.Text, out enteredVerificationNumber); if (emailVerification != enteredVerificationNumber) { errors.Text = "Entered Email Verification number is " + enteredVerificationNumber + " does match the emailed verification number: " + emailVerification; Session["EmailVerification"] = -1; session.Abort(); return; } } if (existingCustomer.password != customer.password && user != existingCustomer.email) { errors.Text = "Entered Email address already registered"; session.Abort(); return; } existingCustomer.priorVerifiedEmailSet.Add(existingCustomer.email); root.customersByEmail.Remove(existingCustomer); existingCustomer.email = customer.email; root.customersByEmail.Add(existingCustomer); } if (existingCustomer.userName != customer.userName) { lookup = new CustomerContact(user, customer.userName); if (root.customersByUserName.TryGetKey(lookup, ref lookup)) { errors.Text = "Entered User Name is already in use"; session.Abort(); return; } // remove and add to get correct sorting order root.customersByUserName.Remove(existingCustomer); existingCustomer.userName = customer.userName; root.customersByUserName.Add(existingCustomer); } existingCustomer.company = customer.company; existingCustomer.firstName = customer.firstName; existingCustomer.lastName = customer.lastName; existingCustomer.address = customer.address; existingCustomer.addressLine2 = customer.addressLine2; existingCustomer.city = customer.city; existingCustomer.zipCode = customer.zipCode; existingCustomer.state = customer.state; existingCustomer.country = Country.SelectedItem.Text; existingCustomer.countryCode = Country.SelectedItem.Value; existingCustomer.phone = customer.phone; existingCustomer.fax = customer.fax; existingCustomer.mobile = customer.mobile; existingCustomer.skypeName = customer.skypeName; existingCustomer.webSite = customer.webSite; existingCustomer.password = customer.password; existingCustomer.howFoundOther = customer.howFoundOther; existingCustomer.howFoundVelocityDb = customer.howFoundVelocityDb; } else { if (Request.IsLocal == false) { int emailVerification = (int)Session["EmailVerification"]; string verifiedEmail = (string)Session["EmailVerificationEmail"]; if (emailVerification < 0 || verifiedEmail != customer.email) { errors.Text = "Email was not verified for new user registration"; session.Abort(); return; } int enteredVerificationNumber; int.TryParse(EmailVerification.Text, out enteredVerificationNumber); if (emailVerification != enteredVerificationNumber) { errors.Text = "Entered Email Verification number is " + enteredVerificationNumber + " does match the emailed verification number: " + emailVerification; Session["EmailVerification"] = -1; session.Abort(); return; } } Placement placementCustomer = new Placement(customer.PlacementDatabaseNumber); customer.idNumber = root.NewCustomerNumber(); customer.Persist(placementCustomer, session); root.customersByEmail.Add(customer); root.customersByUserName.Add(customer); } session.Commit(); string redirectUrl = FormsAuthentication.GetRedirectUrl(Email.Text, false); try { string path; MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**"); if (existingCustomer == null) { path = HttpContext.Current.Server.MapPath("~/Save") + "/new" + DateTime.Now.Ticks + ".txt"; message.Subject = "VelocityWeb new prospect: " + customer.Email; } else { customer = existingCustomer; path = HttpContext.Current.Server.MapPath("~/Save") + "/updated" + DateTime.Now.Ticks + ".txt"; message.Subject = "VelocityWeb updated prospect: " + customer.Email; } using (System.IO.StreamWriter file = new System.IO.StreamWriter(path)) { file.Write("{0}\t", "Email"); file.Write("{0}\t", "FirstName"); file.Write("{0}\t", "LastName"); file.Write("{0}\t", "Address"); file.Write("{0}\t", "Address2"); file.Write("{0}\t", "City"); file.Write("{0}\t", "Company"); file.Write("{0}\t", "Country"); file.Write("{0}\t", "countryCode"); file.Write("{0}\t", "Fax"); file.Write("{0}\t", "HowFoundUs"); file.Write("{0}\t", "HowFoundUsOther"); file.Write("{0}\t", "Mobile"); file.Write("{0}\t", "Password"); file.Write("{0}\t", "Phone"); file.Write("{0}\t", "Skype"); file.Write("{0}\t", "State"); file.Write("{0}\t", "UserName"); file.Write("{0}\t", "WebSite"); file.WriteLine("{0}\t", "ZipCode"); file.Write("{0}\t", customer.Email); file.Write("{0}\t", customer.FirstName); file.Write("{0}\t", customer.LastName); file.Write("{0}\t", customer.Address); file.Write("{0}\t", customer.Address2); file.Write("{0}\t", customer.City); file.Write("{0}\t", customer.Company); file.Write("{0}\t", customer.Country); file.Write("{0}\t", customer.countryCode); file.Write("{0}\t", customer.Fax); file.Write("{0}\t", customer.HowFoundUs); file.Write("{0}\t", customer.HowFoundUsOther); file.Write("{0}\t", customer.Mobile); file.Write("{0}\t", customer.Password); file.Write("{0}\t", customer.Phone); file.Write("{0}\t", customer.Skype); file.Write("{0}\t", customer.State); file.Write("{0}\t", customer.UserName); file.Write("{0}\t", customer.WebSite); file.WriteLine("{0}\t", customer.ZipCode); } Session["UserName"] = customer.UserName; Session["Email"] = Email.Text; Session["FirstName"] = customer.FirstName; Session["LastName"] = customer.LastName; message.Body = path; Attachment data = new Attachment(path); message.Attachments.Add(data); SmtpClient client = new SmtpClient("smtpout.secureserver.net", 80); System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("*****@*****.**", "xxxx"); // Add credentials if the SMTP server requires them. client.Credentials = SMTPUserInfo; client.Send(message); } catch (System.Exception ex) { string errorPath = HttpContext.Current.Server.MapPath("~/Errors"); using (StreamWriter outfile = new StreamWriter(errorPath + @"\errors.txt", true)) { outfile.Write(ex.ToString()); } } if (redirectUrl == null || redirectUrl.Length == 0) Response.Redirect("~/Secure/Issues.aspx"); FormsAuthentication.RedirectFromLoginPage(Email.Text, false); } } catch (System.Exception ex) { errors.Text = ex.ToString(); } }
User lookupUser(IssueTracker issueTracker, SessionBase session) { string userEmail = this.User.Identity.Name; User user = new User(userEmail); string dataPath = HttpContext.Current.Server.MapPath("~/Database"); if (!issueTracker.UserSet.TryGetValue(user, ref user)) { CustomerContact existingCustomer = null; string firstName = null; string lastName = null; string userName = null; try { using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true)) { session2.BeginRead(); Root velocityDbroot = session2.AllObjects<Root>(false).FirstOrDefault(); CustomerContact lookup = new CustomerContact(userEmail, null); velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer); session2.Commit(); firstName = existingCustomer.FirstName; lastName = existingCustomer.LastName; userName = existingCustomer.UserName; } } catch (System.Exception ex) { this.errorLabel.Text = ex.ToString(); } user = new User(null, userEmail, firstName, lastName, userName); session.Persist(user); issueTracker.UserSet.Add(user); } return user; }
User lookupUser(IssueTracker issueTracker, SessionBase session) { string userEmail = this.User.Identity.Name; User user = new User(userEmail); if (!issueTracker.UserSet.TryGetValue(user, ref user)) { CustomerContact existingCustomer = null; string firstName = null; string lastName = null; string userName = null; try { using (SessionNoServer session2 = new SessionNoServer(dataPath, 2000, true, true)) { session2.BeginRead(); Root velocityDbroot = (Root)session2.Open(Root.PlaceInDatabase, 1, 1, false); CustomerContact lookup = new CustomerContact(userEmail, null); velocityDbroot.customersByEmail.TryGetKey(lookup, ref existingCustomer); session2.Commit(); firstName = existingCustomer.FirstName; lastName = existingCustomer.LastName; userName = existingCustomer.UserName; } } catch (System.Exception ex) { this.errorLabel.Text = ex.ToString(); } user = new User(null, userEmail, firstName, lastName, userName); Placement placer = new Placement(user.PlacementDatabaseNumber); user.Persist(placer, session, true, true); issueTracker.UserSet.Add(user); } return user; }