Example #1
0
        public ActionResult Index(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "TL");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Incorrect user name or password.");
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", "Apologies! The app is down - please try again later.");
                }

            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Example #2
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                            && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return Redirect(returnUrl);
                        }
                        else
                        {
                            return RedirectToAction("Index", "TL");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "The user store is not reachable.  Please try again later.");

                    // Log error
                    LoggingHelper.TraceError("Membership.ValidateUser failed: " + ex.Message);
                }

            }

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