Esempio n. 1
0
 private bool ValidateAccessCode(RegisterModel model)
 {
     return model.AccessCode.StartsWith("ZAP", StringComparison.OrdinalIgnoreCase);
 }
Esempio n. 2
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);
                    // add a cookie indicating the user is recognized (this will redirect existing users to signin page)
                    Response.Cookies.Add(new HttpCookie(ExistingUserCookie));
                    return RedirectToAction("Initialize", "Dashboard");
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // error, redisplay form
            return View(model);
        }