internal void SendRegistrationConfirmationEmail(RegisterModel model) { MailMessage message = new MailMessage(); message.IsBodyHtml = true; message.Subject = "New User Registration for ETC Canada"; message.Body = this.GetRegisterNotificationToAdminEmailBody(model); message.To.Add(new MailAddress(WebSettings.AdminEmail)); EmailHandler emailHandler = new EmailHandler(message); Thread thread = new Thread(new ThreadStart(emailHandler.SendEmail)); thread.Start(); }
public async Task<IdentityResult> RegisterUserAsync(RegisterModel registerModel) { IdentityResult result; ApplicationUser appUser = ApplicationUserMapper.ToApplicationUserEntity(registerModel); result = await IdentityManagers.UserManager.CreateAsync(appUser, registerModel.Password); if (result.Succeeded) { result = await IdentityManagers.UserManager.AddToRoleAsync(appUser.Id, "User"); } return result; }
internal static ApplicationUser ToApplicationUserEntity(RegisterModel registerModel) { return new ApplicationUser { Email = registerModel.Email, UserName = registerModel.Email, AddressLine1 = registerModel.AddressLine1, AddressLine2 = registerModel.AddressLine2, City = registerModel.City, Country = registerModel.Country, FirstName = registerModel.FirstName, LastName = registerModel.LastName, Phone = registerModel.Phone, PostalCode = registerModel.PostalCode, State = registerModel.State, IsApproved = false, FirstNameInTamil = registerModel.FirstNameInTamil, LastNameInTamil = registerModel.LastNameInTamil }; }
private string GetRegisterNotificationToAdminEmailBody(RegisterModel model) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Registered user details"); sb.AppendLine(string.Format("Email - {0}", model.Email)); sb.AppendLine(); sb.AppendLine(string.Format("First name - {0}", model.FirstName)); sb.AppendLine(); sb.AppendLine(string.Format("Last name - {0}", model.LastName)); sb.AppendLine(); return sb.ToString(); }
public async Task<ActionResult> CreateUser(CreateUserModel model) { ViewBag.CountryList = commonBPL.GetCountrySelectList(); if (ModelState.IsValid) { RegisterModel registerModel = new RegisterModel { FirstName = model.FirstName, LastName = model.LastName, IsApproved = false, Email = model.Email, Password = model.Password, FirstNameInTamil = model.FirstNameInTamil, LastNameInTamil = model.LastNameInTamil }; IdentityResult result = await accountBPL.RegisterUserAsync(registerModel).ConfigureAwait(false); if (result.Succeeded) { // EmailSender emailSender = new EmailSender(); // emailSender.SendRegistrationConfirmationEmail(model); // 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>"); ViewBag.Message = "Success"; return View(); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
public async Task<IdentityResult> RegisterUserAsync(RegisterModel registerModel) { IdentityResult result = await accountRepo.RegisterUserAsync(registerModel).ConfigureAwait(false); return result; }