Beispiel #1
0
        public string Login(string account, string psd)
        {
            if (account == null || psd == null)
            {
                return("0");
            }
            UserInfoContext uc = new UserInfoContext();
            UserInfo        ui = uc.CheckLogin(account, psd);

            if (ui == null)
            {
                return("0");
            }
            Session["UserId"]   = ui.ID;
            Session["UserName"] = ui.UserName;
            Session["MenuList"] = MenuHelper.GetMainMenu(ui.RoleId);
            Session["RoleId"]   = ui.RoleId;
            HttpCookie c1 = new HttpCookie("UserName");

            c1.Value   = ui.UserName;
            c1.Expires = DateTime.Now.AddHours(3);
            Response.Cookies.Add(c1);
            HttpCookie c2         = new HttpCookie("UserDepartment");
            string     department = uc.GetUserDepartment(ui.ID);

            c2.Value = department;
            Session["UserDepartment"] = department;
            c2.Expires = DateTime.Now.AddHours(3);
            Response.Cookies.Add(c2);
            HttpCookie c3 = new HttpCookie("RoleId");

            c3.Value   = ui.RoleId.ToString();
            c3.Expires = DateTime.Now.AddHours(3);
            Response.Cookies.Add(c3);
            Log l = new Log();

            l.OperType    = OperateType.Login;
            l.UserId      = ui.ID.ToString();
            l.Description = "登陆系统";
            LogContext.WriteLog(l);
            return("1");
        }