public ActionResult ForgotPW(string email)
        {
            var user = db.TbUsers.Where(x => x.Email == email).SingleOrDefault();

            if (user == null)
            {
                return(Json("The email you entered is not correct"));
            }


            Random rdom  = new Random();
            var    xPass = rdom.Next(100000, 1000000).ToString();

            ///string newPass = xPass.ToString("000000");

            user.Password   = MySecurity.EncryptPassword(xPass);
            user.StatusId   = 1;
            user.CountLogin = 0;
            user.TimeLock   = null;
            db.SaveChanges();

            EmailManagement.SendMail(user.Email, "Aptech Shose Shop",
                                     "<h1>Hello [Name]! Your new password is [newPass]</h1>"
                                     .Replace("[Name]", user.FullName)
                                     .Replace("[newPass]", xPass));

            return(Json("Please check your email for the password"));
        }
Пример #2
0
        public ActionResult Register(TbUser user)
        {
            var emailUser = db.TbUsers.Where(x => x.Email == user.Email).SingleOrDefault();

            if (emailUser != null)
            {
                ModelState.AddModelError("", "Email này đã tồn tại");
                return(View());
            }

            TbUser newUser = new TbUser()
            {
                FullName    = user.FullName,
                Email       = user.Email,
                Password    = MySecurity.EncryptPassword(user.Password),
                StatusId    = 1,
                CreatedDate = DateTime.Now
            };

            db.TbUsers.Add(newUser);
            db.SaveChanges();
            Authen(newUser.Id);


            //sendmail
            EmailManagement.SendMail(user.Email, "Chuc mung dang ky thanh cong", "<h1>Hello [Name], ban da dag ky</h1>".Replace("[Name]", newUser.FullName));
            return(RedirectToAction("Index", "Home"));
            ///return Redirect(Request.UrlReferrer.ToString());
        }
        public Usuario SendEmailNewPassword(string userName, string urlDomain)
        {
            try
            {
                UsuarioBS usuarioBS = new UsuarioBS();
                Usuario   usuario   = usuarioBS.GetByUserName(userName);
                Guid      token     = Guid.NewGuid();

                RecuperarSenha recuperarSenha = new RecuperarSenha
                {
                    ID_USUARIO     = usuario.ID_USUARIO,
                    PRIVATE_TOKEN  = token.ToString(),
                    ALTERADO_SENHA = false,
                };

                _dbRecuperarSenha.Add(recuperarSenha);

                StringBuilder body = new StringBuilder();



                body.AppendLine($"<p>Olá { usuario.NOME_USUARIO }</p>");
                body.AppendLine($"<p>Acesse o link abaixo ou copie e cole esse url no navegador {urlDomain}/AlterarSenha/?token={token} </p>");
                body.AppendLine($"<a href=\"{urlDomain}/AlterarSenha/?token={token}\" >Alterar Senha</a>");
                body.AppendLine("");

                EmailManagement.Send("*****@*****.**", usuario.EMAIL_USUARIO, "Reupera senha | KIS", body.ToString());

                return(usuario);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public ActionResult Register(TbUser user)
        {
            var emailUser = db.TbUsers.Where(x => x.Email == user.Email).SingleOrDefault();

            if (emailUser != null)
            {
                return(Json("This email already exists"));
            }

            if (user.Password == null)
            {
                return(Json("Your email is valid!"));
            }

            TbUser newUser = new TbUser()
            {
                FullName    = user.FullName,
                Email       = user.Email,
                Password    = MySecurity.EncryptPassword(user.Password),
                StatusId    = 1,
                CreatedDate = DateTime.Now,
                CountLogin  = 0
            };

            db.TbUsers.Add(newUser);
            db.SaveChanges();
            Authen(newUser.Id);

            //sendmail
            EmailManagement.SendMail(user.Email, "Aptech Shose Shop",
                                     "<h1>Hello [Name]! You have successfully registered an account at Aptech Shose Shop</h1>".Replace("[Name]", newUser.FullName));
            return(RedirectToAction("Index", "Home"));
        }
Пример #5
0
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     if (emailid != 0)
     {
         EmailManagement emallManagement = new EmailManagement(UserId, EmailId: emailid);
         Email           email           = emallManagement.GetEmail();
         FNameTb.Text         = email.F_Name;
         LNameTb.Text         = email.L_Name;
         EMailtb.Text         = email.Email_Add;
         DeleteBtn.Visibility = Visibility.Visible;
     }
 }
Пример #6
0
 public override void Execute()
 {
     try
     {
         hexCode = GenerateCode(6);
         EmailManagement emailService = new EmailManagement();
         emailService.SendVerificationCode(employee, hexCode);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #7
0
        private void TryLogin()
        {
            if (attemptsLeft < 1)
            {
                return;
            }

            // Do not count a log-in attempt if the user does not enter a username/password.
            if (txtLogUser.Text == "" || pswLogPassword.Password == "")
            {
            }

            if (IsLoginDataCorrect(txtLogUser.Text, pswLogPassword.Password))
            {
                if (!DBMethods.LogRegRequests.DoesUse2FA(txtLogUser.Text, ref email))
                {
                    FinishLoggingIn();
                }
                else
                {
                    grd2FA.Visibility          = Visibility.Visible;
                    grdLog.HorizontalAlignment = HorizontalAlignment.Left;
                    grdLog.Margin            = new Thickness(100, 0, 0, 0);
                    lblOutput.Foreground     = new SolidColorBrush(Color.FromRgb(241, 241, 241));
                    lblOutput.Content        = "Name/Password correct!\nPlease enter the authentication key\nwhich has just been emailed to you.";
                    pswLogPassword.IsEnabled = false;
                    txtLogUser.IsEnabled     = false;
                    btnLogIn.Content         = "Resend code";
                    btnLogIn.Click          -= BtnLogIn_Click;
                    btnLogIn.Click          += ResendCode_Click;
                    authKey = EmailManagement.Send2FAEmail(email);
                }
            }
            else
            {
                if (attemptsLeft < 2)
                {
                    txtLogUser.IsEnabled     = false;
                    txtLogUser.Text          = "";
                    pswLogPassword.IsEnabled = false;
                    pswLogPassword.Password  = "";
                    lblOutput.Content        = "You have been locked out from logging in.";
                    btnLogIn.IsEnabled       = false;
                    return;
                }

                attemptsLeft--;
                lblOutput.Content = "Incorrect username/password!\nYou have " + attemptsLeft + " attempts left.";
            }
        }
Пример #8
0
        public static void CreateStaffAccount(string staffName, string staffPassword, string staffEmail, string staffPhoneNo, bool uses2FA)
        {
            string strUses2FA;

            if (uses2FA)
            {
                strUses2FA = "1";
            }
            else
            {
                strUses2FA = "0";
            }
            string salt = EmailManagement.GenerateRandomKey(32);
            string hash = GetSecureHash(staffPassword, salt);

            DBAccess.ExecuteNonQuery($"INSERT INTO [Staff] VALUES ((SELECT Max([Staff ID]) FROM [Staff]) + 1, '{staffName}', '{hash}', '{salt}', '{staffEmail}', '{staffPhoneNo}', {strUses2FA});");
        }
Пример #9
0
        private void DeleteBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to delete the email address?", "Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                EmailManagement emailManagement = new EmailManagement(UserId, EmailId: emailid);
                emailManagement.Delete();
                Window home      = Window.GetWindow(this);
                Frame  MainFrame = FindChild <Frame>(home, "MainFrame");
                MainFrame.Navigate(new EmailsPage()
                {
                    UserId = UserId
                });
            }
            else
            {
            }
        }
Пример #10
0
        private void AddCampBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Random rand = new Random();

            if (emailid == 0)
            {
                emailid = rand.Next(100, 999);
            }
            EmailManagement emailManagement = new EmailManagement(UserId, emailid, 0, FNameTb.Text, LNameTb.Text, EMailtb.Text);

            emailManagement.ProecessSuccess += Success;
            emailManagement.ProcessFail     += Failed;
            if (AddListBtn.DisplayText != "Update")
            {
                emailManagement.Add();
            }
            else
            {
                emailManagement.Update();
            }
        }
