public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, RegistrationDate = DateTime.UtcNow }; IdentityResult result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInAsync(user, isPersistent : 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>"); // Register user to Stripe await SubscriptionsFacade.SubscribeUserAsync(user, model.SubscriptionPlan.ToLower()); await UserManager.UpdateAsync(user); return(RedirectToAction("Index", "Home")); } else { 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 userIP = GeoLocation.GetUserIP(Request).Split(':').First(); var user = new ApplicationUser { UserName = model.Email, Email = model.Email, RegistrationDate = DateTime.UtcNow, LastLoginTime = DateTime.UtcNow, IPAddress = userIP, IPAddressCountry = GeoLocationHelper.GetCountryFromIP(userIP), BillingAddress = new BillingAddress() }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { // Create Stripe user var taxPercent = user.IPAddressCountry != null && EuropeanVat.Countries.ContainsKey(user.IPAddressCountry) ? EuropeanVat.Countries[user.IPAddressCountry] : 0; // if no plan set, default to professional var planId = string.IsNullOrEmpty(model.SubscriptionPlan) ? "professional_monthly" : model.SubscriptionPlan; await SubscriptionsFacade.SubscribeUserAsync(user, planId, taxPercent : taxPercent); await UserManager.UpdateAsync(user); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); await UserManager.EmailService.SendWelcomeEmail(user.UserName, user.Email); TempData["flash"] = new FlashSuccessViewModel("Congratulations! Your account has been created."); return(RedirectToAction("Index", "Notes")); } 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, RegistrationDate = DateTime.UtcNow, LastLoginTime = DateTime.UtcNow }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (string.IsNullOrWhiteSpace(model.SubscriptionPlan)) { model.SubscriptionPlan = "basic_monthly"; } await SubscriptionsFacade.SubscribeUserAsync(user, model.SubscriptionPlan, 0, model.CreditCard); await CardService.AddAsync(user, model.CreditCard); await UserManager.UpdateAsync(user); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); 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)); }