Пример #1
0
        public ActionResult Register(RegisterModel model)
        {
            if(ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                System.Web.Security.Membership.CreateUser(model.UserName, model.Password, model.Email, model.FullName, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);

                if(createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, createPersistentCookie: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #2
0
 public ActionResult RegisterHome(RegisterHomeModel model)
 {
     if(model == null)
         model = new RegisterHomeModel();
     var registerModel = new RegisterModel
                             {
                                 Email = model.Email ?? String.Empty,
                                 UserName = Regex.Replace(model.Name ?? String.Empty, "[^0-9A-Za-z]", ""),
                                 Password = model.PasswordFinal ?? String.Empty,
                                 FullName = model.Name ?? String.Empty
                             };
     return View("Register", registerModel);
 }
Пример #3
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            ViewData["PasswordLength"] = MembershipService.MinPasswordLength;
            return View(model);
        }