Add Async suffix to async methods
Take TUser instead of userId for Usermanager apis
This commit is contained in:
Hao Kung 2014-04-04 13:42:22 -07:00
Родитель 6807da690a
Коммит e8d7cf4219
44 изменённых файлов: 1638 добавлений и 1697 удалений

Просмотреть файл

@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Identity.Entity
public EntityContext Context { get; private set; }
/// <summary>
/// If true will call SaveChanges after Create/Update/Delete
/// If true will call SaveChanges after CreateAsync/UpdateAsync/DeleteAsync
/// </summary>
public bool AutoSaveChanges { get; set; }
@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Identity.Entity
return Roles.SingleOrDefaultAsync(filter, cancellationToken);
}
public async virtual Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Identity.Entity
await SaveChanges(cancellationToken);
}
public async virtual Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Identity.Entity
await SaveChanges(cancellationToken);
}
public async virtual Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -80,12 +80,12 @@ namespace Microsoft.AspNet.Identity.Entity
await SaveChanges(cancellationToken);
}
public Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleIdAsync(TRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(role.Id);
}
public Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(role.Name);
}
@ -97,12 +97,12 @@ namespace Microsoft.AspNet.Identity.Entity
}
/// <summary>
/// Find a role by id
/// FindByLoginAsync a role by id
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<TRole> FindById(string id, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TRole> FindByIdAsync(string id, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -112,12 +112,12 @@ namespace Microsoft.AspNet.Identity.Entity
}
/// <summary>
/// Find a role by name
/// FindByLoginAsync a role by name
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<TRole> FindByName(string name, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TRole> FindByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();

Просмотреть файл

@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Identity.Entity
public EntityContext Context { get; private set; }
/// <summary>
/// If true will call SaveChanges after Create/Update/Delete
/// If true will call SaveChanges after CreateAsync/UpdateAsync/DeleteAsync
/// </summary>
public bool AutoSaveChanges { get; set; }
@ -66,17 +66,41 @@ namespace Microsoft.AspNet.Identity.Entity
//.Include(u => u.Logins)
}
public Task<string> GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserIdAsync(TUser user, CancellationToken cancellationToken = new CancellationToken())
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException("user");
}
return Task.FromResult(Convert.ToString(user.Id, CultureInfo.InvariantCulture));
}
public Task<string> GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserNameAsync(TUser user, CancellationToken cancellationToken = new CancellationToken())
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException("user");
}
return Task.FromResult(user.UserName);
}
public async virtual Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = new CancellationToken())
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
if (user == null)
{
throw new ArgumentNullException("user");
}
user.UserName = userName;
return Task.FromResult(0);
}
public async virtual Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -88,7 +112,7 @@ namespace Microsoft.AspNet.Identity.Entity
await SaveChanges(cancellationToken);
}
public async virtual Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -100,7 +124,7 @@ namespace Microsoft.AspNet.Identity.Entity
await SaveChanges(cancellationToken);
}
public async virtual Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -118,12 +142,12 @@ namespace Microsoft.AspNet.Identity.Entity
}
/// <summary>
/// Find a user by id
/// FindByLoginAsync a user by id
/// </summary>
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -133,12 +157,12 @@ namespace Microsoft.AspNet.Identity.Entity
}
/// <summary>
/// Find a user by name
/// FindByLoginAsync a user by name
/// </summary>
/// <param name="userName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<TUser> FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TUser> FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -151,7 +175,7 @@ namespace Microsoft.AspNet.Identity.Entity
get { return Context.Set<TUser>(); }
}
public async virtual Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -173,7 +197,7 @@ namespace Microsoft.AspNet.Identity.Entity
user.Logins.Add(l);
}
public virtual Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -184,7 +208,7 @@ namespace Microsoft.AspNet.Identity.Entity
throw new NotImplementedException();
}
public virtual Task<IList<UserLoginInfo>> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -197,7 +221,7 @@ namespace Microsoft.AspNet.Identity.Entity
return Task.FromResult(result);
}
public async virtual Task<TUser> Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public async virtual Task<TUser> FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -224,7 +248,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="passwordHash"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -242,7 +266,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<string> GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string> GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -259,7 +283,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
return Task.FromResult(user.PasswordHash != null);
@ -271,7 +295,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<IList<Claim>> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -290,7 +314,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="claim"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -313,7 +337,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="claim"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -348,7 +372,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -366,7 +390,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="confirmed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -385,7 +409,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="email"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -403,7 +427,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<string> GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string> GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -415,12 +439,12 @@ namespace Microsoft.AspNet.Identity.Entity
}
/// <summary>
/// Find a user by email
/// FindByLoginAsync a user by email
/// </summary>
/// <param name="email"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<TUser> FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<TUser> FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -435,7 +459,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<DateTimeOffset> GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<DateTimeOffset> GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -456,7 +480,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="lockoutEnd"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -474,7 +498,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<int> IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<int> IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -492,7 +516,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -511,7 +535,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<int> GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<int> GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -528,7 +552,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -546,7 +570,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="enabled"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -565,7 +589,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="phoneNumber"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -583,7 +607,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<string> GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string> GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -600,7 +624,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -618,7 +642,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="confirmed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -637,7 +661,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task AddToRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -669,7 +693,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task RemoveFromRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -690,7 +714,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<IList<string>> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -708,7 +732,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> IsInRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -730,7 +754,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="stamp"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -748,7 +772,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<string> GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<string> GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -766,7 +790,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="enabled"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();
@ -784,7 +808,7 @@ namespace Microsoft.AspNet.Identity.Entity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<bool> GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<bool> GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
ThrowIfDisposed();

Просмотреть файл

