public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account"); ViewBag.Message = "Check your email and confirm your account, you must be confirmed " + "before you can log in."; return View("Info"); // return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { ApplicationUser user = null; var invitation = db.Invitations.FirstOrDefault(i => i.Email == model.Email); if (invitation != null) { user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, HouseholdId = invitation.HouseholdId }; } else { db.Households.Add(new Household { Name = model.FirstName }); await db.SaveChangesAsync(); var householdId = db.Households.ToList().OrderByDescending(h => h.Id).FirstOrDefault(h => h.Name == model.FirstName).Id; user = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, HouseholdId = householdId }; PopulateCategories(householdId); } var result = await UserManager.CreateAsync(user, model.Password); await db.SaveChangesAsync(); if (result.Succeeded) { string userId = (await db.Users.FirstAsync(u => u.Email == user.Email)).Id; string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account"); ViewBag.Title = "Thank you for Signing Up!"; ViewBag.Message = "Check your email and click on the link provided to confirm your account, you must be confirmed before you can log in."; return View("Info"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }