Example #1
0
 public ActionResult PostLogin(LoginModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Username == "admin" || model.Password == "icb@123456")
         {
             SessionApp.Username = "******";
             SessionApp.Email    = "";
             SessionApp.IsLogin  = true;
             SessionApp.Role     = "0";
             SessionApp.RoleType = 0;
             SessionApp.Fullname = "admin";
             SessionApp.UserID   = 0;
             return(Redirect(Url.Action("Index", "Dashboard", new { area = "admin" })));
         }
         else
         {
             AccountProvider provider = new AccountProvider();
             Account         account  = provider.SignIn(model.Username, model.Password);
             if (account == null)
             {
                 ModelState.AddModelError("loginError", MessageManager.GetErrorMessage(ModuleType.Login, MessageType.Login_Failed));
             }
             else
             {
                 SessionApp.Username = account.Username;
                 SessionApp.Email    = account.Email;
                 SessionApp.IsLogin  = true;
                 SessionApp.Role     = account.Role.ToString();
                 SessionApp.RoleType = account.Role;
                 SessionApp.Fullname = account.Fullname;
                 SessionApp.UserID   = account.ID;
                 return(Redirect(Url.Action("Index", "Home")));
             }
         }
     }
     else
     {
         ModelState.AddModelError("loginError", MessageManager.GetErrorMessage(ModuleType.Login, MessageType.Login_ModelFailed));
     }
     return(View("Login", model));
 }