public ActionResult Register(RegisterWithCalculation model) {
			if (ModelState.IsValid) {
				if (new CalculatedCaptcha().ValidResult(model.Result)) {
					// Attempt to register the user
					MembershipCreateStatus createStatus;
					System.Web.Security.Membership.CreateUser(model.Username, model.Password, model.EmailAddress, null, null, true, null, out createStatus);

					if (createStatus == MembershipCreateStatus.Success) {
						FormsAuthentication.SetAuthCookie(model.Username, false /* createPersistentCookie */);
						DependencyResolver.Current.GetService<ILogger>().Log(EventType.Info, "User logged on");

						return RedirectToAction("Index", "Home");
					}
					else {
						ModelState.AddModelError("", ErrorCodeToString(createStatus));
					}
				}
				else {
					ModelState.AddModelError("", "Result not correct, please try again!");
				}
			}

			// If we got this far, something failed, redisplay form
			return View(model);
		}
Esempio n. 2
0
        public ActionResult Register(RegisterWithCalculation model)
        {
            if (ModelState.IsValid)
            {
                if (new CalculatedCaptcha().ValidResult(model.Result))
                {
                    // Attempt to register the user
                    MembershipCreateStatus createStatus;
                    System.Web.Security.Membership.CreateUser(model.Username, model.Password, model.EmailAddress, null, null, true, null, out createStatus);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsAuthentication.SetAuthCookie(model.Username, false /* createPersistentCookie */);
                        DependencyResolver.Current.GetService <ILogger>().Log(EventType.Info, "User logged on");

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Result not correct, please try again!");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }