本文整理汇总了C#中UserStore.UpdateAsync方法的典型用法代码示例。如果您正苦于以下问题:C# UserStore.UpdateAsync方法的具体用法?C# UserStore.UpdateAsync怎么用?C# UserStore.UpdateAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserStore
的用法示例。
在下文中一共展示了UserStore.UpdateAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAsync_GivenAnUpdate_UpdatesTheUser
public async void UpdateAsync_GivenAnUpdate_UpdatesTheUser()
{
var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
var userStore = new UserStore<User>(applicationDatabaseConfiguration);
var user = new User
{
Email = "[email protected]",
IsEmailConfirmed = true,
PasswordHash = "PasswordHash",
PhoneNumber = "PhoneNumber",
IsPhoneNumberConfirmed = true,
IsTwoFactorEnabled = false,
LockoutEndDateUtc = null,
IsLockoutEnabled = true,
AccessFailedCount = 0,
UserName = "UserName",
IsAccountActive = true
};
await userStore.CreateAsync(user);
var existingUser = await userStore.FindByNameAsync("UserName");
existingUser.Email = "[email protected]";
existingUser.PhoneNumber = "1234";
await userStore.UpdateAsync(existingUser);
var updatedUser = await userStore.FindByNameAsync("UserName");
updatedUser.Should().NotBeNull();
updatedUser.Email.Should().Be("[email protected]");
updatedUser.PhoneNumber.Should().Be("1234");
}
示例2: AddRemoveUserClaimTest
public async Task AddRemoveUserClaimTest()
{
var db = UnitTestHelper.CreateDefaultDb();
var store = new UserStore<IdentityUser>(db);
;
var user = new IdentityUser("ClaimsAddRemove");
await store.CreateAsync(user);
Claim[] claims = {new Claim("c", "v"), new Claim("c2", "v2"), new Claim("c2", "v3")};
foreach (Claim c in claims)
{
await store.AddClaimAsync(user, c);
}
await store.UpdateAsync(user);
var userClaims = await store.GetClaimsAsync(user);
Assert.Equal(3, userClaims.Count);
await store.RemoveClaimAsync(user, claims[0]);
Assert.Equal(3, userClaims.Count); // No effect until save changes
db.SaveChanges();
userClaims = await store.GetClaimsAsync(user);
Assert.Equal(2, userClaims.Count);
await store.RemoveClaimAsync(user, claims[1]);
Assert.Equal(2, userClaims.Count); // No effect until save changes
db.SaveChanges();
userClaims = await store.GetClaimsAsync(user);
Assert.Equal(1, userClaims.Count);
await store.RemoveClaimAsync(user, claims[2]);
Assert.Equal(1, userClaims.Count); // No effect until save changes
db.SaveChanges();
userClaims = await store.GetClaimsAsync(user);
Assert.Equal(0, userClaims.Count);
//Assert.Equal(0, user.Claims.Count);
}
示例3: UpdateAutoSavesTest
public async Task UpdateAutoSavesTest()
{
var db = new NoopIdentityDbContext();
var store = new UserStore<IdentityUser>(db);
var user = new IdentityUser("test");
await store.UpdateAsync(user);
Assert.True(db.SaveChangesCalled);
}
示例4: DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive
public async void DeleteAsync_GivenAnExistingUser_UpdatesTheAccountToInActive()
{
var applicationDatabaseConfiguration = new ApplicationDatabaseConfiguration();
var userStore = new UserStore<User>(applicationDatabaseConfiguration);
var existingUser = await userStore.FindByNameAsync("UserName");
existingUser.UserName = "HideMe";
await userStore.UpdateAsync(existingUser);
await userStore.DeleteAsync(existingUser);
existingUser.IsAccountActive.Should().BeFalse();
}
示例5: Button1_Click
protected async void Button1_Click(object sender, EventArgs e)
{
if (txtPsw.Text.Length > 8)
{
UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(_db);
UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
String userId = ddlUser.SelectedValue.ToString();
String newPassword = txtPsw.Text;
String hashedNewPassword = UserManager.PasswordHasher.HashPassword(newPassword);
ApplicationUser cUser = await store.FindByIdAsync(userId);
await store.SetPasswordHashAsync(cUser, hashedNewPassword);
await store.UpdateAsync(cUser);
lblOk.ForeColor = Color.GreenYellow;
lblOk.Text = "Password modificata con successo!";
}
else
{
lblOk.ForeColor = Color.Red;
lblOk.Text = "Scrivi una password valida! Almeno 8 carattteri, 1 maiuscola e un carattere non alfanumerico!";
}
}
示例6: ChangeUserData
public void ChangeUserData(UserdataChangeModel model, IdentityUser user)
{
String hashedNewPassword = _userManager.PasswordHasher.HashPassword(model.password);
UserStore<IdentityUser> store = new UserStore<IdentityUser>(context);
store.SetPasswordHashAsync(user, hashedNewPassword);
store.UpdateAsync(user);
UserInfos info = (from m in db.UserInfos
where m.User_FK == user.Id
select m).First<UserInfos>();
if (model.firstname != null)
info.firstname = model.firstname;
if (model.lastname != null)
info.lastname = model.lastname;
db.Entry(info).State = EntityState.Modified;
db.SaveChanges();
}
示例7: ResetPasswords
public async Task<ActionResult> ResetPasswords()
{
SkyberryContext context = new SkyberryContext();
UserStore<SkyberryUser> store = new UserStore<SkyberryUser>(context);
UserManager<SkyberryUser> UserManager = new UserManager<SkyberryUser>(store);
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(context));
var cUsers = UserManager.Users.ToList();
foreach (var cUser in cUsers)
{
String hashedNewPassword = UserManager.PasswordHasher.HashPassword(cUser.OldPassword ?? "p4ssL3tt3rs");
await store.SetPasswordHashAsync(cUser, hashedNewPassword);
await store.UpdateAsync(cUser);
}
if (!RoleManager.RoleExists("Admin"))
{
var adminIR = RoleManager.Create(new IdentityRole("Admin"));
}
if (!RoleManager.RoleExists("Client"))
{
var clientIR = RoleManager.Create(new IdentityRole("Client"));
}
foreach (SkyberryUser user in UserManager.Users.ToList())
{
UserManager.AddToRole(user.Id, "Client");
if (user.UserName == "daniel" || user.UserName == "lacey")
{
UserManager.AddToRole(user.Id, "Admin");
}
}
return View();
}
示例8: ResetPassword
public async Task<ActionResult> ResetPassword(ResetPasswordViewModel model, String id)
{
ApplicationDbContext context = new ApplicationDbContext();
UserStore<ApplicationUser> store = new UserStore<ApplicationUser>(context);
UserManager<ApplicationUser> UserManager = new UserManager<ApplicationUser>(store);
String hashedNewPassword = UserManager.PasswordHasher.HashPassword(model.Password);
ApplicationUser cUser = await store.FindByIdAsync(id);
await store.SetPasswordHashAsync(cUser, hashedNewPassword);
await store.UpdateAsync(cUser);
return RedirectToAction("Index");
}
示例9: When_User_Does_Not_Exist_SetPasswordHashAsync_Fails
public async void When_User_Does_Not_Exist_SetPasswordHashAsync_Fails()
{
var user = new IdentityUser("foo");
var passwordHash = "somepasswordhash";
var mockResult = new Mock<IOperationResult<IdentityUser>>();
mockResult.SetupGet(x => x.Success).Returns(false);
mockResult.SetupGet(x => x.Status).Returns(ResponseStatus.KeyNotFound);
var mockBucket = new Mock<IBucket>();
mockBucket.SetupGet(e => e.Name).Returns("default");
mockBucket.Setup(x => x.ReplaceAsync(It.IsAny<string>(), It.IsAny<IdentityUser>()))
.ReturnsAsync(mockResult.Object);
var store = new UserStore<IdentityUser>(new ThrowableBucket(mockBucket.Object));
await store.SetPasswordHashAsync(user, passwordHash);
Assert.Throws<CouchbaseException>(async () => await store.UpdateAsync(user));
}
示例10: UserProperties
public async Task<ActionResult> UserProperties(UserPropertiesViewModel model)
{
if (ModelState.IsValid)
{
try
{
using (CustomDbContext db = new CustomDbContext())
{
UserStore<CustomUser> userstore = new UserStore<CustomUser>(db);
var user = await userstore.FindByIdAsync(User.Identity.GetUserId());
user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.Email = model.Email;
user.Phone = model.Phone;
await userstore.UpdateAsync(user);
await db.SaveChangesAsync();
return RedirectToAction("Manage", new { Message = "Your properties have been updated." });
}
}
catch (Exception ex)
{
Trace.TraceError("Error occurred while updating user properties : {0}", ex.ToString());
}
}
return View(model);
}
示例11: ResetPassword
public async Task<ActionResult> ResetPassword(int id) {
var familyUser = await _db.Users.Where(
u => u.Claims.Any(c => c.ClaimType == "Family" && c.ClaimValue == id.ToString())
).FirstAsync();
using (var userStore = new UserStore<WishlistUser>(_db))
using (var userManager = new WishlistUserManager(userStore)) {
var password = GenerateRandomPassword(8);
var hashedPassword = userManager.PasswordHasher.HashPassword(password);
await userStore.SetPasswordHashAsync(familyUser, hashedPassword);
await userStore.UpdateAsync(familyUser);
TempData["familyCredentials"] = new FamilyCredentials {
Username = familyUser.UserName,
Password = password
};
return RedirectToAction("Administer", new { id = id });
}
}
示例12: UserStoreMethodsThrowWhenDisposedTest
public void UserStoreMethodsThrowWhenDisposedTest()
{
var db = UnitTestHelper.CreateDefaultDb();
var store = new UserStore<IdentityUser>(db);
store.Dispose();
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null)));
Assert.Throws<ObjectDisposedException>(
() => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByIdAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.FindByNameAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.UpdateAsync(null)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.DeleteAsync(null)));
Assert.Throws<ObjectDisposedException>(
() => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true)));
Assert.Throws<ObjectDisposedException>(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null)));
Assert.Throws<ObjectDisposedException>(
() => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true)));
Assert.Throws<ObjectDisposedException>(
() => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null)));
}
示例13: UpdateUser
public ActionResult UpdateUser(string Id, string UserName, string RoleName, string roleId)
{
try
{
var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(dbEntity));
using (var store = new UserStore<ApplicationUser>(new ApplicationDbContext()))
{
var userReloaded = store.Users.Where(u => u.Id == Id).FirstOrDefault();
userReloaded.Roles.Clear();
var result = store.AddToRoleAsync(userReloaded, RoleName);
var result2 = store.UpdateAsync(userReloaded);
if (result.IsCompleted && result2.IsCompleted)
{
store.Context.SaveChanges();
}
}
var userVm = new
{
Id = Id,
UserName = UserName,
RoleName = RoleName
};
return Json(new { Result = "OK", Data = userVm, Message = "Cambios Guardados." });
}
catch (Exception e)
{
return Json(new { Result = "ERROR", Message = e.Message });
}
}
示例14: UserStorePublicNullCheckTest
public void UserStorePublicNullCheckTest()
{
var store = new UserStore<IdentityUser>();
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.CreateAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.UpdateAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.DeleteAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddClaimAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(null, null)),
"user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetClaimsAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetLoginsAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetRolesAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddLoginAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(null, null)),
"user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.AddToRoleAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(null, null)),
"user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.IsInRoleAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPasswordHashAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPasswordHashAsync(null, null)),
"user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetSecurityStampAsync(null)),
"user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.SetSecurityStampAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.AddClaimAsync(new IdentityUser("fake"), null)), "claim");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.RemoveClaimAsync(new IdentityUser("fake"), null)), "claim");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.AddLoginAsync(new IdentityUser("fake"), null)), "login");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.RemoveLoginAsync(new IdentityUser("fake"), null)), "login");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.FindAsync(null)), "login");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailConfirmedAsync(null)),
"user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.SetEmailConfirmedAsync(null, true)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetEmailAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetEmailAsync(null, null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetPhoneNumberAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.SetPhoneNumberAsync(null, null)),
"user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.GetPhoneNumberConfirmedAsync(null)), "user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.SetPhoneNumberConfirmedAsync(null, true)), "user");
ExceptionHelper.ThrowsArgumentNull(() => AsyncHelper.RunSync(() => store.GetTwoFactorEnabledAsync(null)),
"user");
ExceptionHelper.ThrowsArgumentNull(
() => AsyncHelper.RunSync(() => store.SetTwoFactorEnabledAsync(null, true)), "user");
ExceptionHelper.ThrowsArgumentNullOrEmpty(
() => AsyncHelper.RunSync(() => store.AddToRoleAsync(new IdentityUser("fake"), null)), "roleName");
ExceptionHelper.ThrowsArgumentNullOrEmpty(
() => AsyncHelper.RunSync(() => store.RemoveFromRoleAsync(new IdentityUser("fake"), null)), "roleName");
ExceptionHelper.ThrowsArgumentNullOrEmpty(
() => AsyncHelper.RunSync(() => store.IsInRoleAsync(new IdentityUser("fake"), null)), "roleName");
}
示例15: removeRole
public async Task<ActionResult> removeRole(string userID, string roleID)
{
ajaxReturnData data = new ajaxReturnData();
try
{
using (ApplicationDbContext DB = new ApplicationDbContext())
{
ApplicationUser user = new ApplicationUser();
var store = new UserStore<ApplicationUser>(DB);
UserManager<ApplicationUser> um = new UserManager<ApplicationUser>(store);
user = um.FindById(userID);
var RoleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(DB));
IdentityRole role = RoleManager.FindById(roleID);
if (user.UserName == "[email protected]" && role.Name == "admin") {
data.statusCode = (int)statusCodes.fail;
data.message = "I'm sorry Dave, I'm afraid I can't do that";
}
else
{
await store.RemoveFromRoleAsync(user, role.Name);
await store.UpdateAsync(user);
data.statusCode = (int)statusCodes.successRun;
data.message = "Role '" + role.Name + "' removed from user '" + user.UserName + "'";
}
}
}
catch (Exception ex)
{
data.statusCode = (int)statusCodes.fail;
data.message = "Failed to remove role from user; Error is: " + ex.Message;
}
return Json(data);
}