示例#1
0
        public async Task<ActionResult> SetUserPassword(SetPasswordViewModel model)
        {
            UserManagement userMgr = new UserManagement(User.Identity.GetUserId<int>());
            try
            {
                BUser user = userMgr.GetUserInfo(model.Id);
                if (ModelState.IsValid)
                {
                    userMgr.DataProtectionProvider = Startup.DataProtectionProvider;
                    bool ret = await userMgr.SetUserPassword(model.Id, model.NewPassword);
                    //var result = await userMgr.AddPasswordAsync(User.Identity.GetUserId<int>(), model.NewPassword);
                    if (!user.IsAdmin)
                    {
                        return RedirectToAction("Agencies");
                    }
                    else
                    {
                        return RedirectToAction("Administrators");
                    }

                }
                else
                {

                    ViewBag.User = user;
                    return View(model);
                }

            }
            catch (KMBitException ex)
            {
                ViewBag.Message = ex.Message;
            }
            catch (Exception ex)
            {
            }

            return View("Error");
        }
示例#2
0
        public async Task<ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId<int>(), model.NewPassword);
                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    }
                    return RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess });
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
示例#3
0
 public ActionResult SetUserPassword(int userId)
 {
     SetPasswordViewModel model = new SetPasswordViewModel() { Id = userId };
     UserManagement userMgr = new UserManagement(User.Identity.GetUserId<int>());
     BUser user = userMgr.GetUserInfo(userId);
     if(user!=null)
     {
         ViewBag.User = user;
         return View(model);
     }else
     {
         ViewBag.Message = string.Format("编号为{0}的用户不存在",userId);
         return View("Error");
     }           
 }