/// <summary> /// 登录,返回用户对象 /// </summary> /// <param name="accountName">用户名</param> /// <param name="passWord">密码</param> /// <returns></returns> public ResultModel Login(string accountName, string passWord) { try { AccountBLL bll = new AccountBLL(); ResultModel result = bll.CheckLogin(accountName, passWord); if (result.ResultStatus == 0 && result.ReturnValue != null) { int i; if (int.TryParse(result.ReturnValue.ToString(), out i) && i == 1) { //生成唯一token,写Cache string token = CreateToken(); CacheManager.CacheInsert(token, accountName); result.ReturnValue = token; //result.ReturnValue = User.UserProvider.GetUserModel(token, accountName); } } return result; } catch (Exception ex) { this.log.ErrorFormat(ex.Message); return null; } }
/// <summary> /// 登录,返回用户对象 /// </summary> /// <param name="accountName">用户名</param> /// <param name="passWord">密码</param> /// <returns></returns> public ResultModel Login(string accountName, string passWord) { try { AccountBLL bll = new AccountBLL(); ResultModel result = bll.CheckLogin(accountName, passWord); if (result.ResultStatus == 0 && result.ReturnValue != null) { int i; if (int.TryParse(result.ReturnValue.ToString(), out i) && i == 1) { //生成唯一token,写Cache string token = CreateToken(); CacheManager.CacheInsert(token, accountName); result.ReturnValue = token; //result.ReturnValue = User.UserProvider.GetUserModel(token, accountName); } } return(result); } catch (Exception ex) { this.log.ErrorFormat(ex.Message); return(null); } }
//登录 private Negotiator CheckLogin(dynamic _) { var recdata = this.GetModule <ReceiveModule <loginData> >(); LogEntity logEntity = new LogEntity(); logEntity.CategoryId = 1; logEntity.OperateTypeId = ((int)OperationType.Login).ToString(); logEntity.OperateType = EnumAttribute.GetDescription(OperationType.Login); logEntity.OperateAccount = recdata.data.username; logEntity.OperateUserId = recdata.data.username; logEntity.Module = "Offertech.敏捷开发框架"; try { Operator operators = new Operator(); LoginUserModel loginUser = new LoginUserModel(); loginUserInfo result = new loginUserInfo(); #region 第三方账户验证 AccountEntity accountEntity = accountBLL.CheckLogin(recdata.data.username, recdata.data.password); if (accountEntity != null) { loginUser.UserId = accountEntity.AccountId; loginUser.Code = accountEntity.MobileCode; loginUser.Account = accountEntity.MobileCode; loginUser.UserName = accountEntity.FullName; loginUser.Password = accountEntity.Password; loginUser.IPAddress = Net.Ip; loginUser.IPAddressName = IPLocation.GetLocation(Net.Ip); loginUser.LogTime = DateTime.Now; loginUser.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); loginUser.IsSystem = true; //登录限制 LoginLimit(recdata.data.username, loginUser.IPAddress, loginUser.IPAddressName, recdata.platform); result.userid = loginUser.UserId; result.account = loginUser.Account; result.password = loginUser.Password; result.realname = loginUser.UserName; result.headicon = ""; result.gender = ""; result.mobile = loginUser.Account; } #endregion #region 内部登录 else { //写入当前用户信息 UserEntity userEntity = new UserBLL().CheckLogin(recdata.data.username, recdata.data.password); if (userEntity != null) { AuthorizeBLL authorizeBLL = new AuthorizeBLL(); 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.IPAddress = Net.Ip; loginUser.ObjectId = new PermissionBLL().GetObjectStr(userEntity.UserId); loginUser.LogTime = DateTime.Now; loginUser.Token = DESEncrypt.Encrypt(Guid.NewGuid().ToString()); if (userEntity.Account == "System") { loginUser.IsSystem = true; } else { loginUser.IsSystem = false; } 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; result.userid = userEntity.UserId; result.account = userEntity.Account; result.password = userEntity.Password; result.realname = userEntity.RealName; result.headicon = ""; result.gender = (userEntity.Gender == 1 ? "男" : "女"); result.mobile = userEntity.Mobile; result.telephone = userEntity.Telephone; result.email = userEntity.Email; result.oicq = userEntity.OICQ; result.wechat = userEntity.WeChat; result.msn = userEntity.MSN; result.managerid = userEntity.ManagerId; result.manager = userEntity.Manager; result.organizeid = userEntity.OrganizeId; result.organizename = organizeCache.GetEntity(result.organizeid).FullName; result.departmentid = userEntity.DepartmentId; result.departmentname = departmentCache.GetEntity(userEntity.DepartmentId).FullName; result.roleid = userEntity.RoleId; result.rolename = roleCache.GetEntity(userEntity.RoleId).FullName; result.dutyid = userEntity.DutyId; result.dutyname = userEntity.DutyName; result.postid = userEntity.PostId; result.postname = userEntity.PostName; result.description = userEntity.Description; } } #endregion //移动端不采用cookie的方式 this.WriteCache <Operator>(operators, operators.LoginInfo.UserId); //写入日志 logEntity.ExecuteResult = 1; logEntity.ExecuteResultJson = "登录成功"; logEntity.WriteLog(); return(this.SendData <loginUserInfo>(result, result.userid, operators.LoginInfo.Token, ResponseType.Success)); } catch (Exception ex) { logEntity.ExecuteResult = -1; logEntity.ExecuteResultJson = ex.Message; logEntity.WriteLog(); return(this.SendData(ResponseType.Fail, ex.Message)); } }