public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { LogEntity logEntity = new LogEntity(); logEntity.CategoryId = 1; logEntity.OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.OperateType = EnumAttribute.GetDescription(OperationType.Login); logEntity.OperateAccount = username; logEntity.OperateUserId = username; logEntity.Module = Config.GetValue("SoftName"); try { #region 验证码验证 if (autologin == 0) { verifycode = Md5Helper.MD5(verifycode.ToLower(), 16); if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString()) { throw new Exception("验证码错误,请重新输入"); } } #endregion #region 第三方账户验证 AccountEntity accountEntity = accountBLL.CheckLogin(username, password); if (accountEntity != null) { Operator operators = new Operator(); operators.UserId = accountEntity.AccountId; operators.Code = accountEntity.MobileCode; operators.Account = accountEntity.MobileCode; operators.UserName = accountEntity.FullName; operators.Password = accountEntity.Password; operators.IPAddress = Net.Ip; operators.IPAddressName = IPLocation.GetLocation(Net.Ip); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); operators.IsSystem = true; OperatorProvider.Provider.AddCurrent(operators); //登录限制 LoginLimit(username, operators.IPAddress, operators.IPAddressName); return(Success("登录成功。")); } #endregion #region 内部账户验证 UserEntity userEntity = new UserBLL().CheckLogin(username, password); if (userEntity != null) { AuthorizeBLL authorizeBLL = new AuthorizeBLL(); Operator operators = new Operator(); operators.UserId = userEntity.UserId; operators.Code = userEntity.EnCode; operators.Account = userEntity.Account; operators.UserName = userEntity.RealName; operators.Password = userEntity.Password; operators.Secretkey = userEntity.Secretkey; operators.CompanyId = userEntity.OrganizeId; operators.DepartmentId = userEntity.DepartmentId; operators.IPAddress = Net.Ip; operators.IPAddressName = IPLocation.GetLocation(Net.Ip); operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 if (userEntity.Account == "System") { operators.IsSystem = true; } else { operators.IsSystem = false; } OperatorProvider.Provider.AddCurrent(operators); //登录限制 LoginLimit(username, operators.IPAddress, operators.IPAddressName); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); } return(Success("登录成功。")); #endregion } catch (Exception ex) { WebHelper.RemoveCookie("learn_autologin"); //清除自动登录 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(Error(ex.Message)); } }
//登录 private Negotiator CheckLogin(dynamic _) { var recdata = this.GetModule <ReceiveModule <loginData> >(); LogEntity logEntity = new LogEntity(); logEntity.F_CategoryId = 1; logEntity.F_OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.F_OperateType = EnumAttribute.GetDescription(OperationType.Login); logEntity.F_OperateAccount = recdata.data.username; logEntity.F_OperateUserId = recdata.data.username; logEntity.F_Module = "LeaRun.敏捷开发框架"; try { Operator operators = new Operator(); loginUserInfo result = new loginUserInfo(); #region 内部登录 { //写入当前用户信息 UserEntity userEntity = new UserBLL().CheckLogin(recdata.data.username, recdata.data.password); if (userEntity != null) { AuthorizeBLL authorizeBLL = new AuthorizeBLL(); operators.UserId = userEntity.F_UserId; operators.Code = userEntity.F_EnCode; operators.Account = userEntity.F_Account; operators.UserName = userEntity.F_RealName; operators.Password = userEntity.F_Password; operators.Secretkey = userEntity.F_Secretkey; operators.CompanyId = userEntity.F_OrganizeId; operators.DepartmentId = userEntity.F_DepartmentId; operators.IPAddress = Net.Ip; operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.F_UserId); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); if (userEntity.F_Account == "System") { operators.IsSystem = true; } else { operators.IsSystem = false; } //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); result.userid = userEntity.F_UserId; result.account = userEntity.F_Account; result.password = userEntity.F_Password; result.realname = userEntity.F_RealName; result.headicon = ""; result.gender = (userEntity.F_Gender == 1 ? "男" : "女"); result.mobile = userEntity.F_Mobile; result.telephone = userEntity.F_Telephone; result.email = userEntity.F_Email; result.oicq = userEntity.F_OICQ; result.wechat = userEntity.F_WeChat; result.msn = userEntity.F_MSN; result.managerid = userEntity.F_ManagerId; result.manager = userEntity.F_Manager; result.organizeid = userEntity.F_OrganizeId; result.organizename = organizeCache.GetEntity(result.organizeid).F_FullName; result.departmentid = userEntity.F_DepartmentId; result.departmentname = departmentCache.GetEntity(userEntity.F_DepartmentId).F_FullName; result.roleid = userEntity.F_RoleId; result.rolename = roleCache.GetEntity(userEntity.F_RoleId).F_FullName; result.dutyid = userEntity.F_DutyId; result.dutyname = userEntity.F_DutyName; result.postid = userEntity.F_PostId; result.postname = userEntity.F_PostName; result.description = userEntity.F_Description; } } #endregion //移动端不采用cookie的方式 this.WriteCache <Operator>(operators, operators.UserId); //写入日志 logEntity.F_ExecuteResult = 1; logEntity.F_ExecuteResultJson = "登录成功"; logEntity.WriteLog(); return(this.SendData <loginUserInfo>(result, result.userid, operators.Token, ResponseType.Success)); } catch (Exception ex) { logEntity.F_ExecuteResult = -1; logEntity.F_ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(this.SendData(ResponseType.Fail, ex.Message)); } }
public Object checkLogin([FromBody] JObject json) { string res = json.Value <string>("json"); dynamic dy = JsonConvert.DeserializeObject <ExpandoObject>(res); string username = dy.data.useraccount; string password = dy.data.password; LogEntity logEntity = new LogEntity(); logEntity.CategoryId = 1; logEntity.OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.OperateType = EnumAttribute.GetDescription(OperationType.Login); logEntity.OperateAccount = username; logEntity.OperateUserId = username; logEntity.Module = "APP"; try { #region 内部账户验证 UserBLL userBLL = new UserBLL(); UserInfoEntity userEntity = userBLL.CheckLogin(username, password); if (userEntity != null) { if (userEntity.AllowStartTime != null && userEntity.AllowEndTime != null) { if (DateTime.Now > userEntity.AllowEndTime) { return(new { code = -1, count = 0, info = "您的账号使用期限已过期,请联系管理员或客服,谢谢" }); } } AuthorizeBLL authorizeBLL = new AuthorizeBLL(); Operator operators = new Operator(); operators.UserId = userEntity.UserId; operators.Code = userEntity.EnCode; operators.Account = userEntity.Account; operators.UserName = userEntity.RealName; operators.Password = userEntity.Password; operators.Secretkey = userEntity.Secretkey; operators.DeptId = userEntity.DepartmentId; operators.ParentId = userEntity.ParentId; operators.DeptCode = userEntity.DepartmentCode; operators.OrganizeCode = userEntity.OrganizeCode; operators.DeptName = userEntity.DeptName; operators.IsTrain = userEntity.IsTrain; operators.SignImg = userEntity.SignImg; DepartmentEntity dept = userBLL.GetUserOrgInfo(userEntity.UserId); //获取当前用户所属的机构 operators.OrganizeId = dept.DepartmentId; //所属机构ID operators.OrganizeCode = dept.EnCode; //所属机构编码 operators.NewDeptCode = dept.DeptCode; //所属机构新的编码(对应部门表中新加的编码字段deptcode) operators.OrganizeName = dept.FullName; //所属机构名称 operators.SpecialtyType = userEntity.SpecialtyType; ////公司级用户 if (new UserBLL().HaveRoleListByKey(userEntity.UserId, dataitemdetailbll.GetItemValue("HidOrganize")).Rows.Count > 0) { operators.DeptId = userEntity.OrganizeId; operators.DeptCode = userEntity.OrganizeCode; operators.DeptName = userEntity.OrganizeName; } operators.PostName = userBLL.GetObjectName(userEntity.UserId, 3); operators.RoleName = userBLL.GetObjectName(userEntity.UserId, 2); operators.RoleId = userEntity.RoleId; operators.PostId = userEntity.PostId; operators.DutyName = userBLL.GetObjectName(userEntity.UserId, 4); operators.IPAddress = Net.Ip; operators.Photo = dataitemdetailbll.GetItemValue("imgUrl") + userEntity.HeadIcon; //头像 operators.IdentifyID = userEntity.IdentifyID; //身份证号码 //operators.SendDeptID = userEntity.SendDeptID; //operators.IPAddressName = IPLocation.GetLocation(Net.Ip); operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 if (userEntity.Account == "System") { operators.IsSystem = true; } else { operators.IsSystem = false; } string userMode = ""; string roleCode = dataitemdetailbll.GetItemValue("HidApprovalSetting"); string HidApproval = dataitemdetailbll.GetItemValue("HidApproval"); string[] pstr = HidApproval.Split('#'); //分隔机构组 foreach (string strArgs in pstr) { string[] str = strArgs.Split('|'); //当前机构相同,且为本部门安全管理员验证 第一种 层层上报 if (str[0].ToString() == userEntity.OrganizeId && str[1].ToString() == "0") { /*************临时使用,后续需要进行调整,原有隐患基于角色,较为固定,后期则废弃*************/ //WfControlObj wfentity = new WfControlObj(); //wfentity.businessid = ""; // //wfentity.startflow = "隐患评估"; //wfentity.submittype = "上报"; //wfentity.rankname = "一般隐患"; //wfentity.user = operators; //wfentity.mark = "厂级隐患排查"; //厂级隐患排查 //wfentity.isvaliauth = true; ////获取下一流程的操作人 //WfControlResult result = new WfControlBLL().GetWfControl(wfentity); //bool ishaveapproval = result.ishave; //具有评估权限的人 int count = new UserBLL().GetUserListByRole(userEntity.DepartmentCode, roleCode, userEntity.OrganizeId).ToList().Where(p => p.UserId == userEntity.UserId).Count(); if (count > 0)//包含安全管理员、负责人 { userMode = "0"; } else { userMode = "1"; } break; } if (str[0].ToString() == userEntity.OrganizeId && str[1].ToString() == "1") { //获取指定部门的所有人员 int count = new UserBLL().GetUserListByDeptCode(str[2].ToString(), null, false, userEntity.OrganizeId).ToList().Where(p => p.UserId == userEntity.UserId).Count(); if (count > 0) { userMode = "2"; } else { userMode = "3"; } break; } } if (userEntity.RoleName.Contains("省级用户")) { userMode = "4"; } string rankArgs = dataitemdetailbll.GetItemValue("GeneralHid"); //一般隐患 operators.rankArgs = rankArgs; operators.wfMode = userMode; string hidPlantLevel = dataitemdetailbll.GetItemValue("HidPlantLevel"); string hidOrganize = dataitemdetailbll.GetItemValue("HidOrganize"); string CompanyRole = hidPlantLevel + "," + hidOrganize; var userList = userBLL.GetUserListByDeptCode(userEntity.DepartmentCode, CompanyRole, false, userEntity.OrganizeId).Where(p => p.UserId == userEntity.UserId).ToList(); string isPlanLevel = ""; //当前用户是公司级及厂级用户 if (userList.Count() > 0) { isPlanLevel = "1"; //厂级用户 } else { isPlanLevel = "0"; //非公司及厂级 } operators.isPlanLevel = isPlanLevel; string pricipalCode = dataitemdetailbll.GetItemValue("HidPrincipalSetting"); IList <UserEntity> ulist = new UserBLL().GetUserListByRole(userEntity.DepartmentCode, pricipalCode, userEntity.OrganizeId).ToList(); //返回的记录数,大于0,标识当前用户拥有部门负责人身份,反之则无 int uModel = ulist.Where(p => p.UserId == userEntity.UserId).Count(); operators.isPrincipal = uModel > 0 ? "1" : "0"; var deptEntity = new DepartmentBLL().GetEntity(userEntity.DepartmentId); if (null != deptEntity) { operators.SendDeptID = deptEntity.SendDeptID; } else { operators.SendDeptID = ""; } //用于违章的用户标记 string mark = string.Empty; mark = userbll.GetSafetyAndDeviceDept(operators); //1 安全管理部门, 2 装置部门 5.发包部门 string isPrincipal = userbll.HaveRoleListByKey(operators.UserId, dataitemdetailbll.GetItemValue("PrincipalUser")).Rows.Count > 0 ? "3" : ""; //第一级核准人 if (!string.IsNullOrEmpty(isPrincipal)) { if (!string.IsNullOrEmpty(mark)) { mark = mark + "," + isPrincipal; } else { mark = isPrincipal; } } string isEpiboly = userbll.HaveRoleListByKey(operators.UserId, dataitemdetailbll.GetItemValue("EpibolyUser")).Rows.Count > 0 ? "4" : ""; //承包商 if (!string.IsNullOrEmpty(isEpiboly)) { if (!string.IsNullOrEmpty(mark)) { mark = mark + "," + isEpiboly; } else { mark = isEpiboly; } } operators.uMark = mark; //国电新疆红雁池专用 string GDXJ_HYC_ORGCODE = dataitemdetailbll.GetItemValue("GDXJ_HYC_ORGCODE"); //国电新疆红雁池专用 operators.IsGdxjUser = userEntity.OrganizeCode == GDXJ_HYC_ORGCODE ? 1 : 0; OperatorProvider.Provider.AddCurrent(operators); //登录限制 //LoginLimit(username, operators.IPAddress, operators.IPAddressName); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); //异步处理与培训平台对接功能 //UserEntity ue = userbll.GetEntity(userEntity.UserId); //UserInfoExtension uinfoextesion = GoToTrainee(ue); var di = new DataItemDetailBLL(); string webPath = di.GetItemValue("imgPath"); string webUrl = di.GetItemValue("imgUrl"); string signUrl = ""; string qrCodeImgUrl = webUrl + "/Resource/AppFile/download.jpg"; if (!string.IsNullOrEmpty(userEntity.SignImg)) { if (userEntity.SignImg.ToLower().Trim().StartsWith("http://")) { signUrl = userEntity.SignImg; } else { string fname = ""; string sImg = ""; if (userEntity.SignImg.ToLower().Contains("/resource/sign/")) { fname = userEntity.SignImg.Replace("/", "\\"); string name = userEntity.SignImg.Substring(userEntity.SignImg.LastIndexOf("/") + 1); sImg = "s" + name.Replace("/", "\\"); } else { fname = "\\Resource\\sign\\" + userEntity.SignImg.Replace("/", "\\"); sImg = "\\Resource\\sign\\s" + userEntity.SignImg.Replace("/", "\\"); } if (File.Exists(webPath + sImg)) { signUrl = webUrl + sImg.Replace("\\", "/"); } else { if (File.Exists(webPath + fname)) { signUrl = webUrl + fname.Replace("\\", "/"); } } } } return(new { code = 0, count = -1, info = "登陆成功", data = new { userid = operators.UserId, tokenid = operators.Token, useraccount = operators.Account, telephone = userEntity.Telephone, phone = userEntity.Mobile, username = operators.UserName, password = operators.Password, logtime = operators.LogTime, secretkey = operators.Secretkey, gender = operators.Gender, organizeid = operators.OrganizeId, deptid = operators.DeptId, deptcode = operators.DeptCode, deptname = operators.DeptName, organizecode = operators.OrganizeCode, organizename = operators.OrganizeName, objectid = operators.ObjectId, ipaddress = operators.IPAddress, ipaddressname = operators.IPAddressName, issystem = operators.IsSystem, roleid = operators.RoleId, rolename = operators.RoleName, postid = operators.PostId, postname = operators.PostName, dutyname = operators.DutyName, photo = operators.Photo, wfmode = operators.wfMode, senddeptid = operators.SendDeptID, rankargs = operators.rankArgs, isprincipal = operators.isPrincipal, identifyid = operators.IdentifyID, mark = operators.uMark, signurl = signUrl, isgdxjuser = operators.IsGdxjUser, qrimgurl = qrCodeImgUrl, //ticket = uinfoextesion.ticket, //openid = uinfoextesion.openId, //traineeaccount = uinfoextesion.traineeAccount, //traineepwd = uinfoextesion.traineePwd, dataauthorize = new { moduleid = operators.DataAuthorize.ModuleId, readautorize = operators.DataAuthorize.ReadAutorize, readautorizeuserid = operators.DataAuthorize.ReadAutorizeUserId, writeautorize = operators.DataAuthorize.WriteAutorize, writeautorizeuserid = operators.DataAuthorize.WriteAutorizeUserId } } }); } else { return(new { code = -1, count = 0, info = "密码输入错误" }); } #endregion } catch (Exception ex) { WebHelper.RemoveCookie("autologin"); //清除自动登录 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(new { code = -1, count = 0, info = "账号或密码错误!" }); } }
public ActionResult Index(string urlstr) { //1.2根据注册的微信id去用户表中匹配是否有此员工 WeChat_UsersEntity entity = wechatUserBll.GetEntity(CurrentWxUser.OpenId); //WeChat_UsersEntity entity = wechatUserBll.GetEntity("o7HEd1LjnupfP0BBBMz5f69MFYVE"); if (!string.IsNullOrEmpty(entity.UserName) && !string.IsNullOrEmpty(entity.UserId)) { UserEntity userEntity = new UserBLL().GetEntity(entity.UserId); LogEntity logEntity = new LogEntity(); logEntity.CategoryId = 1; logEntity.OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.OperateType = EnumAttribute.GetDescription(OperationType.AppLogin); logEntity.OperateAccount = userEntity.RealName; logEntity.OperateUserId = userEntity.RealName; logEntity.Module = Config.GetValue("SoftName"); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); AuthorizeBLL authorizeBLL = new AuthorizeBLL(); Operator operators = new Operator(); operators.UserId = userEntity.UserId; operators.Code = userEntity.EnCode; operators.Account = userEntity.Account; operators.UserName = userEntity.RealName; operators.Password = userEntity.Password; operators.Secretkey = userEntity.Secretkey; operators.CompanyId = userEntity.OrganizeId; operators.DepartmentId = userEntity.DepartmentId; operators.IPAddress = Net.Ip; operators.IPAddressName = IPLocation.GetLocation(Net.Ip); operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 if (userEntity.Account == "System") { operators.IsSystem = true; } else { operators.IsSystem = false; } OperatorProvider.Provider.AddCurrent(operators); //return RedirectToAction("Index", "WeiXinHome"); return(RedirectToAction("Index", "WeiXinHome", new { urlstr = urlstr })); } else { return(View()); } }
/* 匿名请求: * 1. GET方式 * 2. 入参增加code参数传值:code: '@Request["code"]' * 3. ListIntercept添加Controller、Action * */ protected override void OnActionExecuting(ActionExecutingContext filterContext) { string UserId = string.Empty; string userAgent = Request.UserAgent; string jurl = ""; if (userAgent.ToLower().Contains("micromessenger")) { //从微信端访问 if (Session["WxUserID"] == null || Session["WxUserID"].ToString().Length == 0) { #region 获取微信用户信息 if (string.IsNullOrWhiteSpace(Request.QueryString["code"])) { jurl = OAuth2ApiHelper.GetCode(Request.Url.AbsoluteUri); filterContext.Result = RedirectPermanent(jurl); Logger.Info("jurl:" + jurl); } else { try { GetUserInfoResult result = OAuth2ApiHelper.GetUserId(Request.QueryString["code"]); UserId = result.UserId ?? ""; Logger.Info("GetUserId:" + result.ToJson()); } catch (Exception ex) { Logger.Error(ex); } Session["WxUserID"] = UserId; } #endregion } else { UserId = Session["WxUserID"] == null ? string.Empty : Session["WxUserID"].ToString(); } } if (!IsLogin()) { if (userAgent.ToLower().Contains("micromessenger")) { #region 微信登录 if (!string.IsNullOrWhiteSpace(UserId)) { try { UserEntity userEntity = new UserBLL().WechatLogin(UserId); if (userEntity != null) { #region 记录登录成功信息 AuthorizeBLL authorizeBLL = new AuthorizeBLL(); Operator operators = new Operator(); LoginUserModel LoginUser = new LoginUserModel(); LoginUser.UserId = userEntity.UserId; LoginUser.Code = userEntity.EnCode; LoginUser.Account = userEntity.Account; LoginUser.UserName = userEntity.RealName; LoginUser.Password = userEntity.Password; LoginUser.Secretkey = userEntity.Secretkey; LoginUser.CompanyId = userEntity.OrganizeId; LoginUser.DepartmentId = userEntity.DepartmentId; LoginUser.ManagerId = userEntity.ManagerId; LoginUser.Manager = userEntity.Manager; LoginUser.HeadIcon = userEntity.HeadIcon; LoginUser.IPAddress = Net.Ip; LoginUser.IPAddressName = IPLocation.GetLocation(Net.Ip); LoginUser.LogTime = DateTime.Now; LoginUser.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); operators.LoginInfo = LoginUser; // 写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); operators.DataAuthorize = dataAuthorize; OperatorProvider.AppUserId = userEntity.UserId; OperatorProvider.Provider.AddCurrent(operators); Logger.Info("微信登录写入缓存:" + LoginUser.ToJson()); #endregion } else { Logger.Info("登录失败1"); //跳转到登录页面 filterContext.Result = new RedirectResult("~/Login/Index"); } } catch (Exception ex) { Logger.Info("登录异常"); Logger.Error(ex); //跳转到登录页面 filterContext.Result = new RedirectResult("~/Login/Index"); } } #endregion } else { Logger.Info("非微信--登录失败1"); //跳转到登录页面 filterContext.Result = new RedirectResult("~/Login/Index"); } } base.OnActionExecuting(filterContext); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { ActionResult res = null; LogEntity logEntity = new LogEntity { CategoryId = (int)CategoryType.Login, OperateTypeId = ((int)OperationType.Login).ToString(), OperateType = OperationType.Login.GetEnumDescription(), OperateAccount = username, OperateUserId = username, OperateTime = DateTime.Now, IPAddress = NetHelper.Ip, IPAddressName = "",//NetHelper.GetAddressByIP(NetHelper.Ip), Browser = NetHelper.Browser, Module = ConfigHelper.GetValue("SoftName") }; Logger(this.GetType(), "登录验证-CheckLogin", () => { #region 验证码验证 string code = Md5Helper.Md5(verifycode.ToLower()); string sessionCode = SessionHelper.GetSession <string>("session_verifycode"); if (string.IsNullOrEmpty(sessionCode) || code != sessionCode) { res = Error("验证码错误,请重新输入"); } #endregion #region 账户验证 else { Tuple <UserEntity, JsonObjectStatus> tuple = userBll.CheckLogin(username, password); JsonObjectStatus status = tuple.Item2; UserEntity user = tuple.Item1; if (status != JsonObjectStatus.Success || user == null) { res = Error(status.GetEnumDescription()); } else { string objId = permissionBll.GetObjectString(user.Id); OperatorEntity operators = new OperatorEntity { UserId = user.Id, Code = user.EnCode, Account = user.Account, UserName = user.RealName ?? user.NickName, Password = user.Password, Secretkey = user.Secretkey, CompanyId = user.OrganizeId, DepartmentId = user.DepartmentId, IPAddress = NetHelper.Ip, IPAddressName = "",//NetHelper.GetAddressByIP(NetHelper.Ip), ObjectId = objId, LoginTime = DateTime.Now, Token = DESEncryptHelper.Encrypt(CommonHelper.GetGuid(), user.Secretkey) }; //写入当前用户数据权限 string ReadAutorize = authorizeBLL.GetDataAuthor(operators); string ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); string WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); string WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); AuthorizeDataModel dataAuthorize = new AuthorizeDataModel { ReadAutorize = ReadAutorize, ReadAutorizeUserId = ReadAutorizeUserId, WriteAutorize = WriteAutorize, WriteAutorizeUserId = WriteAutorizeUserId }; operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 operators.IsSystem = user.Account == "System"; //写入登录信息 OperatorProvider.Provider.AddCurrent(operators); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logBll.WriteLog(logEntity); res = Success("登录成功", user, "/Home/AdminDefault"); } } #endregion }, e => { CookieHelper.DelCookie("__autologin");//清除自动登录 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = e.Message; logBll.WriteLog(logEntity); res = Error("系统异常:" + e.Message); }, () => { SessionHelper.RemoveSession("session_verifycode"); }); return(res); }
public Operator GetOperator(string userId) { AuthorizeBLL authorizeBLL = new AuthorizeBLL(); UserBLL userBLL = new UserBLL(); UserInfoEntity userEntity = userbll.GetUserInfoEntity(userId); if (userEntity == null) { return(null); } Operator operators = new Operator(); operators.UserId = userEntity.UserId; operators.Code = userEntity.EnCode; operators.Account = userEntity.Account; operators.UserName = userEntity.RealName; operators.Password = userEntity.Password; operators.Secretkey = userEntity.Secretkey; operators.OrganizeId = userEntity.OrganizeId; operators.DeptId = userEntity.DepartmentId; operators.ParentId = userEntity.ParentId; operators.DeptCode = userEntity.DepartmentCode; operators.OrganizeCode = userEntity.OrganizeCode; operators.DeptName = userEntity.DeptName; operators.OrganizeName = userEntity.OrganizeName; operators.SpecialtyType = userEntity.SpecialtyType; //公司级用户 if (new UserBLL().HaveRoleListByKey(userEntity.UserId, dataitemdetailbll.GetItemValue("HidOrganize")).Rows.Count > 0) { operators.DeptId = userEntity.OrganizeId; operators.DeptCode = userEntity.OrganizeCode; operators.DeptName = userEntity.OrganizeName; } operators.PostName = userBLL.GetObjectName(userEntity.UserId, 3); operators.RoleName = userBLL.GetObjectName(userEntity.UserId, 2); operators.RoleId = userEntity.RoleId; operators.DutyName = userBLL.GetObjectName(userEntity.UserId, 4); operators.IPAddress = Net.Ip; operators.Photo = dataitemdetailbll.GetItemValue("imgUrl") + userEntity.HeadIcon; //头像 operators.IdentifyID = userEntity.IdentifyID; //身份证号码 //operators.SendDeptID = userEntity.SendDeptID; //operators.IPAddressName = IPLocation.GetLocation(Net.Ip); operators.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId); operators.LogTime = DateTime.Now; operators.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel(); dataAuthorize.ReadAutorize = authorizeBLL.GetDataAuthor(operators); dataAuthorize.ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators); dataAuthorize.WriteAutorize = authorizeBLL.GetDataAuthor(operators, true); dataAuthorize.WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true); operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 if (userEntity.Account == "System") { operators.IsSystem = true; } else { operators.IsSystem = false; } string userMode = ""; string roleCode = dataitemdetailbll.GetItemValue("HidApprovalSetting"); string HidApproval = dataitemdetailbll.GetItemValue("HidApproval"); string[] pstr = HidApproval.Split('#'); //分隔机构组 foreach (string strArgs in pstr) { string[] str = strArgs.Split('|'); //当前机构相同,且为本部门安全管理员验证 第一种 if (str[0].ToString() == userEntity.OrganizeId && str[1].ToString() == "0") { int count = new UserBLL().GetUserListByRole(userEntity.DepartmentCode, roleCode, userEntity.OrganizeId).ToList().Where(p => p.UserId == userEntity.UserId).Count(); if (count > 0) { userMode = "0"; } else { userMode = "1"; } break; } if (str[0].ToString() == userEntity.OrganizeId && str[1].ToString() == "1") { //获取指定部门的所有人员 int count = new UserBLL().GetUserListByDeptCode(str[2].ToString(), null, false, userEntity.OrganizeId).ToList().Where(p => p.UserId == userEntity.UserId).Count(); if (count > 0) { userMode = "2"; } else { userMode = "3"; } break; } } string rankArgs = dataitemdetailbll.GetItemValue("GeneralHid"); //一般隐患 operators.rankArgs = rankArgs; operators.wfMode = userMode; string hidPlantLevel = dataitemdetailbll.GetItemValue("HidPlantLevel"); string hidOrganize = dataitemdetailbll.GetItemValue("HidOrganize"); string CompanyRole = hidPlantLevel + "," + hidOrganize; var userList = userBLL.GetUserListByDeptCode(userEntity.DepartmentCode, CompanyRole, false, userEntity.OrganizeId).Where(p => p.UserId == userEntity.UserId).ToList(); string isPlanLevel = ""; //当前用户是公司级及厂级用户 if (userList.Count() > 0) { isPlanLevel = "1"; //厂级用户 } else { isPlanLevel = "0"; //非公司及厂级 } operators.isPlanLevel = isPlanLevel; string pricipalCode = dataitemdetailbll.GetItemValue("HidPrincipalSetting"); IList <UserEntity> ulist = new UserBLL().GetUserListByRole(userEntity.DepartmentCode, pricipalCode, userEntity.OrganizeId).ToList(); //返回的记录数,大于0,标识当前用户拥有部门负责人身份,反之则无 int uModel = ulist.Where(p => p.UserId == userEntity.UserId).Count(); operators.isPrincipal = uModel > 0 ? "1" : "0"; var deptEntity = new DepartmentBLL().GetEntity(userEntity.DepartmentId); if (null != deptEntity) { operators.SendDeptID = deptEntity.SendDeptID; } else { operators.SendDeptID = ""; } //用于违章的用户标记 string mark = string.Empty; mark = userbll.GetSafetyAndDeviceDept(operators); //1 安全管理部门, 2 装置部门 5.发包部门 string isPrincipal = userbll.HaveRoleListByKey(operators.UserId, dataitemdetailbll.GetItemValue("PrincipalUser")).Rows.Count > 0 ? "3" : ""; //第一级核准人 if (!string.IsNullOrEmpty(isPrincipal)) { if (!string.IsNullOrEmpty(mark)) { mark = mark + "," + isPrincipal; } else { mark = isPrincipal; } } string isEpiboly = userbll.HaveRoleListByKey(operators.UserId, dataitemdetailbll.GetItemValue("EpibolyUser")).Rows.Count > 0 ? "4" : ""; //承包商 if (!string.IsNullOrEmpty(isEpiboly)) { if (!string.IsNullOrEmpty(mark)) { mark = mark + "," + isEpiboly; } else { mark = isEpiboly; } } operators.uMark = mark; OperatorProvider.Provider.AddCurrent(operators); return(operators); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { ActionResult res = null; Logger(this.GetType(), "登录验证-CheckLogin", () => { #region 验证码验证 string code = Md5Helper.Md5(verifycode.ToLower()); string sessionCode = SessionHelper.GetSession <string>("session_verifycode"); if (string.IsNullOrEmpty(sessionCode) || code != sessionCode) { res = Error("验证码错误,请重新输入"); } #endregion #region 账户验证 else { JsonObjectStatus status; UserEntity user = _userBll.CheckLogin(username, password, out status); if (status != JsonObjectStatus.Success || user == null) { res = Error(status.GetEnumDescription()); } else { string objId = _permissionBll.GetObjectString(user.UserId); OperatorEntity operators = new OperatorEntity { UserId = user.UserId, Code = user.EnCode, Account = user.Account, UserName = user.RealName ?? user.NickName, Password = user.Password, Secretkey = user.Secretkey, CompanyId = user.OrganizeId, DepartmentId = user.DepartmentId, IPAddress = NetHelper.Ip, IPAddressName = NetHelper.GetAddressByIP(NetHelper.Ip), ObjectId = objId, LoginTime = DateTime.Now, Token = DESEncryptHelper.Encrypt(CommonHelper.GetGuid(), user.Secretkey) }; //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel { ReadAutorize = _authorizeBll.GetDataAuthor(operators), ReadAutorizeUserId = _authorizeBll.GetDataAuthorUserId(operators), WriteAutorize = _authorizeBll.GetDataAuthor(operators, true), WriteAutorizeUserId = _authorizeBll.GetDataAuthorUserId(operators, true) }; operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 operators.IsSystem = user.Account == "System"; //写入登录信息 OperatorProvider.Provider.AddCurrent(operators); res = Success("登录成功", user, "/Home/AdminDefault"); } } #endregion }, e => { res = Error("系统异常:" + e.Message); }, () => { SessionHelper.RemoveSession("session_verifycode"); }); return(res); }
public ActionResult CheckLogin(string username, string password, string verifycode, int autologin) { LogEntity logEntity = new LogEntity { CategoryId = (int)CategoryType.Login, OperateTypeId = ((int)OperationType.Login).ToString(), OperateType = OperationType.Login.GetEnumDescription(), OperateAccount = username, OperateUserId = username, Module = ConfigHelper.GetValue("SoftName") }; try { #region 验证码验证 if (autologin == 0) { verifycode = Md5Helper.MD5(verifycode.ToLower(), 16); if (Session["session_verifycode"].IsEmpty() || verifycode != Session["session_verifycode"].ToString()) { throw new Exception("验证码错误,请重新输入"); } } #endregion #region 第三方账户验证 modify by chengzg 20160812 关闭该验证 //AccountEntity accountEntity = accountBLL.CheckLogin(username, password); //if (accountEntity != null) //{ // Operator operators = new Operator(); // operators.UserId = accountEntity.AccountId; // operators.Code = accountEntity.MobileCode; // operators.Account = accountEntity.MobileCode; // operators.UserName = accountEntity.FullName; // operators.Password = accountEntity.Password; // operators.IPAddress = Net.Ip; // operators.IPAddressName = IPLocation.GetLocation(Net.Ip); // operators.LogTime = DateTimeHelper.Now; // operators.Token = DESEncrypt.Encrypt(CommonHelper.GetGuid().ToString()); // operators.IsSystem = true; // OperatorProvider.Provider.AddCurrent(operators); // //登录限制 // LoginLimit(username, operators.IPAddress, operators.IPAddressName); // return Success("登录成功。"); //} #endregion #region 内部账户验证 UserEntity userEntity = new UserBLL().CheckLogin(username, password); if (userEntity != null) { AuthorizeBLL authorizeBLL = new AuthorizeBLL(); Operator operators = new Operator { UserId = userEntity.UserId, Code = userEntity.EnCode, Account = userEntity.Account, UserName = userEntity.RealName, Password = userEntity.Password, Secretkey = userEntity.Secretkey, CompanyId = userEntity.OrganizeId, DepartmentId = userEntity.DepartmentId, IPAddress = NetHelper.Ip, IPAddressName = IPLocation.GetLocation(NetHelper.Ip), ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId), LogTime = DateTimeHelper.Now, Token = DESEncrypt.Encrypt(CommonHelper.GetGuid().ToString()) }; //写入当前用户数据权限 AuthorizeDataModel dataAuthorize = new AuthorizeDataModel { ReadAutorize = authorizeBLL.GetDataAuthor(operators), ReadAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators), WriteAutorize = authorizeBLL.GetDataAuthor(operators, true), WriteAutorizeUserId = authorizeBLL.GetDataAuthorUserId(operators, true) }; operators.DataAuthorize = dataAuthorize; //判断是否系统管理员 operators.IsSystem = userEntity.Account == "System"; OperatorProvider.Provider.AddCurrent(operators); //登录限制 modify by chengzg 20160812 关闭该验证 //LoginLimit(username, operators.IPAddress, operators.IPAddressName); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); } return(Success("登录成功。")); #endregion } catch (Exception ex) { WebHelper.RemoveCookie("__autologin"); //清除自动登录 logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(Error(ex.Message)); } }