public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; Membership.CreateUser(model.Email, model.Password, model.Email, null, null, false, null, out createStatus); if (createStatus == MembershipCreateStatus.Success) { MembershipUser account = Membership.GetUser(model.Email); User user = new User(); user.Email = account.Email; user.RegistrationDate = account.CreationDate; user.PaymentId = Guid.NewGuid().ToString("N"); user.ActivationKey = Guid.NewGuid().ToString("N"); if (ModelState.IsValid) { DatabaseContext db = new DatabaseContext(); db.Users.Add(user); db.SaveChanges(); Roles.AddUserToRole(account.Email, "User"); WebMail.SmtpServer = "smtp.gmail.com"; WebMail.EnableSsl = true; WebMail.SmtpPort = 587; WebMail.UserName = "******"; WebMail.Password = "******"; WebMail.Send( account.Email, "Aktywacja konta na Streameo", "Witaj!<br /><br />" + "Kliknij w poniższy link aby aktywować konto.<br /><br />" + "<a href=\"" + Url.Action("Activate", "Account", new { key = user.ActivationKey }, Request.Url.Scheme) + "\">Aktywacja</a>" ); } else { Membership.DeleteUser(account.Email); } //FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */); return RedirectToAction("RegisterSuccess", "Account"); } else { ModelState.AddModelError("", ErrorCodeToString(createStatus)); } } // If we got this far, something failed, redisplay form return View(model); }