public ActionResult LogOn(LogOnModel model)
 {
     if (ModelState.IsValid)
     {
         if (MembershipService.ValidateUser(model.UserName, model.Password))
         {
             var user = userRepository.GetUserByUsername(model.UserName);
             if (user.CreationDate == user.LastPasswordChangedDate && !user.IsGeneric)
             {
                 TempData["username"] = model.UserName;
                 TempData["password"] = model.Password;
                 TempData["rememberme"] = model.RememberMe;
                 model.Url = Url.Action("FirstLogOn", "Account");
                 return PartialView("LogOnContainer", model);
             }
             if ((user.Roles.Contains(roleRepository.GetRoleByName("Poll Administrator")) && DateTime.Now < user.AccountExpiryDate) ||
                 (!user.Roles.Contains(roleRepository.GetRoleByName("Poll Administrator"))))
             {
                 FormsService.SignIn(model.UserName, model.RememberMe);
             }
             else
             {
                 ModelState.AddModelError("", "Error, that account has expired");
                 return PartialView("LogOnContainer", model);
             }
             if (IsLocalUrl(model.ReturnUrl))
             {
                 model.Url = model.ReturnUrl;
                 return PartialView("LogOnContainer", model);
             }
             else
             {
                 model.Url = GetRedirectURL(model.UserName);
                 return PartialView("LogOnContainer", model);
             }
         }
         else
         {
             ModelState.AddModelError("", "The current password is incorrect or the username is invalid.");
         }
     }
     return View("LogOnContainer", model);
 }
        public ActionResult LogOn()
        {
            if (User.Identity.IsAuthenticated)
                return Redirect(GetRedirectURL(User.Identity.Name));

            var model = new LogOnModel();
            if (Request.QueryString["ReturnUrl"] != null)
                model.ReturnUrl = Request.QueryString["ReturnUrl"];
            return View(model);
        }