@ -11,13 +11,13 @@ namespace Microsoft.AspNet.Identity.InMemory
{
private readonly Dictionary<string, TRole> _roles = new Dictionary<string, TRole>();
public Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
_roles[role.Id] = role;
return Task.FromResult(0);
}
public Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
if (role == null || !_roles.ContainsKey(role.Id))
{
@ -27,23 +27,23 @@ namespace Microsoft.AspNet.Identity.InMemory
return Task.FromResult(0);
}
public Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleIdAsync(TRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(role.Id);
}
public Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(role.Name);
}
public Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
_roles[role.Id] = role;
return Task.FromResult(0);
}
public Task<TRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
public Task<TRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken))
{
if (_roles.ContainsKey(roleId))
{
@ -52,7 +52,7 @@ namespace Microsoft.AspNet.Identity.InMemory
return Task.FromResult<TRole>(null);
}
public Task<TRole> FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken))
public Task<TRole> FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
return
Task.FromResult(

Просмотреть файл

@ -30,99 +30,99 @@ namespace Microsoft.AspNet.Identity.InMemory
get { return _users.Values.AsQueryable(); }
}
public Task<IList<Claim>> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.Claims);
}
public Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
public Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
{
user.Claims.Add(claim);
return Task.FromResult(0);
}
public Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
public Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken))
{
user.Claims.Remove(claim);
return Task.FromResult(0);
}
public Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken))
public Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken))
{
user.Email = email;
return Task.FromResult(0);
}
public Task<string> GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<string> GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.Email);
}
public Task<bool> GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.EmailConfirmed);
}
public Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
{
user.EmailConfirmed = confirmed;
return Task.FromResult(0);
}
public Task<TUser> FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken))
public Task<TUser> FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken))
{
return
Task.FromResult(
Users.FirstOrDefault(u => String.Equals(u.Email, email, StringComparison.OrdinalIgnoreCase)));
}
public Task<DateTimeOffset> GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<DateTimeOffset> GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.LockoutEnd);
}
public Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
public Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken))
{
user.LockoutEnd = lockoutEnd;
return Task.FromResult(0);
}
public Task<int> IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<int> IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
user.AccessFailedCount++;
return Task.FromResult(user.AccessFailedCount);
}
public Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
user.AccessFailedCount = 0;
return Task.FromResult(0);
}
public Task<int> GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<int> GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.AccessFailedCount);
}
public Task<bool> GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.LockoutEnabled);
}
public Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
public Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
{
user.LockoutEnabled = enabled;
return Task.FromResult(0);
}
public Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
user.Logins.Add(login);
_logins[login] = user;
return Task.FromResult(0);
}
public Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
var logs =
user.Logins.Where(l => l.ProviderKey == login.ProviderKey && l.LoginProvider == login.LoginProvider)
@ -135,12 +135,12 @@ namespace Microsoft.AspNet.Identity.InMemory
return Task.FromResult(0);
}
public Task<IList<UserLoginInfo>> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.Logins);
}
public Task<TUser> Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
public Task<TUser> FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken))
{
if (_logins.ContainsKey(login))
{
@ -149,29 +149,35 @@ namespace Microsoft.AspNet.Identity.InMemory
return Task.FromResult<TUser>(null);
}
public Task<string> GetUserId(TUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserIdAsync(TUser user, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(user.Id);
}
public Task<string> GetUserName(TUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserNameAsync(TUser user, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(user.UserName);
}
public Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = new CancellationToken())
{
user.UserName = userName;
return Task.FromResult(0);
}
public Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
_users[user.Id] = user;
return Task.FromResult(0);
}
public Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
_users[user.Id] = user;
return Task.FromResult(0);
}
public Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken))
public Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
{
if (_users.ContainsKey(userId))
{
@ -184,14 +190,14 @@ namespace Microsoft.AspNet.Identity.InMemory
{
}
public Task<TUser> FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken))
public Task<TUser> FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken))
{
return
Task.FromResult(
Users.FirstOrDefault(u => String.Equals(u.UserName, userName, StringComparison.OrdinalIgnoreCase)));
}
public Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
if (user == null || !_users.ContainsKey(user.Id))
{
@ -201,84 +207,84 @@ namespace Microsoft.AspNet.Identity.InMemory
return Task.FromResult(0);
}
public Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken))
public Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken))
{
user.PasswordHash = passwordHash;
return Task.FromResult(0);
}
public Task<string> GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<string> GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.PasswordHash);
}
public Task<bool> HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.PasswordHash != null);
}
public Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
public Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken))
{
user.PhoneNumber = phoneNumber;
return Task.FromResult(0);
}
public Task<string> GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<string> GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.PhoneNumber);
}
public Task<bool> GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.PhoneNumberConfirmed);
}
public Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
public Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken))
{
user.PhoneNumberConfirmed = confirmed;
return Task.FromResult(0);
}
public Task AddToRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
public Task AddToRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
{
user.Roles.Add(role);
return Task.FromResult(0);
}
public Task RemoveFromRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
public Task RemoveFromRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
{
user.Roles.Remove(role);
return Task.FromResult(0);
}
public Task<IList<string>> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.Roles);
}
public Task<bool> IsInRole(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> IsInRoleAsync(TUser user, string role, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.Roles.Contains(role));
}
public Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken))
public Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken))
{
user.SecurityStamp = stamp;
return Task.FromResult(0);
}
public Task<string> GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<string> GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.SecurityStamp);
}
public Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
public Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken))
{
user.TwoFactorEnabled = enabled;
return Task.FromResult(0);
}
public Task<bool> GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task<bool> GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(user.TwoFactorEnabled);
}

Просмотреть файл

