예제 #1
0
        /// <summary>
        /// 返回编辑用户信息的的json格式
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public string EditUserInfoToJson(Web_User user)
        {
            StringBuilder Json = new StringBuilder();
            StringWriter sw = new StringWriter(Json);
            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {

                jsonWriter.Formatting = Formatting.Indented;

                jsonWriter.WriteStartObject();
                jsonWriter.WritePropertyName("LOGNAME");
                jsonWriter.WriteValue(user.LOGNAME);
                jsonWriter.WritePropertyName("REALNAME");
                jsonWriter.WriteValue(user.REALNAME);
                jsonWriter.WritePropertyName("USERGROUPID");
                jsonWriter.WriteValue(user.GROUP.Group_ID);
                //jsonWriter.WritePropertyName("USERGROUP");
                //jsonWriter.WriteValue(user.GROUP.USERGROUP);
                jsonWriter.WritePropertyName("STATE");
                jsonWriter.WriteValue(user.STATE);
                jsonWriter.WritePropertyName("MEMO");
                jsonWriter.WriteValue(user.MEMO);
                jsonWriter.WritePropertyName("id");
                jsonWriter.WriteValue(user.ID);
                jsonWriter.WriteEndObject();

            }
            return Json.ToString();
        }
예제 #2
0
        public void DealLogin()
        {
            string LoginIp = Request.UserHostAddress;//获取用户ip地址
            string checkcode = Request["vdcode"];
            Web_User user = new Web_User();
            try
            {
                user.LOGNAME = Request["username"];
                user.PASSWORD = Request["userpass"];
                string sUser = Convert.ToString(Cache.Get(user.LOGNAME));
                if (Session["checkcode"].ToString().Equals(checkcode))
                {
                    int groupID = new Web_UserBLL().IsLogin(user);
                    if (groupID > 0)
                    {
                        //这里要判断单点登录的情况
                        if (sUser == null || sUser == string.Empty)
                        {
                            TimeSpan SessTimeOut = new TimeSpan(0, 0, 1, 0, 0);//取得Session的过期时间System.Web.HttpContext.Current.Session.Timeout(这里设置为1分钟)
                            Cache.Insert(user.LOGNAME, user.LOGNAME, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable);//将值放入cache以方便单点登录
                            user.GROUP = new Web_UserGroup();
                            user.GROUP.Group_ID = groupID;
                            Session["User"] = user;
                            new SystemLogBLL().SaveSystemLog("登录成功!");

                            for (int i = 0; i < 1000; i++)
                            {
                                logger.Info(user.LOGNAME + " Test Log File");
                            }

                            logger.Info("用户: " + user.LOGNAME + " 登录成功!");
                            //  WriteSysLog log = new WriteSysLog();
                            // log.WriteSystemLog(LoginIp+"于"+DateTime.Now.ToString ()+"以"+user.LOGNAME+"帐号登录系统");
                            RedirectToAction("Main", "Home");
                        }
                        else if (Cache.Get(sUser).ToString() == user.LOGNAME)//如果这个账号已经登录
                        {
                            JScript.Alert("该用户已登录!!");
                        }
                        else
                        {
                            Session.Abandon();//这段主要是为了避免不必要的错误导致不能登录
                        }
                    }
                    else
                    {
                        JScript.Alert("帐号或密码错误,或者用户组被禁用!");
                    }
                }
                else
                    JScript.AlertAndRedirect("验证码出错!!","/Admin/Home/Login");
            }
            catch (Exception ex)
            {
                logger.Error("登录出错!登录ip:" + LoginIp + "登录时间:" + DateTime.Now.ToString(), ex);

                JScript.Alert("系统出错!");
            }
        }
예제 #3
0
 public bool AddNew(Web_User model, RogerContext dbParm = null)
 {
     try
     {
         if (dbParm == null)
         {
             dbParm = db;
         }
         dbParm.Web_Users.Add(model);
         dbParm.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #4
0
 /// <summary>
 /// 更新用户权限信息
 /// </summary>
 /// <param name="context"></param>
 public void UpdateUserInfo()
 {
     Web_User user = new Web_User();
     string id = Request["id"];
     string state = Request["state"];
     if (Tools.IsValidInput(ref id, true) && Tools.IsValidInput(ref state, true))
     {
         user.ID = Convert.ToInt32(id);
         user.STATE = (state == "1" ? "0" : "1");//这里要反向操作
         userBLL.UpdateState(user);
     }
 }
예제 #5
0
        public void SaveUserInfo()
        {
            //用户json数据读取
            //数据为[{"LOGNAME":"tianzh","USERGROUPID":"1","PASSWORD":"******","REALNAME":"tianzhuanghu","MEMO":"tianzhuanghu"}]
            String UserInfoStr = Request["UserInfo"];
            //System.IO.StreamWriter sw = new System.IO.StreamWriter(context.Server.MapPath("tzh.txt"));
            //sw.Write(UserInfoStr);
            //sw.Close();
            //使用Newtonsoft.Json.dll组件解析json对象
            //首先过滤掉json中的[和]
            string info = UserInfoStr.TrimStart('[');
            info = info.TrimEnd(']');
            JObject o = JObject.Parse(info);
            string LOGNAME = (string)o.SelectToken("LOGNAME");
            string USERGROUPID = (string)o.SelectToken("USERGROUPID");
            string PASSWORD = (string)o.SelectToken("PASSWORD");
            string REALNAME = (string)o.SelectToken("REALNAME");
            string MEMO = (string)o.SelectToken("MEMO");

            //保存用户数据的model对象
            Web_User user = new Web_User();
            //  //对象的赋值
            user.LOGNAME = LOGNAME;

            //Group需要特殊处理,从数据库中取出
            Web_UserGroup group = groupBLL.Get(Convert.ToInt32(USERGROUPID), dbParm);
            user.GROUP = group;
            user.PASSWORD = PASSWORD;
            user.REALNAME = REALNAME;
            user.MEMO = MEMO;
            user.REG_DATE = DateTime.Now;
            user.LAST_LOG_DATE = DateTime.Now;
            user.LOG_TIMES = 0;
            user.STATE = "0";
            if (o.SelectToken("id") != null)
            {
                user.ID = (int)o.SelectToken("id");
                userBLL.Update(user, dbParm);
            }
            else
            {
                userBLL.AddNew(user, dbParm);
            }
        }
예제 #6
0
 /// <summary>
 /// 登录验证,返回用户组Id信息
 /// </summary>
 /// <param name="user">用户实体</param>
 /// <returns>返回用户组信息</returns>
 public int IsLogin(Web_User user)
 {
     try
     {
         return db.Web_Users.Include("GROUP").First(s => s.LOGNAME == user.LOGNAME && s.PASSWORD == user.PASSWORD && s.STATE == "1").GROUP.Group_ID;
     }
     catch
     {
         return 0;
     }
 }
예제 #7
0
 /// <summary>
 /// 更新状态信息
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool UpdateState(Web_User user)
 {
     try
     {
         db.Web_Users.First(s => s.ID == user.ID).STATE = user.STATE;
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #8
0
 public int Update(Web_User model, RogerContext dbParm = null)
 {
     return base.Update<Web_User>(model, model.ID, dbParm);
     //if (dbParm == null)
     //{
     //    dbParm = db;
     //}
     //dbParm.Entry(model).State = System.Data.EntityState.Modified;
     //return dbParm.SaveChanges();
 }
예제 #9
0
        public string DealMenu()
        {
            //优化:此处取session中存的user
            //(WEB_USER)context.Session["User"]
            Web_User user = new Web_User();
            user.LOGNAME = "tianzhuanghu";
            user.PASSWORD = "******";
            user.GROUP = new Web_UserGroup();
            user.GROUP.Group_ID = 1;

            return new Web_UserBLL().GetMenuByJson(user);
        }
예제 #10
0
 /// <summary>
 /// 增加WEB_USER
 /// </summary>
 /// <param name="model">tableName实体</param>
 /// <returns>执行状态</returns>
 public bool AddNew(Web_User model, RogerContext dbParm)
 {
     return dal.AddNew(model, dbParm);
 }
예제 #11
0
 /// <summary>
 /// 更新状态信息
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool UpdateState(Web_User user)
 {
     return dal.UpdateState(user);
 }
예제 #12
0
 /// <summary>
 /// 更新WEB_USER实体
 /// </summary>
 /// <param name="model">tableName实体</param>
 /// <returns>执行状态</returns>
 public int Update(Web_User model, RogerContext dbParm)
 {
     return dal.Update(model, dbParm);
 }
예제 #13
0
 /// <summary>
 /// 登录验证,返回用户组信息
 /// </summary>
 /// <param name="user">用户实体</param>
 /// <returns>返回用户组信息</returns>
 public int IsLogin(Web_User user)
 {
     int num = 0;
     num = dal.IsLogin(user);
     return num;
 }
예제 #14
0
        /// <summary>
        /// 获取后台首页菜单数据(格式为json)
        /// </summary>
        /// <param name="user">user的model实体</param>
        /// <returns></returns>
        public string GetMenuByJson(Web_User user)
        {
            //这里要获取功能表中,一级菜单
            IEnumerable<Web_Sys_Function> functions = new Web_Sys_FunctionDAL().ListAllTopMenu();
            List<Web_Sys_Function> userGroupFunctions = new Web_UserGroupDAL().GetUserGroupFunction(user.GROUP.Group_ID);
            StringBuilder Json = new StringBuilder();
            StringWriter sw = new StringWriter(Json);
            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteStartArray();
                foreach (Web_Sys_Function funtion in functions)
                {
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName("id");
                    jsonWriter.WriteValue(funtion.ID);
                    jsonWriter.WritePropertyName("text");
                    jsonWriter.WriteValue(funtion.NAME);
                    jsonWriter.WritePropertyName("expanded");
                    jsonWriter.WriteValue("false");
                    jsonWriter.WritePropertyName("children");//接下来是一个集合
                    jsonWriter.WriteStartArray();
                    foreach (Web_Sys_Function func in userGroupFunctions)
                    {
                        if ((int)func.FATHER_ID == funtion.ID)
                        {

                            jsonWriter.WriteStartObject();
                            jsonWriter.WritePropertyName("id");
                            jsonWriter.WriteValue(func.FATHER_ID.ToString());
                            jsonWriter.WritePropertyName("url");
                            jsonWriter.WriteValue(func.URL);
                            jsonWriter.WritePropertyName("text");
                            jsonWriter.WriteValue(func.NAME);
                            jsonWriter.WritePropertyName("expanded");
                            jsonWriter.WriteValue("false");
                            jsonWriter.WriteEndObject();
                        }
                    }
                    jsonWriter.WriteEndArray();
                    jsonWriter.WriteEndObject();
                }
                jsonWriter.WriteEndArray();
            }
            return Json.ToString();
        }