public ActionResult Login()
        {
            var tenantConfig = EnvironmentConfig.TenantConfiguration;

            var result = TryLogin(tenantConfig);

            if (result == LoginResult.Success)
            {
                return RedirectToAction("Index", "Project");
            }
            else if (result == LoginResult.LocalLoginFailed)
            {
                return RedirectToAction("LocalLogin");
            }
            else if (result == LoginResult.ForBugzLoginFailed)
            {
                throw new ApplicationException("Invalid FogBugz credentials passed.");
            }

            var model = new LoginViewModel();
            return View(model);
        }
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            string fogBugzUrl = model.FogBugzUrl.ToLower();

            //remove backslash from end if there is one
            fogBugzUrl = fogBugzUrl.TrimEnd(new[] { '/' });

            if (!LoginUtils.LoginToFogBugz(fogBugzUrl, model.FogBugzUsername, model.FogBugzPassword))
            {
                model.ErrorMessage = "Login to FogBugz failed for given url, username and password.";
                return View(model);
            }

            FogBugzClient.LogOn(fogBugzUrl + "/api.asp", model.FogBugzUsername, model.FogBugzPassword);

            return RedirectToAction("Index", "Home");
        }