public async Task<ActionResult> Register(RegisterViewModel model) { //Check to see if we can read their profile RSS feed. If not, then id is invalid. Return to page and ask again. try { ParsedFeed profilecheck = new ParsedFeed(model.CustomerID); } catch { ViewBag.Error = "There is a problem with that Amazon Profile ID. Please check and try again."; return View("Register", model); } if (db.Customers.Where(u => u.CustomerID == model.CustomerID).Any()) { ViewBag.Error = "That Amazon Profile ID is already in use."; return View("Register", model); } if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.CustomerID, Email = model.Email, CustomerID = model.CustomerID }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { //We will not sign in customer immediately. They have to confirm email. //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); Customer customer = new Customer(); customer.Email = model.Email; customer.FirstName = model.FirstName; customer.LastName = model.LastName; customer.CustomerID = model.CustomerID; customer.LastReviewCheck = DateTime.Now; customer.JoinDate = DateTime.Now; customer.Qualified = true; db.Customers.Add(customer); db.SaveChanges(); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Email Confirmation string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); var response = SendEmailConfirmation(user.Email, callbackUrl, false); // Uncomment to debug locally // TempData["ViewBagLink"] = callbackUrl; if (model.BeSeller) { await UserManager.AddToRoleAsync(user.Id, "seller"); await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToAction("CreateSeller", "Seller"); } else { //use this for TESTING ONLY //await UserManager.AddToRoleAsync(user.Id, "campaignManager"); ////USE THIS FOR LIVE SITE await UserManager.AddToRoleAsync(user.Id, "customer"); } return RedirectToAction("Welcome", "Dashboard", new { message = "confirmmail" }); //return RedirectToAction("Welcome", "Dashboard"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; 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>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }