diff --git a/src/Microsoft.AspNet.Identity/UserManager.cs b/src/Microsoft.AspNet.Identity/UserManager.cs index fae4cc5edf..a40f1213ed 100644 --- a/src/Microsoft.AspNet.Identity/UserManager.cs +++ b/src/Microsoft.AspNet.Identity/UserManager.cs @@ -5,12 +5,10 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Runtime.CompilerServices; using System.Security.Claims; using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Logging; @@ -24,6 +22,9 @@ namespace Microsoft.AspNet.Identity /// The type encapsulating a user. public class UserManager : IDisposable where TUser : class { + protected const string ResetPasswordTokenPurpose = "ResetPassword"; + protected const string ConfirmEmailTokenPurpose = "EmailConfirmation"; + private readonly Dictionary> _tokenProviders = new Dictionary>(); @@ -203,7 +204,8 @@ namespace Microsoft.AspNet.Identity /// /// true if the backing user store supports user emails, otherwise false. /// - public virtual bool SupportsUserEmail + public virtual bool SupportsUserEmail + { get { @@ -720,7 +722,7 @@ namespace Microsoft.AspNet.Identity public virtual Task GeneratePasswordResetTokenAsync(TUser user) { ThrowIfDisposed(); - return GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword"); + return GenerateUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, ResetPasswordTokenPurpose); } /// @@ -743,7 +745,7 @@ namespace Microsoft.AspNet.Identity } // Make sure the token is valid and the stamp matches - if (!await VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, "ResetPassword", token)) + if (!await VerifyUserTokenAsync(user, Options.Tokens.PasswordResetTokenProvider, ResetPasswordTokenPurpose, token)) { return IdentityResult.Failed(ErrorDescriber.InvalidToken()); } @@ -1265,7 +1267,7 @@ namespace Microsoft.AspNet.Identity public virtual Task GenerateEmailConfirmationTokenAsync(TUser user) { ThrowIfDisposed(); - return GenerateUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation"); + return GenerateUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, ConfirmEmailTokenPurpose); } /// @@ -1286,7 +1288,7 @@ namespace Microsoft.AspNet.Identity throw new ArgumentNullException("user"); } - if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, "EmailConfirmation", token)) + if (!await VerifyUserTokenAsync(user, Options.Tokens.EmailConfirmationTokenProvider, ConfirmEmailTokenPurpose, token)) { return IdentityResult.Failed(ErrorDescriber.InvalidToken()); } @@ -1324,7 +1326,7 @@ namespace Microsoft.AspNet.Identity public virtual Task GenerateChangeEmailTokenAsync(TUser user, string newEmail) { ThrowIfDisposed(); - return GenerateUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail)); + return GenerateUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailTokenPurpose(newEmail)); } /// @@ -1346,7 +1348,7 @@ namespace Microsoft.AspNet.Identity } // Make sure the token is valid and the stamp matches - if (!await VerifyUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailPurpose(newEmail), token)) + if (!await VerifyUserTokenAsync(user, Options.Tokens.ChangeEmailTokenProvider, GetChangeEmailTokenPurpose(newEmail), token)) { return IdentityResult.Failed(ErrorDescriber.InvalidToken()); } @@ -2042,7 +2044,12 @@ namespace Microsoft.AspNet.Identity } - private static string GetChangeEmailPurpose(string newEmail) + /// + /// Generates the token purpose used to change email + /// + /// + /// + protected static string GetChangeEmailTokenPurpose(string newEmail) { return "ChangeEmail:" + newEmail; }