using System.Threading.Tasks;
namespace Microsoft.AspNet.Identity
{
///
/// TokenProvider that generates tokens from the user's security stamp and notifies a user via email.
///
/// The type used to represent a user.
public class EmailTokenProvider : TotpSecurityStampBasedTokenProvider
where TUser : class
{
///
/// Checks if a two factor authentication token can be generated for the specified .
///
/// The to retrieve the from.
/// The to check for the possibility of generating a two factor authentication token.
/// True if the user has an email address set, otherwise false.
public override async Task CanGenerateTwoFactorTokenAsync(UserManager manager, TUser user)
{
var email = await manager.GetEmailAsync(user);
return !string.IsNullOrWhiteSpace(email) && await manager.IsEmailConfirmedAsync(user);
}
///
/// Returns the a value for the user used as entropy in the generated token.
///
/// The purpose of the two factor authentication token.
/// The to retrieve the from.
/// The to check for the possibility of generating a two factor authentication token.
/// A string suitable for use as entropy in token generation.
public override async Task GetUserModifierAsync(string purpose, UserManager manager,
TUser user)
{
var email = await manager.GetEmailAsync(user);
return "Email:" + purpose + ":" + email;
}
}
}