Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot ConfirmEmail with new 2.0 #31

Open
jakvike opened this issue Apr 28, 2014 · 2 comments
Open

Cannot ConfirmEmail with new 2.0 #31

jakvike opened this issue Apr 28, 2014 · 2 comments

Comments

@jakvike
Copy link

jakvike commented Apr 28, 2014

I am attempting to ConfirmEmail. I have implemented Registration but when i confirm the email, I receive 'Cannot set the confirmation status of the e-mail because user doesn't have an e-mail as RavenUserEmail document.'

I then attempted to extend RavenUser by creating a new class that inherits from RavenUser. Within this class i have a property RavenUserEmail and create it when I create the RavenUser within the Registration. When i attempt to Confirm the email, I receive an error 'Cannot set the confirmation status of the e-mail because user doesn't have an e-mail.'

This is the code within my AccountController:

// GET: /Account/ConfirmEmail
[AllowAnonymous]
public async Task ConfirmEmail(string userId, string code)
{
var result = await UserManager.ConfirmEmailAsync(userId, code);
return View();
}

@Chaddeus
Copy link

Chaddeus commented Jun 6, 2014

I get the same exact error.

I initialize my IAsyncDocumentSession like so:

ravenSession.Advanced.UseOptimisticConcurrency = true;
RavenSession = ravenSession;

var provider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("Example");
UserManager = new UserManager<ApplicationUser>(new RavenUserStore<ApplicationUser>(ravenSession))
{
    UserTokenProvider =
        new Microsoft.AspNet.Identity.Owin.DataProtectorTokenProvider<ApplicationUser>(
            provider.Create("EmailConfirmation"))
};

A new user is created like so:

var user = new ApplicationUser(model.UserName) {
    DateRegistered = DateTime.UtcNow,
    DateLastConnected = DateTime.UtcNow
};
user.SetEmail(model.Email);

var result = await UserManager.CreateAsync(user, model.Password);

I generate the email with callback url to confirm email like so:

var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code }, Request.Url.Scheme);

SendVerificationEmail(user, callbackUrl);

The SendVerification() method is simply a wrapper, I use Mandrill to send my emails. The callback url is created fine, and the email is received by users fine too.

However, when a user clicks the callback url, they get the following error:

Cannot set the confirmation status of the e-mail because user doesn't have an e-mail as RavenUserEmail document.

The code to verify email is quite simple:

var result = await UserManager.ConfirmEmailAsync(userId, code);

if (result.Succeeded)
    return View("ConfirmEmail");

@Chaddeus
Copy link

Chaddeus commented Jun 9, 2014

Got some time to dig into this... turns out you need to create the RavenUserEmail yourself. In your AccountController,when you register a user, create the RavenUserEmail at the same time:

var email = new RavenUserEmail(user.Email, user.Id);
await RavenSession.StoreAsync(email);
await RavenSession.SaveChangesAsync();

Keep in mind that when/if you need to delete a user, you'll need to delete the RavenUserEmail document too.

*** Perhaps this should be handled by the CreateAsync() and DeleteAsync() methods?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants