예제 #1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (ValidateLogOn(model.UserName, model.Password))
                {
                    // Make sure we have the username with the right capitalization
                    // since we do case sensitive checks for OpenID Claimed Identifiers later.
                    string userName = MembershipService.GetCanonicalUsername(model.UserName);

                    FormsAuth.SignIn(userName, model.RememberMe);

                    //Jamie
                    AdProvider adProvider = new AdProvider();
                    String     catagory   = adProvider.GetCatagory(userName);
                    Session["adUri"] = "/Content/images/" + catagory + ".png";

                    // Make sure we only follow relative returnUrl parameters to protect against having an open redirector
                    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.");
                }
            }
            return(View(model));
        }
예제 #2
0
        public void GetCatagoryUsingValidValue_ReturnsExpected()
        {
            String     fileUri    = "Data/nameLookup.csv";
            var        userName   = "******";
            AdProvider adProvider = new AdProvider(fileUri);
            var        actual     = adProvider.GetCatagory(userName);
            var        expected   = "MiddleAged Male";

            Assert.AreEqual(expected, actual);
        }