Пример #11
0
 async void PopulateEmailLists(int UserId)
 {
     EmailManagement emailManagement = new EmailManagement(UserId);
     await Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => dgv.ItemsSource = emailManagement.GetAllEmails()));
 }
Пример #12
0
 private void BtnEmail_Click(object sender, RoutedEventArgs e)
 {
     EmailManagement.SendInvoiceEmail("*****@*****.**", table, columns, contactData);
 }
Пример #13
0
 private void BtnEmail_Click(object sender, RoutedEventArgs e)
 {
     EmailManagement.SendDataEmail("*****@*****.**", filterableDataGrid.GetDataTable(), columns.Select(c => c.Name).ToArray());
 }
Пример #14
0
        public ActionResult Checkout(string data,
                                     string CustomerName, string CustomerEmail,
                                     string CustomerAddress,
                                     string CustomerPhone, string OrderNote
                                     )
        {
            if (CustomerName == "" || CustomerEmail == "" || CustomerPhone == "" || CustomerAddress == "")
            {
                return(Content("Kiểm tra lại thông tin"));
            }

            var cart_items = JsonConvert.DeserializeObject <List <CartItem> >(data);

            if (cart_items == null || cart_items.Count == 0)
            {
                return(Content("Ko có sp trong giỏ hàng"));
            }

            int?userName = null;

            if (User.Identity.IsAuthenticated)
            {
                userName = int.Parse(User.Identity.Name);
            }

            Order orders = new Order()
            {
                CustomerName    = CustomerName,
                CustomerEmail   = CustomerEmail,
                CustomerAddress = CustomerAddress,
                CustomerPhone   = CustomerPhone,
                OrderDate       = DateTime.Now,
                OrderNote       = OrderNote,
                UserId          = userName != null ? userName : userName,
                StatusId        = 1
            };

            db.Orders.Add(orders);

            string emailOrderDetail = string.Empty;
            double subTotal         = 0;

            foreach (var item in cart_items)
            {
                Product     p  = db.Products.Find(item.productid);
                OrderDetail od = new OrderDetail()
                {
                    OrderId       = orders.Id,
                    ProductId     = item.productid,
                    UnitPrice     = p.UnitPrice,
                    DiscountRatio = p.DiscountRatio,
                    Quantity      = item.quantity,
                    ColorName     = item.ColorName,
                    SizeName      = item.SizeName
                };
                db.OrderDetails.Add(od);

                string priceInEmail = (p.UnitPrice - ((p.UnitPrice * p.DiscountRatio) / 100)).ToString();
                string quanInEmail  = item.quantity.ToString();
                subTotal         += (p.UnitPrice - ((p.UnitPrice * p.DiscountRatio.Value) / 100)) * item.quantity;
                emailOrderDetail += "<tr>" +
                                    "<td width='80%' class='purchase_item'><span class='f-fallback'>{" + od.Product.ProductName + "}</span></td>" +
                                    "<td class='align-right' width='20%' class='purchase_item'><span class='f-fallback'>" + quanInEmail + " x $" + priceInEmail + "</span></td>" +
                                    "</tr>";
            }
            db.SaveChanges();
            subTotal *= 1.1;

            //Send mail
            string CreateBody()
            {
                string body = string.Empty;

                using (StreamReader reader = new StreamReader(Server.MapPath("~/Views/Checkout/Receipt.html")))
                {
                    body = reader.ReadToEnd();
                }
                body = body.Replace("{ purchase_date }", DateTime.Now.ToString("yyyy-MM-dd"));
                body = body.Replace("{name}", CustomerName);
                body = body.Replace("{receipt_id}", orders.Id.ToString());
                body = body.Replace("{OrderDate}", DateTime.Now.ToString());
                body = body.Replace("{receipt_details}", emailOrderDetail);
                body = body.Replace("{total}", subTotal.ToString());

                return(body);
            }

            EmailManagement.SendMail(CustomerEmail, "Aptech Shose Shop", CreateBody());

            return(Content("OK"));
        }
Пример #15
0
 private void ResendCode_Click(object sender, RoutedEventArgs e)
 {
     authKey = EmailManagement.Send2FAEmail(email);
 }