Пример #1
0
        public ActionResult LogOn(LogonRegisterModel model, string returnUrl)
        {
            var logonModel = model.LogonModel;
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(logonModel.UserName, logonModel.Password))
                {
                    FormsAuthentication.SetAuthCookie(logonModel.UserName, false);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View("LogonRegister", model);
        }
Пример #2
0
        public ActionResult Register(LogonRegisterModel model, string returnUrl)
        {
            var registerModel = model.RegisterModel;
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                MembershipCreateStatus createStatus;
                Membership.CreateUser(registerModel.UserName, registerModel.Password, registerModel.Email, "What is your favourite childhood memory?", registerModel.SecurityAnswer, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    FormsAuthentication.SetAuthCookie(registerModel.UserName, false /* createPersistentCookie */);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                       && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return View("LogonRegister", model);
        }
Пример #3
0
 public ActionResult LogOn(string returnUrl)
 {
     var model = new LogonRegisterModel();
     model.ReturnUrl = returnUrl;
     return View("LogonRegister", model);
 }