Beispiel #1
0
        public IActionResult ResetPossword()
        {
            string ForgotEmail = HttpContext.Request.Form["ForgotPasswordEmail"];

            string[] ValidationInputs = { ForgotEmail };
            if (!functions.ValidateInputs(ValidationInputs))
            {
                TempData["ErrorMessage"] = "Validation error. Email required.";

                return(RedirectToAction("Index", "SignIn"));
            }

            if (!_context.Accounts.Any(s => s.Email == ForgotEmail))
            {
                TempData["ErrorMessage"] = "The email provided does not exist in our records.";

                return(RedirectToAction("Index", "SignIn"));
            }

            string AccountID = _context.Accounts.Where(s => s.Email == ForgotEmail).FirstOrDefault().AccountID;

            try
            {
                //remove other user reset data if exists
                functions.DeleteTableData("PasswordForgot", "AccountID", AccountID, _systemConfiguration.connectionString);

                //add reset data
                string ResetID = functions.RandomString(120);
                functions.AddForgotPassword(ResetID, AccountID);

                //send user email
                //set email data
                string   ToName            = functions.GetAccountData(AccountID, "FullName");
                string[] MessageParagraphs = { "Hello, ", "We've received a request to reset the password for your account. No changes have been made to your account yet. You can reset your password by clicking the link below: ", "If you did not request a new password, please let us know immediately by replying to this email." };
                string   PreHeader         = "Account password reset link notification.";
                bool     Button            = true;
                int      ButtonPosition    = 2;
                string   ButtonLink        = functions.GetSiteLookupData("AppDomain") + "/PasswordReset/?id=" + ResetID;
                string   ButtonLinkText    = "Reset Password";
                string   Closure           = _systemConfiguration.emailClosure;
                string   Company           = _systemConfiguration.emailCompany;
                string   UnsubscribeLink   = _systemConfiguration.emailUnsubscribeLink;
                string   MessageBody       = EmailFormating.FormatEmail(MessageParagraphs, PreHeader, Button, ButtonPosition, ButtonLink, ButtonLinkText, Closure, Company, UnsubscribeLink);

                string FromEmail = _systemConfiguration.smtpEmail;
                string ToEmail   = ForgotEmail;
                string Subject   = "Password Reset Email";

                //Get smtp details
                string smtpEmail   = _systemConfiguration.smtpEmail;
                string smtpPass    = _systemConfiguration.smtpPass;
                string displayName = _systemConfiguration.emailDisplayName;
                string smtpHost    = _systemConfiguration.smtpHost;
                int    smtpPort    = _systemConfiguration.smtpPort;

                EmailService.SendEmail(FromEmail, ToEmail, Subject, MessageBody, smtpEmail, smtpPass, displayName, smtpHost, smtpPort);


                TempData["SuccessMessage"] = @"The email with further instructions was sent to the submitted email address. If you don’t receive a message in 5 minutes, " +
                                             "check the junk folder. If you are still experiencing any problems, contact support at " + functions.GetSiteLookupData("SupportEmail");

                //log activity
                if (_systemConfiguration.logActivity)
                {
                    string LogAction = $@"User '{ToName}' did password reset.";
                    functions.LogActivity(ToEmail, ToEmail, "PasswordReset", LogAction);
                }

                return(RedirectToAction("Index", "SignIn"));
            }
            catch (Exception ex)
            {
                //Log Error
                _logger.LogInformation("Password Reset Error: " + ex.ToString());
                TempData["ErrorMessage"] = "There was an error processing your request. Please try again. If this error persists, please send an email to the administrator.";
                return(RedirectToAction("Index", "SignIn"));
            }
        }
        public async Task <IActionResult> NewPost(ProductsModel productsModel)
        {
            string AccountID = _sessionManager.LoginAccountId;

            //Set ViewBags data for form return data
            ViewBag.CurrencyList = functions.GetCurrencyList();
            ViewBag.CategoryList = functions.GetCategoryList();
            ViewBag.StoresList   = functions.GetStoresList(_sessionManager.LoginAccountId);

            if (ModelState.IsValid)
            {
                try
                {
                    //Set other product data
                    productsModel.ProductID         = functions.GetUinqueId();
                    productsModel.AccountID         = _sessionManager.LoginAccountId;
                    productsModel.UniqueProductName = functions.GenerateUniqueProductName(productsModel.ProductName);
                    productsModel.FeaturedPost      = (string.IsNullOrEmpty(HttpContext.Request.Form["FeaturedPost"])) ? 0 : functions.Int32Parse(HttpContext.Request.Form["FeaturedPost"]);
                    productsModel.ApproveStatus     = _systemConfiguration.defaultProductApproveStatus;
                    productsModel.UpdatedBy         = _sessionManager.LoginUsername;
                    productsModel.UpdateDate        = DateTime.Now;
                    productsModel.DateAdded         = DateTime.Now;


                    if (!string.IsNullOrEmpty(HttpContext.Request.Form["EditPost"]) && HttpContext.Request.Form["EditPost"] == "True")
                    {
                        //update post
                        productsModel.ID        = functions.Int32Parse(HttpContext.Request.Form["ID"]);
                        productsModel.ProductID = HttpContext.Request.Form["ProductID"];

                        _context.Update(productsModel);
                        await _context.SaveChangesAsync();

                        //remove current post images
                        functions.DeleteProductImages(AccountID, productsModel.ProductID);
                        functions.DeleteTableData("ProductImages", "ProductID", productsModel.ProductID, _systemConfiguration.connectionString);
                    }
                    else
                    {
                        //add post
                        _context.Add(productsModel);
                        await _context.SaveChangesAsync();

                        //add product stock
                        functions.AddTableData("ProductStock", "ProductID", _systemConfiguration.defaultProductStock.ToString(), _systemConfiguration.connectionString);
                    }


                    //Image watermark from config file
                    string TextWaterMark  = _systemConfiguration.textWaterMark;
                    string ImageWaterMark = _systemConfiguration.imageWatermark;
                    int    ImageHeight    = _systemConfiguration.uploadImageDefaultHeight;
                    int    ImageWidth     = _systemConfiguration.uploadImageDefaultWidth;

                    //Get account directory name
                    var DirectoryName = functions.GetAccountData(_sessionManager.LoginAccountId, "DirectoryName");
                    var SavePath      = @"wwwroot\\files\\" + DirectoryName + "\\products";

                    int TotalUploads = 0;
                    //Loop through files and upload
                    foreach (var file in Request.Form.Files)
                    {
                        if (file.Length > 0)
                        {
                            using (var stream = file.OpenReadStream())
                            {
                                using (var img = Image.FromStream(stream))
                                {
                                    string NewFileName = functions.RandomString(4) + "-" + file.FileName;
                                    if (!string.IsNullOrEmpty(ImageWaterMark))
                                    {
                                        img.ScaleAndCrop(ImageWidth, ImageHeight)
                                        .AddImageWatermark(@"wwwroot\files\images\" + ImageWaterMark)
                                        .AddTextWatermark(TextWaterMark)
                                        .SaveAs(SavePath + "\\" + NewFileName);
                                    }
                                    else
                                    {
                                        try
                                        {
                                            img.ScaleAndCrop(ImageWidth, ImageHeight)
                                            .AddTextWatermark(TextWaterMark)
                                            .SaveAs(SavePath + "\\" + NewFileName);
                                        }
                                        catch (Exception)
                                        {
                                            //exclude watermark
                                            img.ScaleAndCrop(ImageWidth, ImageHeight)
                                            .SaveAs(SavePath + "\\" + NewFileName);
                                        }
                                    }

                                    //Add image to ProductImages table
                                    functions.AddProductImages(productsModel.ProductID, NewFileName, null);
                                    TotalUploads++;
                                }
                            }
                        }
                    }

                    //Add product video (if added)
                    var ProductVideo = Request.Form["ProductVideo"];
                    if (!string.IsNullOrEmpty(ProductVideo.ToString()))
                    {
                        string NewFileName = functions.RandomString(4) + "-" + ProductVideo;

                        //Add to ProductVideo table
                        functions.AddProductVideo(productsModel.ProductID, NewFileName, null);
                    }

                    TempData["SuccessMessage"] = @$ "Product added successfully.  {TotalUploads} images uploaded. 
                        <br/> Add product details here: <a href='/Account/AddProductColors/{productsModel.ProductID}' class='mr-2'>Product Colors</a>
                        <a href='/Account/AddProductSizes/{productsModel.ProductID}'>Product Sizes</a>";

                    return(RedirectToAction("ManagePosts", "Account"));
                }