Пример #1
0
        public async Task<ActionResult> ChangePassword(ManageUserViewModel model)
        {
            bool hasPassword = HasPassword();
            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl = Url.Action("Manage");
           
            
                // User does not have a password so remove any validation errors caused by a missing OldPassword field
                ModelState state = ModelState["OldPassword"];
                if (state != null)
                {
                    state.Errors.Clear();
                }

                if (ModelState.IsValid)
                {
                    var checkexist = db.Retrievepassword.Where(m => m.ConfirmationToken == model.ConfirmationToken).FirstOrDefault();
                    var userid = db.Users.Where(m => m.UserName == checkexist.Email).FirstOrDefault();
                    IdentityResult result = await UserManager.RemovePasswordAsync(userid.Id);
                    result = await UserManager.AddPasswordAsync(userid.Id,model.NewPassword);
                    if (result.Succeeded)
                    {
                        Retrievepassword Retrievepassword = db.Retrievepassword.Where(m=>m.ConfirmationToken==model.ConfirmationToken).FirstOrDefault();
                        db.Retrievepassword.Remove(Retrievepassword);
                        db.SaveChanges();
                        return RedirectToAction("Login");
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #2
0
        public async Task<ActionResult> Manage(ManageUserViewModel model)
        {
            bool hasPassword = HasPassword();
            ViewBag.HasLocalPassword = hasPassword;
            ViewBag.ReturnUrl = Url.Action("Manage");
            if (hasPassword)
            {
                if (ModelState.IsValid)
                {
                    IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
                    if (result.Succeeded)
                    {
                        return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }
            else
            {
                // User does not have a password so remove any validation errors caused by a missing OldPassword field
                ModelState state = ModelState["OldPassword"];
                if (state != null)
                {
                    state.Errors.Clear();
                }

                if (ModelState.IsValid)
                {
                    IdentityResult result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);
                    if (result.Succeeded)
                    {
                        return RedirectToAction("Manage", new { Message = ManageMessageId.SetPasswordSuccess });
                    }
                    else
                    {
                        AddErrors(result);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #3
0
 public ActionResult ChangePassword(String ID)
     {
     
     if (ID != null)
     {
         
         var result = db.Retrievepassword.Where(m => m.ConfirmationToken == ID).FirstOrDefault();
         if (result != null)
         {
             if (Request.IsAuthenticated)
             {
                 AuthenticationManager.SignOut();
             }
             ManageUserViewModel objManageUserViewModel = new ManageUserViewModel() { ConfirmationToken=ID };
             return View(objManageUserViewModel);
         }
         else 
         {
             ViewBag.expired = "Link has Expired";
               return RedirectToAction("Login","Account");
         }
     }
     {
         return RedirectToAction("Index","Home");
     }
 }