Пример #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                if (!ValidateAccessCode(model))
                {   // validate access code (restrict access for now)
                    ModelState.AddModelError("", "The given access code is not valid.");
                    return View(model);
                }

                // 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)
                {
                    SetAuthCookie(model.UserName, false);
                    return RedirectToAction("Initialize", "Dashboard");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // error, redisplay form
            return View(model);
        }
Пример #2
0
 private bool ValidateAccessCode(RegisterModel model)
 {
     return model.AccessCode.Equals("ZAP", StringComparison.Ordinal);
 }