本文整理汇总了C#中ApplicationUserManager.AddPasswordAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUserManager.AddPasswordAsync方法的具体用法?C# ApplicationUserManager.AddPasswordAsync怎么用?C# ApplicationUserManager.AddPasswordAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationUserManager
的用法示例。
在下文中一共展示了ApplicationUserManager.AddPasswordAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Edit
public async Task<ActionResult> Edit(UserDetailsViewModel model)
{
if (ModelState.IsValid)
{
using (var db = new ApplicationDbContext())
{
MyUser user = db.Users.Find(model.UserId);
user.Id = model.UserId;
user.UserName = model.UserName;
user.Email = model.EmailAddress;
user.EmailConfirmed = model.EmailAddressConfirmed;
user.AccessFailedCount = model.AccessFailedCount;
user.LockoutEnabled = model.LockoutEnabled;
user.LockoutEndDateUtc = model.LockoutEndDate;
user.UserDetails.FirstName = model.FirstName;
user.UserDetails.LastName = model.LastName;
user.UserDetails.Age = model.Age;
user.UserDetails.Address = model.Address;
user.UserDetails.City = model.City;
user.UserDetails.Country = model.Country;
MyUserRole currentRole = db.Users.FirstOrDefault(m => m.Id == model.UserId)
.Roles.FirstOrDefault();
db.Users.FirstOrDefault(m => m.Id == model.UserId)
.Roles.Remove(currentRole);
db.Users.FirstOrDefault(m => m.Id == model.UserId)
.Roles.Add(new MyUserRole { RoleId = int.Parse(model.Role), UserId = model.UserId });
db.Entry(user).State = EntityState.Modified;
await db.SaveChangesAsync();
ApplicationUserManager userManager = new ApplicationUserManager(new MyUserStore(new ApplicationDbContext()));
// Dodati da se novi password salje ;)
await userManager.RemovePasswordAsync(model.UserId);
await userManager.AddPasswordAsync(model.UserId, model.Password);
}
return RedirectToAction("Index", new { Message = UserMessageId.ChangeUser });
}
ViewBag.Roles = new SelectList(db.Roles.AsEnumerable().ToList(),
"Id", "Name", db.Roles.FirstOrDefault(m => m.Id.ToString() == model.Role));
ViewBag.Id = new SelectList(db.UserDetails, "Id", "Role", model.Role);
return View(model);
}
示例2: SetPassword
public async Task<IHttpActionResult> SetPassword(SetPasswordBindingModel model)
{
if (!ModelState.IsValid)
return BadRequest(ModelState);
var manager = new ApplicationUserManager(new MySqlUserStore<ApplicationUser>());
IdentityResult result = await manager.AddPasswordAsync(User.Identity.GetUserId(), model.NewPassword);
if (!result.Succeeded)
return GetErrorResult(result);
return Ok();
}