public AccountController( ApplicationUserManager userManager, ApplicationSignInManager signInManager, IAccountService accountService, ParameterService paramService) { this.accountService = accountService; this.userManager = userManager; this.signInManager = signInManager; this.paramService = paramService; // var provider = new DpapiDataProtectionProvider("SciReview"); var provider = new MachineKeyProtectionProvider(); userManager.UserTokenProvider = new DataProtectorTokenProvider<AppMember, int>(provider.Create("ASP.NET Identity")) as IUserTokenProvider<AppMember, int>; }
public async Task<ActionResult> EditUser(UserViewModel model, int id) { if (SiteConfiguration.IsDemoMode) { DisplayMessage("You can't save changes in demo mode.", MessageType.Warning); return RedirectToAction("EditUser", new { id = id }); } if (ModelState.IsValid) { var user = adminService.GetUserById(model.UserID); if (user == null) throw new HttpException(404, "User not found."); user.CountryID = model.CountryID; user.DegreeID = model.DegreeID; user.Email = model.Email; user.FirstName = model.FirstName; user.Gender = model.Gender; user.LastName = model.LastName; user.PhoneNumber = model.PhoneNumber; user.UpdatedByUserID = CurrentUser.Id; user.UpdatedDateUtc = DateTime.UtcNow; var result = await userManager.UpdateAsync(Mapper.Map<AppMember>(user)); if(!string.IsNullOrWhiteSpace(model.NewPassword)) { var provider = new MachineKeyProtectionProvider(); userManager.UserTokenProvider = new DataProtectorTokenProvider<AppMember, int>(provider.Create("ASP.NET Identity")) as IUserTokenProvider<AppMember, int>; var resetToken = await userManager.GeneratePasswordResetTokenAsync(model.UserID); await userManager.ResetPasswordAsync(model.UserID, resetToken, model.NewPassword); } if (result.Succeeded) DisplayMessage("Se actualizó la información del usuario.", MessageType.OK); else DisplayMessage("Ha ocurrido un error.", MessageType.Error); } return RedirectToAction("EditUser", new { id = id }); }