Example #1
0
        public ActionResult ForgotPassword(string email)
        {
            var userManager = HttpContext.GetOwinContext().GetUserManager <UserManager <IdentityUser> >();
            var user        = userManager.FindByEmail(email);

            if (user != null)
            {
                string resetToken = userManager.GeneratePasswordResetToken(user.Id);
                string resetUrl   = Request.Url.GetLeftPart(UriPartial.Authority) + "/Account/ResetPassword?email=" + email + "&token=" + resetToken;
                string link       = string.Format("<a href=\"{0}\">Reset your password</a>", resetUrl);
                //userManager.SendEmail(user.Id, "your password reset token", message);
                EmailMessageMaker forgotPasswordEmail = new EmailMessageMaker();
                forgotPasswordEmail.Line.Add("<h2>Thank you for contacting us!</h2>");
                forgotPasswordEmail.Line.Add("<p>To reset your password, please click on the link below.</p>");
                forgotPasswordEmail.Line.Add(link);
                forgotPasswordEmail.Line.Add("<p>Have a great day!</p>");
                PiMailer passwordReset = new PiMailer(user.Email, "Instructions to reset your BakedRaspberryPi password", forgotPasswordEmail);
                passwordReset.SendMail();
            }

            return(RedirectToAction("ForgotPasswordSent"));
        }
Example #2
0
        public ActionResult Index(Models.CheckoutDetails model, string addressId)
        {
            Guid cartID = Guid.Parse(Request.Cookies["cartID"].Value);

            model.CurrentCart = db.Carts.Find(cartID);

            string formattedCCNumber = Regex.Replace(model.CreditCardNumber, @"[^0-9]", "");

            if (ModelState.IsValid)
            {
                string trackingNumber = Guid.NewGuid().ToString().Substring(0, 8).ToUpper();

                decimal tax      = model.CurrentCart.WholePis.Sum(x => x.Price * x.Quantity) * .1025m;
                decimal subtotal = model.CurrentCart.WholePis.Sum(x => x.Price * x.Quantity);
                decimal shipping = model.CurrentCart.WholePis.Sum(x => x.Quantity);
                decimal total    = subtotal + tax + shipping;

                BakedPiPaymentServices payments = new BakedPiPaymentServices();
                string email = User.Identity.IsAuthenticated ? User.Identity.Name : model.ContactEmail;
                Result <Transaction> authorizeReply = payments.AuthorizeCard(email, total, tax, trackingNumber, addressId, model.CardholderName, model.CVV, formattedCCNumber, model.ExpirationMonth, model.ExpirationYear);

                if (string.IsNullOrEmpty(authorizeReply.Message))
                {
                    Order order = new Order
                    {
                        TrackingNumber      = trackingNumber,
                        MaskedCC            = authorizeReply.Target.CreditCard.MaskedNumber,
                        CCImage             = authorizeReply.Target.CreditCard.ImageUrl,
                        CCType              = authorizeReply.Target.CreditCard.CardType.ToString().ToUpper(),
                        Email               = model.ContactEmail,
                        PurchaserName       = model.ContactName,
                        ShippingAddress1    = model.ShippingAddress,
                        ShippingCity        = model.ShippingCity,
                        ShippingState       = model.ShippingState,
                        ShippingPostalCode  = model.ShippingPostalCode,
                        SubTotal            = model.CurrentCart.WholePis.Sum(x => x.Price * x.Quantity),
                        ShippingAndHandling = (model.CurrentCart.WholePis.Sum(x => x.Quantity) * 1.5m),
                        Tax              = model.CurrentCart.WholePis.Sum(x => x.Price * x.Quantity) * .1025m,
                        DateCreated      = DateTime.UtcNow,
                        DateLastModified = DateTime.UtcNow
                    };

                    db.Orders.Add(order);

                    db.SaveChanges();

                    EmailMessageMaker receiptMailMessage = new EmailMessageMaker();
                    receiptMailMessage.Line.Add("<h2>The Pi is now being baked...</h2>");
                    receiptMailMessage.Line.Add("<h4>Thank you for your Order!</h4>");
                    receiptMailMessage.Line.Add("Order# " + order.TrackingNumber);
                    receiptMailMessage.Line.Add("<h2>Shipping To:</h2>");
                    receiptMailMessage.Line.Add(order.PurchaserName);
                    receiptMailMessage.Line.Add(order.ShippingAddress1);
                    receiptMailMessage.Line.Add(order.ShippingCity + ", " + order.ShippingState + " " + order.ShippingPostalCode);
                    receiptMailMessage.Line.Add("<br /><br />");
                    receiptMailMessage.Line.Add("Total: " + (order.SubTotal + order.ShippingAndHandling + order.Tax).ToString("C"));
                    receiptMailMessage.Line.Add("<br />Paid by: " + order.CCType + " " + order.MaskedCC);
                    receiptMailMessage.Line.Add("<br />");
                    receiptMailMessage.Line.Add("Thanks again for shopping with us today! Enjoy your Pi!");
                    string receiptSubject   = "Thank you for your order! (Order: " + order.TrackingNumber + ")";
                    string receiptRecipient = order.Email;

                    //Mail the Receipt
                    PiMailer receiptMail = new PiMailer(receiptRecipient, receiptSubject, receiptMailMessage);
                    receiptMail.SendMail();

                    //Reset the cart - Trash the cookie, so they'll get a new cart next time they need one
                    Response.SetCookie(new System.Web.HttpCookie("cartID")
                    {
                        Expires = DateTime.UtcNow
                    });
                    //If you have a cart table, you can clear this cart out since it has now been converted to an order
                    db.WholePis.RemoveRange(model.CurrentCart.WholePis);
                    db.Carts.Remove(model.CurrentCart);
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Receipt", new { id = trackingNumber }));
                }

                ModelState.AddModelError("CreditCardNumber", authorizeReply.Message);
            }
            return(View(model));
        }