Exemple #1
0
        public ActionResult AdministratorLogOn(AdministratorLogOnModel model, string returnUrl)
        {
            ICardHolderService CardHolderService;

            if (ModelState.IsValid)
            {
                try
                {
                    CardHolderService = new CardHolderService();
                    if (CardHolderService.ValidateUser(model.UserName, model.Password))
                    {
                        if (Roles.IsUserInRole(model.UserName, "SystemAdministrator"))
                        {
                            TempData["User"] = model.UserName;
                            Log.LoginAttempts(Request.UserHostAddress, model.UserName, true);
                            return(RedirectToAction("Administrator2ndLogOn", "Account"));
                        }
                        if (Roles.IsUserInRole(model.UserName, "ClientAdministrator"))
                        {
                            FormsAuthentication.SetAuthCookie(model.UserName, false); //model.RememberMe);
                            Log.LoginAttempts(Request.UserHostAddress, model.UserName, true);
                            return(RedirectToAction("ClientAdminIndex", "Administration"));
                        }
                        if (Roles.IsUserInRole(model.UserName, "Agent"))
                        {
                            FormsAuthentication.SetAuthCookie(model.UserName, false); //model.RememberMe);
                            Log.LoginAttempts(Request.UserHostAddress, model.UserName, true);
                            return(RedirectToAction("AgentIndex", "Administration"));
                        }
                        ModelState.AddModelError("", "That user name is not an administrator.");
                        Log.LoginAttempts(Request.UserHostAddress, model.UserName, false);
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                        Log.LoginAttempts(Request.UserHostAddress, model.UserName, false);
                    }
                }
                catch (Exception Ex)
                {
                    ModelState.AddModelError("", Common.StandardExceptionHandler(Ex, "Admin Log In", Request.Form));
                }
            }
            System.Threading.Thread.Sleep(1000);  // force a one second delay for security purposes
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemple #2
0
 public ActionResult Administrator2ndLogOn()
 {
     try
     {
         AdministratorLogOnModel ToShow = new AdministratorLogOnModel();
         ToShow.UserName = (string)TempData["User"];
         if (ToShow.UserName == null)
         {
             ToShow.UserName = "******";
         }
         return(View(ToShow));
     }
     catch (Exception Ex)
     {
         ViewBag.ErrorMessage = Common.StandardExceptionErrorMessage(Ex);
         return(RedirectToAction("ViewErrorMessage", "Administration"));
     }
     //return RedirectToAction("Index", "Home");
 }
Exemple #3
0
        public ActionResult Administrator2ndLogOn(AdministratorLogOnModel model)
        {
            ICardHolderService CardHolderService;

            if (ModelState.IsValid)
            {
                try
                {
                    CardHolderService = new CardHolderService();
                    if (CardHolderService.ValidateUser("secondPassword", model.Password))
                    {
                        if (Roles.IsUserInRole(model.UserName, "SystemAdministrator"))
                        {
                            Log.LoginAttempts(Request.UserHostAddress, model.UserName, true);
                            FormsAuthentication.SetAuthCookie(model.UserName, false); //model.RememberMe);
                            Session["ReturnStack"] = new Stack <String>();
                            return(RedirectToAction("Index", "Administration"));
                        }
                    }
                    if (CardHolderService.ValidateUser(model.UserName + "SecondPassword", model.Password))
                    {
                        if (Roles.IsUserInRole(model.UserName, "SystemAdministrator"))
                        {
                            Log.LoginAttempts(Request.UserHostAddress, model.UserName, true);
                            FormsAuthentication.SetAuthCookie(model.UserName, false); //model.RememberMe);
                            Session["ReturnStack"] = new Stack <String>();
                            return(RedirectToAction("Index", "Administration"));
                        }
                    }
                    Log.LoginAttempts(Request.UserHostAddress, model.UserName, false);
                    ModelState.AddModelError("", "Sorry, no go.");
                    System.Threading.Thread.Sleep(1000);  // force a one second delay for security purposes
                }
                catch (Exception Ex)
                {
                    ModelState.AddModelError("", Common.StandardExceptionErrorMessage(Ex));
                }
            }

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