/// <summary> /// Registers a user with the system according to the given Alchemy Context. /// </summary> /// <param name="ctx">The user context.</param> public static void RegisterUser(UserContext ctx) { //create the user object User user = new User(ctx); //normally we would check the bool being returned from this function to see if it was added //but really the only time it wouldn't be added is if it already existed, which is ok in this case. users.TryAdd(ctx.ClientAddress.ToString(), user); }
/// <summary> /// Sends an API key update message to a client. /// </summary> /// <param name="user">The user to send the key to.</param> public static void DeliverApiKey(User user) { var message = new { action = WebDE.Types.Net.Action.KEY, apikey = user.ApiKey }; Server.Send(message, user); }
/// <summary> /// Send the specified message to the target user. /// This method will JSON stringify the message object. /// </summary> /// <param name="message">The message object.</param> /// <param name="user">The user object.</param> public static void Send(object message, User user) { string msg = JsonConvert.SerializeObject(message); user.UserContext.Send(msg); }
/// <summary> /// Checks if the target user is in the target group. /// </summary> /// <param name="group">The target group.</param> /// <param name="user">The target user.</param> /// <returns>Boolean indicating whether or not user is in target group.</returns> public static bool InGroup(WebDE.Types.AccessGroup group, User user) { if (API.GetGroups(user).Contains(group)) return true; return false; }
/// <summary> /// Get all groups that the target user belongs to. /// </summary> /// <param name="user">The target user.</param> /// <returns>All groups that the target user belongs to.</returns> public static WebDE.Types.AccessGroup[] GetGroups(User user) { if (user.ApiKey == string.Empty) return new WebDE.Types.AccessGroup[] { }; if (!accessList.ContainsKey(user.ApiKey)) return new WebDE.Types.AccessGroup[] { }; return accessList[user.ApiKey]; }