public ActionResult ConfirmRegistration(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user try { string licenseId = Request.Form["LicenseId"]; Customer customer = Uow.Customers.Where(cs => cs.LicenseId == licenseId).FirstOrDefault(); if (customer == null) throw new ApplicationException("Invalid license id"); if (customer.Registered) throw new ApplicationException("Already registered"); WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); Roles.AddUserToRole(model.UserName, RoleNames.CUSTOMER); Uow.UserCustomerMapping.Add(new UserCustomerMapping { CustomerId = customer.Id, Username = model.UserName }); customer.Registered = true; Uow.Customers.Update(customer); Uow.Commit(); return RedirectToAction("Index", "Branch"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } catch (Exception ex) { ModelState.AddModelError("", ex.GetInnerMostException().Message); } } // 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 try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password); WebSecurity.Login(model.UserName, model.Password); return RedirectToAction("Index", "Home"); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }