public UserDataInfo SaveWeiXinUser(UserDataInfo userDataInfo) { UserDataInfo newUserDataInfo = null; try { User user = db.User.FirstOrDefault(n => n.OpenID == userDataInfo.OpenID); if (user == null) { user = new User(); user.OpenID = userDataInfo.OpenID; user.AttentionDateTime = userDataInfo.AttentionDateTime; user.CanAttention = userDataInfo.CanAttention; user.City = userDataInfo.City; user.Country = userDataInfo.Country; user.CreationDateTime = userDataInfo.CreationDateTime; user.DisplayName = userDataInfo.DisplayName; user.IsUse = userDataInfo.IsUse; user.Province = userDataInfo.Province; user.Remark = userDataInfo.Remark; user.Sex = userDataInfo.Sex; user.SourceProductID = userDataInfo.SourceProductID; user.UserFace = userDataInfo.UserFace; user.CancelAttentionDateTime = null; ServerLogger.Info("SaveWeiXinUser :"******"User", Remark = string.Format("{0}关注了公众号,用户微信数据为:{1}", userDataInfo.DisplayName, Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)), CreationDate = DateTime.Now, CreationUserID = null }); } else { if (!user.CanAttention) { user.CanAttention = true; user.AttentionDateTime = DateTime.Now; db.SaveChanges(); AddSystemLog(new SystemLogDataInfo() { ModulePage = "User", Remark = string.Format("{0}重新关注了公众号,用户微信数据为:{1}", userDataInfo.DisplayName, Newtonsoft.Json.JsonConvert.SerializeObject(userDataInfo)), CreationDate = DateTime.Now, CreationUserID = null }); } } newUserDataInfo = SimpleObjectMapper.CreateTargetObject <User, UserDataInfo>(user); } catch (Exception e) { throw e; } return(newUserDataInfo); }
/// <summary> /// Starts the connection controller. /// </summary> public void Start() { // Log the server information ServerLogger.Info($"Server started on port {Port}"); IPEndPoint endPort = new IPEndPoint(IPAddress.Any, Port); // Bind the ServerSocket Socket.Bind(endPort); Connected = true; // Start receiving packets Socket.Listen(0); // Start accepting clients Socket.BeginAccept(new AsyncCallback(AcceptConnection), Socket); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { // Copy low level code //if (httpContext == null) // throw new ArgumentNullException("httpContext"); //Type baseType = typeof(AuthorizeAttribute); //FieldInfo userFI = baseType.GetField("_usersSplit", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic); //string[] _usersSplit = userFI.GetValue(this) as string[]; //FieldInfo roleFI = baseType.GetField("_rolesSplit", System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.NonPublic); //string[] _rolesSplit = roleFI.GetValue(this) as string[]; //IPrincipal user = httpContext.User; //bool result = user.Identity.IsAuthenticated && // (_usersSplit.Length <= 0 || Enumerable.Contains<string>((IEnumerable<string>)_usersSplit, user.Identity.Name, (IEqualityComparer<string>)StringComparer.OrdinalIgnoreCase)) && // (_rolesSplit.Length <= 0 || Enumerable.Any<string>((IEnumerable<string>)_rolesSplit, new Func<string, bool>(user.IsInRole))); bool result = base.AuthorizeCore(httpContext); ServerLogger.Info(string.Format("Authorized? {0}", result.ToString())); return(result); }
public static HttpResponseMessage SuccesstoJson(Object obj, string Message) { HttpResponseMessage result = null; try { String str = ""; if (obj != null) { if (obj is String || obj is Char) { str = obj.ToString(); } else { str = JsonConvert.SerializeObject(obj); } if (obj is bool) { str = obj.ToString().ToLower(); } } if (!string.IsNullOrEmpty(Message)) { ServerLogger.Info(Message); } result = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(str, Encoding.GetEncoding("UTF-8"), "application/json") }; } catch (Exception ex) { result = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError }; ServerLogger.Error(ex.Message); } return(result); }
public static HttpResponseMessage FailtoJson(string Message, HttpStatusCode HttpStatusCode) { HttpResponseMessage result = null; try { if (!string.IsNullOrEmpty(Message)) { ServerLogger.Info(Message); } result = new HttpResponseMessage { StatusCode = HttpStatusCode }; } catch (Exception ex) { result = new HttpResponseMessage { StatusCode = HttpStatusCode.InternalServerError }; ServerLogger.Error(ex.Message); } return(result); }
public override void OnAuthorization(AuthorizationContext filterContext) { BaseAdminController controller = filterContext.Controller as BaseAdminController; if (controller != null) { base.OnAuthorization(filterContext); ServerLogger.Info(string.Format("Authorize controller {0}", controller.GetType().ToString())); ISystemUserService systemUserService = (ISystemUserService)Bootstrapper.GetService <ISystemUserService>(); SystemUserDataInfo user = systemUserService.GetSystemUserDataInfoByID(controller.CurrentUserID); if (user == null) { filterContext.Result = new RedirectResult("/Account/AdminLogin"); } else { base.OnAuthorization(filterContext); } } else { base.OnAuthorization(filterContext); } }
public async Task GetUserGeneralItems(int userId, int netId, bool startedCommerceSession) { List <UserGeneralItem> generalItems = new List <UserGeneralItem>(); try { generalItems = await m_database.GetUserGeneralItems(userId); var player = Players[netId]; var playerSrc = netId.ToString(); if (startedCommerceSession) { List <UserGeneralItem> webshopGeneralItems = new List <UserGeneralItem>(); int deactivatedGeneralItems = 0; foreach (var generalItem in Cache.GeneralItems) { if (generalItem.TebexPackageId != 0) { bool existsInData = generalItems.Exists(o => o.ItemId == generalItem.Id); bool owned = DoesPlayerOwnSkuExt(playerSrc, generalItem.TebexPackageId); if (owned) { if (!existsInData) { var userOutfit = new UserGeneralItem { ItemId = generalItem.Id, UserId = userId, CreatedAt = DateTime.UtcNow, ExpirationDate = DateTime.UtcNow + generalItem.Duration, IsOneTimeActivation = generalItem.Type == (int)ShopItemType.XPBOOST ? false : true }; userOutfit = await m_database.InsertUserGeneralItem(userOutfit); webshopGeneralItems.Add(userOutfit); } } else { if (existsInData) { var deletedItems = await m_database.DeleteUserGeneralItem(generalItem.Id, userId); deactivatedGeneralItems += deletedItems; } } } } m_logger.Info($"Player {playerSrc} has {webshopGeneralItems.Count} NEW owned General Item Tebex packages"); generalItems.AddRange(webshopGeneralItems); if (player != null && (webshopGeneralItems.Count != 0 | deactivatedGeneralItems != 0)) { player.TriggerEvent("shop:webshop_outfits_count_update", webshopGeneralItems.Count, deactivatedGeneralItems); } } else { if (player != null) { player.TriggerEvent("shop:webshop_error_loading"); } } m_userGeneralItems.AddOrUpdate(userId, generalItems, (key, oldValue) => oldValue = generalItems); } catch (Exception ex) { m_logger.Exception("GetUserOutfits", ex); } finally { List <int> ownedGeneralItemIds = new List <int>(); foreach (var item in generalItems) { ownedGeneralItemIds.Add(item.ItemId); } Players[netId].TriggerEvent("shop:owneditems", JsonConvert.SerializeObject(ownedGeneralItemIds)); } }