void IAccountService.NewRegistration(RegisterModel model) { string token = webSecurityService.CreateUserAndAccount(model.UserName, model.Password, null, true); model.VerifyUrl = "/Account/Verify/" + token; CreatePersonForNewUser(model); this.emailHelper.SendSignupMail(model.UserName, model.Email, model.UserName, model.VerifyUrl); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { //try to add UserId with Guid but there is conflict with limitation of simple membership, it cant //using Guid as key, he just can use Int //_userService.Add(new User() //{ // UserName = model.UserName, // Email = model.Email, // UserId = Guid.NewGuid(), // FirstName = model.FirstName, // LastName = model.LastName //}); //_webSecurityService.CreateAccount(model.UserName, model.Password); _webSecurityService.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName }); _webSecurityService.Login(model.UserName, model.Password); return(RedirectToAction("Index", "Home")); } return(View(model)); }
private static void SeedMembershipData(IWebSecurityService webSecurity) { if (!Roles.RoleExists(Constants.AdministratorsRoleName)) { Roles.CreateRole(Constants.AdministratorsRoleName); } if (!webSecurity.UserExists("Admin")) { // TODO: Make sure password reset functionality works. webSecurity.CreateUserAndAccount("Admin", "admin", new { Email = "*****@*****.**" }); Roles.AddUserToRole("Admin", Constants.AdministratorsRoleName); } }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user var requireEmailConfirmation = Convert.ToBoolean(ConfigurationManager.AppSettings["requireEmailConfirmation"] ?? "false"); var token = webSecurity.CreateUserAndAccount(model.UserName, model.Password, requireConfirmationToken: requireEmailConfirmation); if (requireEmailConfirmation) { // Send email to user with confirmation token if (Request.Url != null) { string hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped); string confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token)); const string fromAddress = "Your Email Address"; var toAddress = model.Email; const string subject = "Thanks for registering but first you need to confirm your registration..."; var body = string.Format( "Your confirmation code is: {0}. Visit <a href=\"{1}\">{1}</a> to activate your account.", token, confirmationUrl); // NOTE: This is just for sample purposes // It's generally a best practice to not send emails (or do anything on that could take a long time and potentially fail) // on the same thread as the main site // You should probably hand this off to a background MessageSender service by queueing the email, etc. messengerService.Send(fromAddress, toAddress, subject, body, true); } // Thank the user for registering and let them know an email is on its way return(RedirectToAction("Thanks", "Account")); } // Navigate back to the homepage and exit webSecurity.Login(model.UserName, model.Password); return(RedirectToAction("Index", "Home")); } // If we got this far, something failed, redisplay form ViewBag.PasswordLength = webSecurity.MinPasswordLength; return(View(model)); }
private static void SeedMembershipData(IWebSecurityService webSecurity) { if (!Roles.RoleExists(Constants.AdministratorsRoleName)) { Roles.CreateRole(Constants.AdministratorsRoleName); } if (!webSecurity.UserExists("Admin")) { // TODO: Make sure password reset functionality works. webSecurity.CreateUserAndAccount("Admin", GenerateRandomPassword(), new { Email = "*****@*****.**" }); Roles.AddUserToRole("Admin", Constants.AdministratorsRoleName); } }