public ActionResult ChangeForgotten(string code, ForgotPasswordModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var dal    = GetDAL <UsersLayer>();
             var crypto = new AESCypto();
             var codes  = crypto.DecryptText(code).Split(',');
             if (codes[0] == "aes")
             {
                 int userId      = int.Parse(codes[1]);
                 var email       = dal.GetEmail(userId);
                 var oldPassword = dal.GetOldPassword(userId);
                 var newPassword = GetMD5(model.NewPassword);
                 dal.ChangeMyPassword(email, oldPassword, newPassword);
                 TempData["message"] = "Password change successful";
                 return(RedirectToAction("Index"));
             }
         }
         else
         {
             ViewBag.IsReady = "1";
         }
     }
     catch (Exception)
     { }
     return(View(model));
 }
        public ActionResult ChangeForgotten(string code)
        {
            try
            {
                var crypto = new AESCypto();
                var codes  = crypto.DecryptText(code).Split(',');
                if (codes[0] == "aes" && DateTime.Parse(codes[2]) > DateTime.Now.AddDays(-1))
                {
                    ViewBag.IsReady = "1";
                }
            }
            catch (Exception)
            { }

            return(View(new ForgotPasswordModel()));
        }
        public ActionResult SendPasswordMail(EmailModel model)
        {
            var userEmail = model.Email;
            var dal       = GetDAL <UsersLayer>();
            var crypto    = new AESCypto();
            var userId    = dal.GetUserId(userEmail);
            var user      = dal.GetEditData(userId);
            var code      = crypto.EncryptText(string.Format("aes,{0},{1:yyyy-MM-dd HH:mm:ss}", userId, DateTime.Now));
            var link      = Url.Action("ChangeForgotten", "Home", new { code }, Request.Url.Scheme);

            if (userId > 0)
            {
                SmtpClient  smtp    = new SmtpClient();
                MailMessage message = new MailMessage();
                message.IsBodyHtml = true;
                message.Subject    = "Reset Password";
                message.To.Add(new MailAddress(user.Email));
                message.Body = string.Format(@"
<html>
<head>
    <title></title>
</head>
<body>
<div>
Dear {0}, {1},
</div>
<div>
Please use the following link to reset your password <br /> <br />
<a href=""{2}"">{2}</a>
</div>
</body>
</html>
                ", user.LastName, user.FirstName, link);
                smtp.Send(message);

                return(CamelJson(new { success = 1 }));
            }

            return(CamelJson(new { success = 0 }));
        }