Ejemplo n.º 1
0
        public ActionResult Index(IndexViewModel Model, string returnUrl)
        {
            AdminManage vAdminManage = new AdminManage();
            AdminUserEF vAdminInfo   = vAdminManage.Login(Model.UserName, Model.Password);

            if (vAdminInfo.ID > 0)
            {
                /////////////////////////////////////////////////////////////////Form验证////////////////////////////////////
                Session["UserInfo"] = vAdminInfo;
                FormsAuthentication.RedirectFromLoginPage(vAdminInfo.UserName, false);
                FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, vAdminInfo.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, "Admin", "/");
                string     HashTicket            = FormsAuthentication.Encrypt(Ticket);
                HttpCookie UserCookie            = new HttpCookie(FormsAuthentication.FormsCookieName, HashTicket);
                HttpContext.Response.Cookies.Add(UserCookie);
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////
                if (returnUrl != "" && returnUrl != null)
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Main", "Admin"));
                }
            }
            else
            {
                ModelState.AddModelError("", "用户名或密码错误");
                return(View());
            }
        }
Ejemplo n.º 2
0
 // GET: Admin
 public ActionResult Main()
 {
     MainViewModel vModel = new MainViewModel();
     AdminUserEF vUserInfo = (AdminUserEF)Session["UserInfo"];
     vModel.UserName = vUserInfo.UserName;
     vModel.LoginLateTime = vUserInfo.LateLoginTime==null?DateTime.Now: vUserInfo.LateLoginTime.Value;
     UserManage vUserManage = new UserManage();
     vModel.OnlineUsersNumber = vUserManage.OnlineUsersInfo().Length;
     return View(vModel);
 }
Ejemplo n.º 3
0
        public AdminUserEF Login(string UserName, string Password)
        {
            AdminUserEF vModelEF = new AdminUserEF();

            vModelEF.UserName = UserName;
            vModelEF.Password = Password;
            AdminUserEF[] vResult = m_BasicDBClass.SelectRecordsEx(vModelEF);
            if (vResult.Length > 0)
            {
                vModelEF = vResult[0];
                vModelEF.LateLoginTime = DateTime.Now;
                m_BasicDBClass.UpdateRecord(vModelEF);
            }
            return(vModelEF);
        }
Ejemplo n.º 4
0
        public bool ChangePassword(string UserName, string OldPassword, string NewPassword)
        {
            bool        vResult  = false;
            AdminUserEF vModelEF = new AdminUserEF();

            vModelEF.UserName = UserName;
            vModelEF.Password = OldPassword;
            AdminUserEF[] vData = m_BasicDBClass.SelectRecordsEx(vModelEF);
            if (vData.Length > 0)
            {
                vModelEF          = new AdminUserEF();
                vModelEF.ID       = vData[0].ID;
                vModelEF.Password = NewPassword;
                vResult           = m_BasicDBClass.UpdateRecord(vModelEF);
            }
            else
            {
                vResult = false;
            }
            return(vResult);
        }