Beispiel #1
0
 public async Task<ActionResult> ForgotPasswd(ForgotPasswdViewModel tblViewModel)
 {
     TBL_WEBUSERS tbl = await db.TBL_WEBUSERS.FirstOrDefaultAsync(m => (m.USERNAME.Equals(tblViewModel.Username) && m.EMAIL.Equals(tblViewModel.Email)));
     if (!(tbl == null))
     {
         tbl.SHA_PASSWORD = Yfunction.generateRandomString(12, "ITDept6953069");
         tbl.PASSWORD = string.Empty;
         db.Entry(tbl).State = EntityState.Modified;
         await db.SaveChangesAsync();
         //send email
         string _bod = string.Format("Dear Sir/Madam {0}, <BR/><BR/> Your password has changed. <BR/> Please login using the following credentials. <br/><br/>Username: {3} <br/>Password: {4} <br/><br/> Kindly replace your temporary password as soon as you login. <br/>Thank you!", tbl.FIRSTNAME + " " + tbl.LASTNAME, tbl.USERNAME, tbl.SHA_PASSWORD, tbl.USERNAME, tbl.SHA_PASSWORD);
         sendEmail("RCTPL Account Settings Change", "Password Change Confirmation", _bod, tbl.EMAIL);
         //view password change successful
         ViewBag.Status = 1;
         ViewBag.Title = "Your Password has changed";
         ViewBag.Message = "Kindly check your email for new Password. Thank you!";
         return View();
         //return RedirectToAction("", "");
     }
     ViewBag.Status = 2;
     ViewBag.Title = "Warning!";
     ViewBag.Message = "Invalid Credentials";
     return View();
 }
Beispiel #2
0
        public async Task<ActionResult> ForgotPassword(ForgotPasswdViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(model.Email);
                if (user == null || !(await UserManager.IsEmailConfirmedAsync(user.Id)))
                {
                    ModelState.AddModelError("", "The user either does not exist or is not confirmed.");
                    return View();
                }

                // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                // Send an email with this link
                // string code = await UserManager.GeneratePasswordResetTokenAsync(user.Id);
                // var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);		
                // await UserManager.SendEmailAsync(user.Id, "Reset Password", "Please reset your password by clicking <a href=\"" + callbackUrl + "\">here</a>");
                // return RedirectToAction("ForgotPasswordConfirmation", "Account");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }