示例#1
0
        //[SupportFilter]
        public ActionResult Edit(int id, SMUSERTB entity)
        {
            if (entity != null && ModelState.IsValid)
            {
                entity.UPDATE_USER = GetCurrentAccount().USER_ID;
                string returnValue = string.Empty;
                SMLOG  _SMLOG      = new SMLOG {
                    OPERATION_TYPE = "U", FUNC_CODE = "010702", USER_ID = Convert.ToInt32(GetCurrentAccount().USER_ID), CLASSNAME = this.GetType().ToString() + ": Edit"
                };
                List <int> oldRoleIds = entity.SysRoleIdOld.GetIdSort();
                List <int> roleIds    = entity.SysRoleId.GetIdSort();

                if (SMUSERTBService.UpdateUserInfo(oldRoleIds, entity, roleIds))
                {
                    _SMLOG.REMARK = "用户:" + entity.USER_NAME + Suggestion.UpdateSucceed;
                    SMLOGService.AddEntity(_SMLOG);         //写入日志
                    return(Json(Suggestion.UpdateSucceed)); //提示更新成功
                }
                else
                {
                    _SMLOG.REMARK = "用户:" + entity.USER_NAME + Suggestion.UpdateFail + "原因:" + returnValue;
                    SMLOGService.AddEntity(_SMLOG);                    //写入日志
                    return(Json(Suggestion.UpdateFail + returnValue)); //提示更新失败
                }
            }
            return(Json(Suggestion.UpdateFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对
        }
 /// <summary>
 /// 判断Cookie信息
 /// </summary>
 private void CheckCookieInfo()
 {
     if (Request.Cookies["ckUid"] != null && Request.Cookies["ckPwd"] != null)
     {
         string userName = Request.Cookies["ckUid"].Value;
         string userPwd  = Request.Cookies["ckPwd"].Value;
         //判断Cookie中存储的用户密码和用户名是否正确.
         SMUSERTB person = SMUSERTBService.ValidateUser(userName, userPwd);
         if (person != null)
         {
             string sessionId = Guid.NewGuid().ToString();                                                                          //作为Memcache的key
             var    account   = person.ToAccount();
             Common.MemcacheHelper.Set(sessionId, Common.SerializerHelper.SerializeToString(account), DateTime.Now.AddMinutes(20)); //使用Memcache代替Session解决数据在不同Web服务器之间共享的问题。
             Response.Cookies["sessionId"].Value = sessionId;                                                                       //将Memcache的key以cookie的形式返回到浏览器端的内存中,当用户再次请求其它的页面请求报文中会以Cookie将该值再次发送服务端。
             //Response.Redirect("/Home/Index"); 尽量不要用这样的写法
             RedirectToAction("Index", "Home");
         }
         else
         {
             //如果说帐号秘密是错误的,就没必要再把登录用户名和密码存在cookies中了
             Response.Cookies["ckUid"].Expires = DateTime.Now.AddDays(-1);
             Response.Cookies["ckPwd"].Expires = DateTime.Now.AddDays(-1);
         }
     }
 }
 public SMROLETB Create(SMROLETB entity)
 {
     foreach (int item in entity.SysPersonId.GetIdSort())
     {
         SMUSERTB sys = this.GetCurrentDbSession.ISMUSERTBRepository.LoadEntities(u => u.USER_ID == item).FirstOrDefault();
         entity.SMUSERTB2.Add(sys);
     }
     return(AddEntity(entity));
 }
示例#4
0
        public bool Edit(SMROLETB model)
        {
            var entity = LoadEntities(r => r.ROLE_ID == model.ROLE_ID).FirstOrDefault();

            entity.SysPersonId    = model.SysPersonId;
            entity.SysPersonIdOld = model.SysPersonIdOld;
            entity.REMARK         = model.REMARK;
            entity.ROLE_NAME      = model.ROLE_NAME;
            entity.STATUS         = model.STATUS;
            entity.UPDATE_TIME    = DateTime.Now;
            entity.UPDATE_USER    = model.UPDATE_USER;

            List <int> addSysPersonId    = new List <int>();
            List <int> deleteSysPersonId = new List <int>();

            DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(),
                                       ref addSysPersonId, ref deleteSysPersonId);

            if (addSysPersonId != null && addSysPersonId.Count() > 0)
            {
                foreach (var item in addSysPersonId)
                {
                    SMUSERTB sys = this.GetCurrentDbSession.ISMUSERTBRepository.LoadEntities(u => u.USER_ID == item)
                                   .FirstOrDefault();
                    entity.SMUSERTB2.Add(new UserRole()
                    {
                        User = sys,
                        Role = entity,
                    });
                }
            }

            if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0)
            {
                List <SMUSERTB> listEntity = new List <SMUSERTB>();
                foreach (var item in deleteSysPersonId)
                {
                    SMUSERTB sys = this.GetCurrentDbSession.ISMUSERTBRepository.LoadEntities(u => u.USER_ID == item)
                                   .FirstOrDefault();
                    listEntity.Add(sys);
                }

                foreach (SMUSERTB item in listEntity)
                {
                    entity.SMUSERTB2.Remove(new UserRole()
                    {
                        UserId = item.USER_ID,
                        User   = item,
                        RoleId = entity.ROLE_ID,
                        Role   = entity,
                    }); //查询数据库
                }
            }

            return(EditEntity(entity));
        }
示例#5
0
        /// <summary>
        /// 首次编辑
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        //[SupportFilter]
        public ActionResult Edit(int id)
        {
            if (id < 1)
            {
                return(null);
            }
            SMUSERTB entity = SMUSERTBService.LoadEntities(x => x.USER_ID == id).FirstOrDefault();

            entity.U_PASSWORD   = Encrypt.UnDecodeText(entity.U_PASSWORD);//解密
            entity.SurePassword = entity.U_PASSWORD;

            return(View(entity));
        }
示例#6
0
        [ValidateAntiForgeryToken]//防伪造令牌来避免CSRF攻击
        public ActionResult Index(LogOnModel model)
        {
            #region 验证码验证

            if (GetSession("ValidateCode") != null && model.ValidateCode != null && model.ValidateCode.ToLower() != GetSession("ValidateCode").ToString())
            {
                ModelState.AddModelError("Error_PersonLogin", "验证码错误!");
                return(View());
            }
            SetSession("ValidateCode", null);
            #endregion

            if (ModelState.IsValid)
            {
                SMUSERTB person = SMUSERTBService.ValidateUser(model.PersonName, Encrypt.DecodeText(model.Password));
                if (person != null) //登录成功
                {
                    Account account = person.ToAccount();

                    string sessionId = Guid.NewGuid().ToString();//作为Memcache的key
                    try
                    {
                        MemcacheHelper.Set(sessionId, Common.SerializerHelper.SerializeToString(account), DateTime.Now.AddMinutes(20));//使用Memcache代替Session解决数据在不同Web服务器之间共享的问题。
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                    //Response.Cookies["sessionId"].Value = sessionId;//将Memcache的key以cookie的形式返回到浏览器端的内存中,当用户再次请求其它的页面请求报文中会以Cookie将该值再次发送服务端。
                    SetCookies("sessionId", sessionId);
                    if (model.RememberMe)
                    {
//                        HttpCookie ckUid = new HttpCookie("ckUid", model.PersonName);
//                        HttpCookie ckPwd = new HttpCookie("ckPwd", Encrypt.DecodeText(model.Password));
//                        ckUid.Expires = DateTime.Now.AddDays(3);
//                        ckPwd.Expires = DateTime.Now.AddDays(3);
//                        Response.Cookies["sessionId"].Expires = DateTime.Now.AddDays(3);
//                        Response.Cookies.Add(ckUid);
//                        Response.Cookies.Add(ckPwd);
                        SetCookies("ckUid", model.PersonName, 60 * 60 * 24 * 3);
                        SetCookies("ckPwd", Encrypt.DecodeText(model.Password), 60 * 60 * 24 * 3);
                    }
                    return(RedirectToAction("Index", "Home"));
                }
            }
            ModelState.AddModelError("Error_PersonLogin", "用户名或者密码出错。");
            return(View());
        }
示例#7
0
        //[SupportFilter]
        public ActionResult Create(SMUSERTB entity)
        {
            if (entity != null && ModelState.IsValid)
            {
                entity.CREATION_TIME = DateTime.Now;
                entity.CREATION_USER = GetCurrentAccount().USER_ID;
                entity.U_PASSWORD    = Encrypt.DecodeText(entity.U_PASSWORD);//加密

                string returnValue = string.Empty;

                if (SMUSERTBService.LoadEntities(x => x.U_ID == entity.U_ID).FirstOrDefault() != null)
                {
                    returnValue = "登录名已存在!";
                    return(Json(Suggestion.InsertFail + returnValue));
                }

                SMLOG _SMLOG = new SMLOG {
                    OPERATION_TYPE = "N", FUNC_CODE = "010702", USER_ID = GetCurrentAccount().USER_ID, CLASSNAME = this.GetType().ToString() + ": Create"
                };
                List <int> roleIds = entity.SysRoleId.GetIdSort();
                entity.SMROLETB = SMROLETBService.LoadEntities(x => roleIds.Contains(x.ROLE_ID)).ToList();
                var result = SMUSERTBService.AddEntity(entity);

                if (result != null)
                {
                    _SMLOG.REMARK = "用户:" + entity.USER_NAME + Suggestion.InsertSucceed;
                    SMLOGService.AddEntity(_SMLOG);//写入日志
                    return(Json(Suggestion.InsertSucceed));
                }
                else
                {
                    _SMLOG.REMARK = "用户:" + entity.USER_NAME + Suggestion.InsertFail + "原因:" + returnValue;
                    SMLOGService.AddEntity(_SMLOG);//写入日志
                    //提示插入失败
                    return(Json(Suggestion.InsertFail + returnValue));
                }
            }
            return(Json(Suggestion.InsertFail + "请核对输入的数据的格式")); //提示输入的数据的格式不对
        }