@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Identity.Security
public HttpContext Context { get; set; }
public virtual async Task<ClaimsIdentity> CreateUserIdentity(TUser user)
public virtual async Task<ClaimsIdentity> CreateUserIdentityAsync(TUser user)
{
if (UserManager == null)
{
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Identity.Security
}
// TODO: all the two factor logic/external/rememberBrowser
var userIdentity = await CreateUserIdentity(user);
var userIdentity = await CreateUserIdentityAsync(user);
Context.Response.SignIn(userIdentity, new AuthenticationProperties { IsPersistent = isPersistent });
}
@ -49,18 +49,18 @@ namespace Microsoft.AspNet.Identity.Security
// return false;
// }
// var token = await UserManager.GenerateTwoFactorToken(userId, provider);
// var token = await UserManager.GenerateTwoFactorTokenAsync(userId, provider);
// // See IdentityConfig.cs to plug in Email/SMS services to actually send the code
// await UserManager.NotifyTwoFactorToken(userId, provider, token);
// await UserManager.NotifyTwoFactorTokenAsync(userId, provider, token);
// return true;
//}
//public Task<TKey> GetVerifiedUserId()
//{
// //var result = await AuthenticationManager.Authenticate(DefaultAuthenticationTypes.TwoFactorCookie);
// //if (result != null && result.Identity != null && !String.IsNullOrEmpty(result.Identity.GetUserId()))
// //if (result != null && result.Identity != null && !String.IsNullOrEmpty(result.Identity.GetUserIdAsync()))
// //{
// // return result.Identity.GetUserId();
// // return result.Identity.GetUserIdAsync();
// //}
// return Task.FromResult(default(TKey));
//}
@ -77,35 +77,35 @@ namespace Microsoft.AspNet.Identity.Security
// {
// return SignInStatus.Failure;
// }
// var user = await UserManager.FindById(userId);
// var user = await UserManager.FindByIdAsync(userId);
// if (user == null)
// {
// return SignInStatus.Failure;
// }
// if (await UserManager.IsLockedOut(user.Id))
// if (await UserManager.IsLockedOutAsync(user.Id))
// {
// return SignInStatus.LockedOut;
// }
// if (await UserManager.VerifyTwoFactorToken(user.Id, provider, code))
// if (await UserManager.VerifyTwoFactorTokenAsync(user.Id, provider, code))
// {
// // When token is verified correctly, clear the access failed count used for lockout
// await UserManager.ResetAccessFailedCount(user.Id);
// await UserManager.ResetAccessFailedCountAsync(user.Id);
// await SignIn(user, isPersistent, rememberBrowser);
// return SignInStatus.Success;
// }
// // If the token is incorrect, record the failure which also may cause the user to be locked out
// await UserManager.AccessFailed(user.Id);
// await UserManager.AccessFailedAsync(user.Id);
// return SignInStatus.Failure;
//}
//public async Task<SignInStatus> ExternalSignIn(ExternalLoginInfo loginInfo, bool isPersistent)
//{
// var user = await UserManager.Find(loginInfo.Login);
// var user = await UserManager.FindByLoginAsync(loginInfo.Login);
// if (user == null)
// {
// return SignInStatus.Failure;
// }
// if (await UserManager.IsLockedOut(user.Id))
// if (await UserManager.IsLockedOutAsync(user.Id))
// {
// return SignInStatus.LockedOut;
// }
@ -114,11 +114,11 @@ namespace Microsoft.AspNet.Identity.Security
//private async Task<SignInStatus> SignInOrTwoFactor(TUser user, bool isPersistent)
//{
// if (await UserManager.GetTwoFactorEnabled(user.Id))
// if (await UserManager.GetTwoFactorEnabledAsync(user.Id))
// //&& !await AuthenticationManager.TwoFactorBrowserRemembered(user.Id))
// {
// //var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie);
// //identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
// //identity.AddClaimAsync(new Claim(ClaimTypes.NameIdentifier, user.Id));
// //AuthenticationManager.SignIn(identity);
// return SignInStatus.RequiresTwoFactorAuthentication;
// }
@ -126,24 +126,22 @@ namespace Microsoft.AspNet.Identity.Security
// return SignInStatus.Success;
//}
public virtual async Task<SignInStatus> PasswordSignIn(string userName, string password, bool isPersistent, bool shouldLockout)
public virtual async Task<SignInStatus> PasswordSignInAsync(string userName, string password, bool isPersistent, bool shouldLockout)
{
if (UserManager == null)
{
return SignInStatus.Failure;
}
var user = await UserManager.FindByName(userName);
var user = await UserManager.FindByNameAsync(userName);
if (user == null)
{
return SignInStatus.Failure;
}
// TODO: overloads taking TUser?
var userId = await UserManager.GetUserId(user);
if (await UserManager.IsLockedOut(userId))
if (await UserManager.IsLockedOutAsync(user))
{
return SignInStatus.LockedOut;
}
if (await UserManager.CheckPassword(user, password))
if (await UserManager.CheckPasswordAsync(user, password))
{
await SignIn(user, isPersistent, false);
return SignInStatus.Success;
@ -152,8 +150,8 @@ namespace Microsoft.AspNet.Identity.Security
if (shouldLockout)
{
// If lockout is requested, increment access failed count which might lock out the user
await UserManager.AccessFailed(userId);
if (await UserManager.IsLockedOut(userId))
await UserManager.AccessFailedAsync(user);
if (await UserManager.IsLockedOutAsync(user))
{
return SignInStatus.LockedOut;
}

Просмотреть файл

@ -50,14 +50,14 @@ namespace Microsoft.AspNet.Identity
public string SecurityStampClaimType { get; set; }
/// <summary>
/// Create a ClaimsIdentity from a user
/// CreateAsync a ClaimsIdentity from a user
/// </summary>
/// <param name="manager"></param>
/// <param name="user"></param>
/// <param name="authenticationType"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<ClaimsIdentity> Create(UserManager<TUser> manager, TUser user,
public virtual async Task<ClaimsIdentity> CreateAsync(UserManager<TUser> manager, TUser user,
string authenticationType, CancellationToken cancellationToken = default(CancellationToken))
{
if (manager == null)
@ -68,18 +68,18 @@ namespace Microsoft.AspNet.Identity
{
throw new ArgumentNullException("user");
}
var userId = await manager.GetUserId(user, cancellationToken);
var userName = await manager.GetUserName(user, cancellationToken);
var userId = await manager.GetUserIdAsync(user, cancellationToken);
var userName = await manager.GetUserNameAsync(user, cancellationToken);
var id = new ClaimsIdentity(authenticationType, UserNameClaimType, RoleClaimType);
id.AddClaim(new Claim(UserIdClaimType, userId));
id.AddClaim(new Claim(UserNameClaimType, userName, ClaimValueTypes.String));
if (manager.SupportsUserSecurityStamp)
{
id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStamp(userId, cancellationToken)));
id.AddClaim(new Claim(SecurityStampClaimType, await manager.GetSecurityStampAsync(user, cancellationToken)));
}
if (manager.SupportsUserRole)
{
var roles = await manager.GetRoles(userId, cancellationToken);
var roles = await manager.GetRolesAsync(user, cancellationToken);
foreach (var roleName in roles)
{
id.AddClaim(new Claim(RoleClaimType, roleName, ClaimValueTypes.String));
@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Identity
}
if (manager.SupportsUserClaim)
{
id.AddClaims(await manager.GetClaims(userId, cancellationToken));
id.AddClaims(await manager.GetClaimsAsync(user, cancellationToken));
}
return id;
}

Просмотреть файл

@ -13,13 +13,13 @@ namespace Microsoft.AspNet.Identity
where TUser : class
{
/// <summary>
/// Create a ClaimsIdentity from an user using a UserManager
/// CreateAsync a ClaimsIdentity from an user using a UserManager
/// </summary>
/// <param name="manager"></param>
/// <param name="user"></param>
/// <param name="authenticationType"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<ClaimsIdentity> Create(UserManager<TUser> manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken));
Task<ClaimsIdentity> CreateAsync(UserManager<TUser> manager, TUser user, string authenticationType, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -14,6 +14,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="message"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Send(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken));
Task SendAsync(IdentityMessage message, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -9,9 +9,9 @@ namespace Microsoft.AspNet.Identity
public interface IPasswordValidator
{
/// <summary>
/// Validate the item
/// ValidateAsync the item
/// </summary>
/// <returns></returns>
Task<IdentityResult> Validate(string password, CancellationToken cancellationToken = default(CancellationToken));
Task<IdentityResult> ValidateAsync(string password, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -1,19 +0,0 @@
//namespace Microsoft.AspNet.Identity
//{
// /// <summary>
// /// Mimimal set of data needed to persist role data
// /// </summary>
// /// <typeparam name="TKey"></typeparam>
// public interface IRole<out TKey>
// {
// /// <summary>
// /// Id of the role
// /// </summary>
// TKey Id { get; }
// /// <summary>
// /// Name of the role
// /// </summary>
// string Name { get; set; }
// }
//}

Просмотреть файл

@ -16,23 +16,23 @@ namespace Microsoft.AspNet.Identity
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Create(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update a role
/// UpdateAsync a role
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Update(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Delete a role
/// DeleteAsync a role
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns a role's id
@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetRoleIdAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns a role's name
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Finds a role by id
@ -56,14 +56,14 @@ namespace Microsoft.AspNet.Identity
/// <param name="roleId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken));
Task<TRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Find a role by name
/// FindByLoginAsync a role by name
/// </summary>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TRole> FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken));
Task<TRole> FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -12,12 +12,12 @@ namespace Microsoft.AspNet.Identity
public interface IRoleValidator<TRole> where TRole : class
{
/// <summary>
/// Validate the user
/// ValidateAsync the user
/// </summary>
/// <param name="role"></param>
/// <param name="manager"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IdentityResult> Validate(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken));
Task<IdentityResult> ValidateAsync(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -1,19 +0,0 @@
//namespace Microsoft.AspNet.Identity
//{
// /// <summary>
// /// Minimal interface for a user with id and username
// /// </summary>
// /// <typeparam name="TKey"></typeparam>
// public interface IUser<out TKey>
// {
// /// <summary>
// /// Unique key for the user
// /// </summary>
// TKey Id { get; }
// /// <summary>
// /// Unique username
// /// </summary>
// string UserName { get; set; }
// }
//}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<Claim>> GetClaims(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Add a new user claim
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="claim"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
Task AddClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Remove a user claim
@ -35,6 +35,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="claim"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveClaim(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
Task RemoveClaimAsync(TUser user, Claim claim, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="email"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetEmail(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken));
Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get the user email
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetEmail(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetEmailAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns true if the user email is confirmed
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> GetEmailConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Sets whether the user email is confirmed
@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="confirmed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetEmailConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken));
Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the user associated with this email
@ -49,6 +49,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="email"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TUser> FindByEmail(string email, CancellationToken cancellationToken = default(CancellationToken));
Task<TUser> FindByEmailAsync(string email, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<DateTimeOffset> GetLockoutEndDate(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<DateTimeOffset> GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Locks a user out until the specified end date (set to a past date, to unlock a user)
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="lockoutEnd"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetLockoutEndDate(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken));
Task SetLockoutEndDateAsync(TUser user, DateTimeOffset lockoutEnd, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Used to record when an attempt to access the user has failed
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> IncrementAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<int> IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Used to reset the account access count, typically after the account is successfully accessed
@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task ResetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the current number of failed access attempts. This number usually will be reset whenever the password is
@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> GetAccessFailedCount(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<int> GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns whether the user can be locked out.
@ -59,7 +59,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> GetLockoutEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Sets whether the user can be locked out.
@ -68,6 +68,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="enabled"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetLockoutEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken));
Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="login"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes the user login with the specified combination if it exists, returns true if found and removed
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="login"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveLogin(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
Task RemoveLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the linked accounts for this user
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<UserLoginInfo>> GetLogins(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the user associated with this login
@ -42,6 +42,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="login"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TUser> Find(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
Task<TUser> FindByLoginAsync(UserLoginInfo login, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -1,37 +0,0 @@
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Identity
{
/// <summary>
/// Stores a user's email
/// </summary>
/// <typeparam name="TUser"></typeparam>
public interface IUserNameStore<TUser, in TKey> : IUserStore<TUser> where TUser : class
{
/// <summary>
/// Set the user name
/// </summary>
/// <param name="user"></param>
/// <param name="userName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetUserName(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get the user name
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the user associated with this name
/// </summary>
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TUser> FindByName(string name, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="passwordHash"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetPasswordHash(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken));
Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get the user password hash
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetPasswordHash(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetPasswordHashAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns true if a user has a password set
@ -32,6 +32,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> HasPassword(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> HasPasswordAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="phoneNumber"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetPhoneNumber(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken));
Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get the user phoneNumber
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetPhoneNumber(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns true if the user phone number is confirmed
@ -32,7 +32,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> GetPhoneNumberConfirmed(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Sets whether the user phone number is confirmed
@ -41,6 +41,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="confirmed"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetPhoneNumberConfirmed(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken));
Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task AddToRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
Task AddToRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Removes the role for the user
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task RemoveFromRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
Task RemoveFromRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the roles for this user
@ -34,7 +34,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IList<string>> GetRoles(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns true if a user is in a role
@ -43,6 +43,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsInRole(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="stamp"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetSecurityStamp(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken));
Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get the user security stamp
@ -24,6 +24,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetSecurityStamp(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetSecurityStampAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetUserId(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetUserIdAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the user's name
@ -25,7 +25,16 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> GetUserName(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GetUserNameAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Set the user name
/// </summary>
/// <param name="user"></param>
/// <param name="userName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Insert a new user
@ -33,23 +42,23 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Create(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task CreateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Update a user
/// UpdateAsync a user
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Update(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task UpdateAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Delete a user
/// DeleteAsync a user
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Delete(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task DeleteAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Finds a user
@ -57,7 +66,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="userId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken));
Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns the user associated with this name
@ -65,7 +74,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="name"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TUser> FindByName(string name, CancellationToken cancellationToken = default(CancellationToken));
Task<TUser> FindByNameAsync(string name, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -17,10 +17,10 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<string> Generate(string purpose, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<string> GenerateAsync(string purpose, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Validate and unprotect a token, returns null if invalid
/// ValidateAsync and unprotect a token, returns null if invalid
/// </summary>
/// <param name="purpose"></param>
/// <param name="token"></param>
@ -28,7 +28,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> Validate(string purpose, string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> ValidateAsync(string purpose, string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Notifies the user that a token has been generated, i.e. via email or sms, or can no-op
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task Notify(string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task NotifyAsync(string token, UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns true if provider can be used for this user, i.e. could require a user to have an email
@ -47,6 +47,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsValidProviderForUser(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> IsValidProviderForUserAsync(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="enabled"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SetTwoFactorEnabled(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken));
Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Returns whether two factor is enabled for the user
@ -24,6 +24,6 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> GetTwoFactorEnabled(TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<bool> GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Identity
public interface IUserValidator<TUser> where TUser : class
{
/// <summary>
/// Validate the user
/// ValidateAsync the user
/// </summary>
/// <param name="manager"></param>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IdentityResult> Validate(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
Task<IdentityResult> ValidateAsync(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken));
}
}

Просмотреть файл

@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="item"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual Task<IdentityResult> Validate(string item, CancellationToken cancellationToken = default(CancellationToken))
public virtual Task<IdentityResult> ValidateAsync(string item, CancellationToken cancellationToken = default(CancellationToken))
{
if (item == null)
{

Просмотреть файл

@ -239,16 +239,12 @@
</data>
<data name="UserAlreadyHasPassword" xml:space="preserve">
<value>User already has a password set.</value>
<comment>error when AddPassword called when a user already has a password</comment>
<comment>error when AddPasswordAsync called when a user already has a password</comment>
</data>
<data name="UserAlreadyInRole" xml:space="preserve">
<value>User already in role.</value>
<comment>Error when a user is already in a role</comment>
</data>
<data name="UserIdNotFound" xml:space="preserve">
<value>UserId not found.</value>
<comment>No user with this id found</comment>
</data>
<data name="UserNameNotFound" xml:space="preserve">
<value>User {0} does not exist.</value>
<comment>error when a user does not exist</comment>

Просмотреть файл

@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Identity
var timestepAsBytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder((long) timestepNumber));
var hash = hashAlgorithm.ComputeHash(ApplyModifier(timestepAsBytes, modifier));
// Generate DT string
// GenerateAsync DT string
var offset = hash[hash.Length - 1] & 0xf;
Debug.Assert(offset + 4 < hash.Length);
var binaryCode = (hash[offset] & 0x7f) << 24

Просмотреть файл

@ -76,16 +76,16 @@ namespace Microsoft.AspNet.Identity
private async Task<IdentityResult> ValidateRoleInternal(TRole role, CancellationToken cancellationToken)
{
return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.Validate(this, role, cancellationToken);
return (RoleValidator == null) ? IdentityResult.Success : await RoleValidator.ValidateAsync(this, role, cancellationToken);
}
/// <summary>
/// Create a role
/// CreateAsync a role
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IdentityResult> Create(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IdentityResult> CreateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
if (role == null)
@ -98,17 +98,17 @@ namespace Microsoft.AspNet.Identity
{
return result;
}
await Store.Create(role, cancellationToken);
await Store.CreateAsync(role, cancellationToken);
return IdentityResult.Success;
}
/// <summary>
/// Update an existing role
/// UpdateAsync an existing role
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IdentityResult> Update(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IdentityResult> UpdateAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
if (role == null)
@ -121,17 +121,17 @@ namespace Microsoft.AspNet.Identity
{
return result;
}
await Store.Update(role, cancellationToken);
await Store.UpdateAsync(role, cancellationToken);
return IdentityResult.Success;
}
/// <summary>
/// Delete a role
/// DeleteAsync a role
/// </summary>
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IdentityResult> Delete(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IdentityResult> DeleteAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
if (role == null)
@ -139,7 +139,7 @@ namespace Microsoft.AspNet.Identity
throw new ArgumentNullException("role");
}
await Store.Delete(role, cancellationToken);
await Store.DeleteAsync(role, cancellationToken);
return IdentityResult.Success;
}
@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<bool> RoleExists(string roleName, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<bool> RoleExistsAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
if (roleName == null)
@ -161,15 +161,15 @@ namespace Microsoft.AspNet.Identity
}
/// <summary>
/// Find a role by id
/// FindByLoginAsync a role by id
/// </summary>
/// <param name="roleId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<TRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<TRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
return await Store.FindById(roleId, cancellationToken);
return await Store.FindByIdAsync(roleId, cancellationToken);
}
/// <summary>
@ -178,10 +178,10 @@ namespace Microsoft.AspNet.Identity
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<string> GetRoleName(TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<string> GetRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
return await Store.GetRoleName(role, cancellationToken);
return await Store.GetRoleNameAsync(role, cancellationToken);
}
/// <summary>
@ -193,11 +193,11 @@ namespace Microsoft.AspNet.Identity
public virtual async Task<string> GetRoleId(TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
ThrowIfDisposed();
return await Store.GetRoleId(role, cancellationToken);
return await Store.GetRoleIdAsync(role, cancellationToken);
}
/// <summary>
/// Find a role by name
/// FindByLoginAsync a role by name
/// </summary>
/// <param name="roleName"></param>
/// <param name="cancellationToken"></param>
@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Identity
throw new ArgumentNullException("roleName");
}
return await Store.FindByName(roleName, cancellationToken);
return await Store.FindByNameAsync(roleName, cancellationToken);
}
private void ThrowIfDisposed()

Просмотреть файл

@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="role"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IdentityResult> Validate(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IdentityResult> ValidateAsync(RoleManager<TRole> manager, TRole role, CancellationToken cancellationToken = default(CancellationToken))
{
if (manager == null)
{
@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity
private static async Task ValidateRoleName(RoleManager<TRole> manager, TRole role,
ICollection<string> errors)
{
var roleName = await manager.GetRoleName(role);
var roleName = await manager.GetRoleNameAsync(role);
if (string.IsNullOrWhiteSpace(roleName))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Name"));

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Identity
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public virtual async Task<IdentityResult> Validate(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken))
public virtual async Task<IdentityResult> ValidateAsync(UserManager<TUser> manager, TUser user, CancellationToken cancellationToken = default(CancellationToken))
{
if (manager == null)
{
@ -104,7 +104,7 @@ namespace Microsoft.AspNet.Identity
private async Task ValidateUserName(UserManager<TUser> manager, TUser user, ICollection<string> errors)
{
var userName = await manager.GetUserName(user);
var userName = await manager.GetUserNameAsync(user);
if (string.IsNullOrWhiteSpace(userName))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "UserName"));
@ -116,8 +116,8 @@ namespace Microsoft.AspNet.Identity
}
else
{
var owner = await manager.FindByName(userName);
if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user)))
var owner = await manager.FindByNameAsync(userName);
if (owner != null && !string.Equals(await manager.GetUserIdAsync(owner), await manager.GetUserIdAsync(user)))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateName, userName));
}
@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Identity
// make sure email is not empty, valid, and unique
private static async Task ValidateEmail(UserManager<TUser> manager, TUser user, List<string> errors)
{
var email = await manager.GetEmailStore().GetEmail(user);
var email = await manager.GetEmailAsync(user);
if (string.IsNullOrWhiteSpace(email))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.PropertyTooShort, "Email"));
@ -144,8 +144,8 @@ namespace Microsoft.AspNet.Identity
return;
}
#endif
var owner = await manager.FindByEmail(email);
if (owner != null && !string.Equals(await manager.GetUserId(owner), await manager.GetUserId(user)))
var owner = await manager.FindByEmailAsync(email);
if (owner != null && !string.Equals(await manager.GetUserIdAsync(owner), await manager.GetUserIdAsync(user)))
{
errors.Add(String.Format(CultureInfo.CurrentCulture, Resources.DuplicateEmail, email));
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
var identityFactory = new Mock<IClaimsIdentityFactory<TestUser>>();
const string authType = "Test";
var testIdentity = new ClaimsIdentity(authType);
identityFactory.Setup(s => s.Create(userManager, user, authType, CancellationToken.None)).ReturnsAsync(testIdentity).Verifiable();
identityFactory.Setup(s => s.CreateAsync(userManager, user, authType, CancellationToken.None)).ReturnsAsync(testIdentity).Verifiable();
userManager.ClaimsIdentityFactory = identityFactory.Object;
var context = new Mock<HttpContext>();
var response = new Mock<HttpResponse>();
@ -44,12 +44,12 @@ namespace Microsoft.AspNet.Identity.Security.Test
// Setup
var user = new TestUser { UserName = "Foo" };
var manager = new Mock<UserManager<TestUser>>();
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(true).Verifiable();
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(true).Verifiable();
manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
// Act
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false);
var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, false);
// Assert
Assert.Equal(SignInStatus.LockedOut, result);
@ -62,9 +62,9 @@ namespace Microsoft.AspNet.Identity.Security.Test
// Setup
var user = new TestUser { UserName = "Foo" };
var manager = new Mock<UserManager<TestUser>>();
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPassword(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable();
manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPasswordAsync(user, "password", CancellationToken.None)).ReturnsAsync(true).Verifiable();
manager.Setup(m => m.CreateIdentity(user, "Microsoft.AspNet.Identity", CancellationToken.None)).ReturnsAsync(new ClaimsIdentity("Microsoft.AspNet.Identity")).Verifiable();
var context = new Mock<HttpContext>();
var response = new Mock<HttpResponse>();
@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
var helper = new SignInManager<TestUser> { UserManager = manager.Object, Context = context.Object };
// Act
var result = await helper.PasswordSignIn(user.UserName, "password", false, false);
var result = await helper.PasswordSignInAsync(user.UserName, "password", false, false);
// Assert
Assert.Equal(SignInStatus.Success, result);
@ -86,13 +86,13 @@ namespace Microsoft.AspNet.Identity.Security.Test
// Setup
var user = new TestUser { UserName = "Foo" };
var manager = new Mock<UserManager<TestUser>>();
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPasswordAsync(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
// Act
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, false);
var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, false);
// Assert
Assert.Equal(SignInStatus.Failure, result);
@ -105,11 +105,11 @@ namespace Microsoft.AspNet.Identity.Security.Test
{
// Setup
var manager = new Mock<UserManager<TestUser>>();
manager.Setup(m => m.FindByName("bogus", CancellationToken.None)).ReturnsAsync(null).Verifiable();
manager.Setup(m => m.FindByNameAsync("bogus", CancellationToken.None)).ReturnsAsync(null).Verifiable();
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
// Act
var result = await helper.PasswordSignIn("bogus", "bogus", false, false);
var result = await helper.PasswordSignInAsync("bogus", "bogus", false, false);
// Assert
Assert.Equal(SignInStatus.Failure, result);
@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
var helper = new SignInManager<TestUser>();
// Act
var result = await helper.PasswordSignIn("bogus", "bogus", false, false);
var result = await helper.PasswordSignInAsync("bogus", "bogus", false, false);
// Assert
Assert.Equal(SignInStatus.Failure, result);
@ -137,7 +137,7 @@ namespace Microsoft.AspNet.Identity.Security.Test
var helper = new SignInManager<TestUser>();
// Act
var result = await helper.CreateUserIdentity(user);
var result = await helper.CreateUserIdentityAsync(user);
// Assert
Assert.Null(result);
@ -151,18 +151,18 @@ namespace Microsoft.AspNet.Identity.Security.Test
var user = new TestUser { UserName = "Foo" };
var manager = new Mock<UserManager<TestUser>>();
var lockedout = false;
manager.Setup(m => m.AccessFailed(user.Id, CancellationToken.None)).Returns(() =>
manager.Setup(m => m.AccessFailedAsync(user, CancellationToken.None)).Returns(() =>
{
lockedout = true;
return Task.FromResult(IdentityResult.Success);
}).Verifiable();
manager.Setup(m => m.IsLockedOut(user.Id, CancellationToken.None)).Returns(() => Task.FromResult(lockedout));
manager.Setup(m => m.FindByName(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPassword(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
manager.Setup(m => m.IsLockedOutAsync(user, CancellationToken.None)).Returns(() => Task.FromResult(lockedout));
manager.Setup(m => m.FindByNameAsync(user.UserName, CancellationToken.None)).ReturnsAsync(user).Verifiable();
manager.Setup(m => m.CheckPasswordAsync(user, "bogus", CancellationToken.None)).ReturnsAsync(false).Verifiable();
var helper = new SignInManager<TestUser> { UserManager = manager.Object };
// Act
var result = await helper.PasswordSignIn(user.UserName, "bogus", false, true);
var result = await helper.PasswordSignInAsync(user.UserName, "bogus", false, true);
// Assert
Assert.Equal(SignInStatus.LockedOut, result);

Просмотреть файл

@ -16,11 +16,11 @@ namespace Microsoft.AspNet.Identity.Test
var factory = new ClaimsIdentityFactory<TestUser>();
var manager = new UserManager<TestUser>(new NoopUserStore());
await Assert.ThrowsAsync<ArgumentNullException>("manager",
async () => await factory.Create(null, null, "whatever"));
async () => await factory.CreateAsync(null, null, "whatever"));
await Assert.ThrowsAsync<ArgumentNullException>("user",
async () => await factory.Create(manager, null, "whatever"));
async () => await factory.CreateAsync(manager, null, "whatever"));
await Assert.ThrowsAsync<ArgumentNullException>("value",
async () => await factory.Create(manager, new TestUser(), null));
async () => await factory.CreateAsync(manager, new TestUser(), null));
}
#if NET45
@ -37,18 +37,18 @@ namespace Microsoft.AspNet.Identity.Test
var user = new TestUser { UserName = "Foo" };
userManager.Setup(m => m.SupportsUserRole).Returns(supportRoles);
userManager.Setup(m => m.SupportsUserClaim).Returns(supportClaims);
userManager.Setup(m => m.GetUserId(user, CancellationToken.None)).ReturnsAsync(user.Id);
userManager.Setup(m => m.GetUserName(user, CancellationToken.None)).ReturnsAsync(user.UserName);
userManager.Setup(m => m.GetUserIdAsync(user, CancellationToken.None)).ReturnsAsync(user.Id);
userManager.Setup(m => m.GetUserNameAsync(user, CancellationToken.None)).ReturnsAsync(user.UserName);
var roleClaims = new[] { "Admin", "Local" };
userManager.Setup(m => m.GetRoles(user.Id, CancellationToken.None)).ReturnsAsync(roleClaims);
userManager.Setup(m => m.GetRolesAsync(user, CancellationToken.None)).ReturnsAsync(roleClaims);
var userClaims = new[] { new Claim("Whatever", "Value"), new Claim("Whatever2", "Value2") };
userManager.Setup(m => m.GetClaims(user.Id, CancellationToken.None)).ReturnsAsync(userClaims);
userManager.Setup(m => m.GetClaimsAsync(user, CancellationToken.None)).ReturnsAsync(userClaims);
const string authType = "Microsoft.AspNet.Identity";
var factory = new ClaimsIdentityFactory<TestUser>();
// Act
var identity = await factory.Create(userManager.Object, user, authType);
var identity = await factory.CreateAsync(userManager.Object, user, authType);
// Assert
Assert.NotNull(identity);

Просмотреть файл

@ -5,27 +5,27 @@ namespace Microsoft.AspNet.Identity.Test
{
public class NoopRoleStore : IRoleStore<TestRole>
{
public Task Create(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
public Task CreateAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task Update(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
public Task UpdateAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task<string> GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleNameAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult<string>(null);
}
public Task<TestRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
public Task<TestRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<TestRole>(null);
}
public Task<TestRole> FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken))
public Task<TestRole> FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<TestRole>(null);
}
@ -34,12 +34,12 @@ namespace Microsoft.AspNet.Identity.Test
{
}
public Task Delete(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
public Task DeleteAsync(TestRole user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task<string> GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleIdAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult<string>(null);
}

Просмотреть файл

@ -5,32 +5,37 @@ namespace Microsoft.AspNet.Identity.Test
{
public class NoopUserStore : IUserStore<TestUser>
{
public Task<string> GetUserId(TestUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserIdAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(user.Id);
}
public Task<string> GetUserName(TestUser user, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetUserNameAsync(TestUser user, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(user.UserName);
}
public Task Create(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task SetUserNameAsync(TestUser user, string userName, CancellationToken cancellationToken = new CancellationToken())
{
return Task.FromResult(0);
}
public Task Update(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task CreateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task<TestUser> FindById(string userId, CancellationToken cancellationToken = default(CancellationToken))
public Task UpdateAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}
public Task<TestUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<TestUser>(null);
}
public Task<TestUser> FindByName(string userName, CancellationToken cancellationToken = default(CancellationToken))
public Task<TestUser> FindByNameAsync(string userName, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult<TestUser>(null);
}
@ -39,7 +44,7 @@ namespace Microsoft.AspNet.Identity.Test
{
}
public Task Delete(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
public Task DeleteAsync(TestUser user, CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(0);
}

Просмотреть файл

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Identity.Test
// Act
// Assert
await Assert.ThrowsAsync<ArgumentNullException>(() => validator.Validate(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => validator.ValidateAsync(null));
}
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Identity.Test
{
const string error = "Passwords must be at least 6 characters.";
var valid = new PasswordValidator {RequiredLength = 6};
IdentityResultAssert.IsFailure(await valid.Validate(input), error);
IdentityResultAssert.IsFailure(await valid.ValidateAsync(input), error);
}
[Theory]
@ -47,7 +47,7 @@ namespace Microsoft.AspNet.Identity.Test
public async Task SuccessIfLongEnoughTests(string input)
{
var valid = new PasswordValidator {RequiredLength = 6};
IdentityResultAssert.IsSuccess(await valid.Validate(input));
IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input));
}
[Theory]
@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Identity.Test
public async Task FailsWithoutRequiredNonAlphanumericTests(string input)
{
var valid = new PasswordValidator {RequireNonLetterOrDigit = true};
IdentityResultAssert.IsFailure(await valid.Validate(input),
IdentityResultAssert.IsFailure(await valid.ValidateAsync(input),
"Passwords must have at least one non letter or digit character.");
}
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Identity.Test
public async Task SucceedsWithRequiredNonAlphanumericTests(string input)
{
var valid = new PasswordValidator {RequireNonLetterOrDigit = true};
IdentityResultAssert.IsSuccess(await valid.Validate(input));
IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input));
}
[Theory]
@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Identity.Test
}
if (errors.Count == 0)
{
IdentityResultAssert.IsSuccess(await valid.Validate(input));
IdentityResultAssert.IsSuccess(await valid.ValidateAsync(input));
}
else
{
IdentityResultAssert.IsFailure(await valid.Validate(input), string.Join(" ", errors));
IdentityResultAssert.IsFailure(await valid.ValidateAsync(input), string.Join(" ", errors));
}
}
}

Просмотреть файл

@ -36,11 +36,11 @@ namespace Microsoft.AspNet.Identity.Test
Assert.Throws<ArgumentNullException>("store",
() => new RoleManager<TestRole>(null));
var manager = new RoleManager<TestRole>(new NotImplementedStore());
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Create(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Update(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.Delete(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.CreateAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.UpdateAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await manager.DeleteAsync(null));
await Assert.ThrowsAsync<ArgumentNullException>("roleName", async () => await manager.FindByName(null));
await Assert.ThrowsAsync<ArgumentNullException>("roleName", async () => await manager.RoleExists(null));
await Assert.ThrowsAsync<ArgumentNullException>("roleName", async () => await manager.RoleExistsAsync(null));
}
[Fact]
@ -48,47 +48,47 @@ namespace Microsoft.AspNet.Identity.Test
{
var manager = new RoleManager<TestRole>(new NoopRoleStore());
manager.Dispose();
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindById(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindByIdAsync(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.FindByName(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.RoleExists(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Create(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Update(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.Delete(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.RoleExistsAsync(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.CreateAsync(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.UpdateAsync(null));
await Assert.ThrowsAsync<ObjectDisposedException>(() => manager.DeleteAsync(null));
}
private class NotImplementedStore : IRoleStore<TestRole>
{
public Task Create(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task CreateAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}
public Task Update(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task UpdateAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}
public Task Delete(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
public Task DeleteAsync(TestRole role, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}
public Task<string> GetRoleId(TestRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleIdAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken())
{
throw new NotImplementedException();
}
public Task<string> GetRoleName(TestRole role, CancellationToken cancellationToken = new CancellationToken())
public Task<string> GetRoleNameAsync(TestRole role, CancellationToken cancellationToken = new CancellationToken())
{
throw new NotImplementedException();
}
public Task<TestRole> FindById(string roleId, CancellationToken cancellationToken = default(CancellationToken))
public Task<TestRole> FindByIdAsync(string roleId, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}
public Task<TestRole> FindByName(string roleName, CancellationToken cancellationToken = default(CancellationToken))
public Task<TestRole> FindByNameAsync(string roleName, CancellationToken cancellationToken = default(CancellationToken))
{
throw new NotImplementedException();
}

Просмотреть файл

@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Identity.Test
// Act
// Assert
await Assert.ThrowsAsync<ArgumentNullException>("manager", async () => await validator.Validate(null, null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await validator.Validate(manager, null));
await Assert.ThrowsAsync<ArgumentNullException>("manager", async () => await validator.ValidateAsync(null, null));
await Assert.ThrowsAsync<ArgumentNullException>("role", async () => await validator.ValidateAsync(manager, null));
}
[Theory]
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Identity.Test
var user = new TestRole {Name = input};
// Act
var result = await validator.Validate(manager, user);
var result = await validator.ValidateAsync(manager, user);
// Assert
IdentityResultAssert.IsFailure(result, "Name cannot be null or empty.");

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Identity.Test
// Act
// Assert
await Assert.ThrowsAsync<ArgumentNullException>("manager", () => validator.Validate(null, null));
await Assert.ThrowsAsync<ArgumentNullException>("user", () => validator.Validate(manager, null));
await Assert.ThrowsAsync<ArgumentNullException>("manager", () => validator.ValidateAsync(null, null));
await Assert.ThrowsAsync<ArgumentNullException>("user", () => validator.ValidateAsync(manager, null));
}
[Theory]
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Identity.Test
var user = new TestUser {UserName = input};
// Act
var result = await validator.Validate(manager, user);
var result = await validator.ValidateAsync(manager, user);
// Assert
IdentityResultAssert.IsFailure(result, "UserName cannot be null or empty.");
@ -50,7 +50,7 @@ namespace Microsoft.AspNet.Identity.Test
var user = new TestUser {UserName = userName};
// Act
var result = await validator.Validate(manager, user);
var result = await validator.ValidateAsync(manager, user);
// Assert
if (expectSuccess)
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Identity.Test
var user = new TestUser {UserName = userName};
// Act
var result = await validator.Validate(manager, user);
var result = await validator.ValidateAsync(manager, user);
// Assert
if (expectSuccess)