Esempio n. 1
0
        /// <summary>
        /// Check session and returns some related objects.
        /// </summary>
        /// <param name="sessionKey"></param>
        /// <returns></returns>
        public static AuthenticationResponse AuthenticateSession(string sessionKey)
        {
            // Get session
            Sessions session = MongoManager.FirstOrDefault <Sessions>(s => s.Key == sessionKey);

            if (session == null)
            {
                // BAD auth
                log.Error("Auth FAILED, fail to get the fetched database row.");
                return(BaseResponse <AuthenticationResponse> .BadAuth());
            }

            // OK, session existing
            log.Information($"Auth OK, for userId = [{session.UserId}].");

            return(new AuthenticationResponse(MongoManager.First <Users>(x => x._id == session.UserId), session));
        }
Esempio n. 2
0
        /// <summary>
        /// Save WebSocket user connections on hubs.
        /// </summary>
        public static void SaveUserConnectionIds()
        {
            Configurations configurations = MongoManager.First <Configurations>();
            SignalRServers server         = configurations.SignalRServers;
            SignalRHub     hub            = configurations.SignalRServers.Hubs.First(x => x.Type == SignalRHubTypes.Events);

            hub.ConnectedClients = UserConnectionIds.Sum(x => x.Value.Count);

            configurations.SignalRServers.Hubs[configurations.SignalRServers.Hubs.IndexOf(hub)] = hub;

            UpdateDefinition <Configurations> update = Builders <Configurations> .Update.Set(x => x.SignalRServers, server);

            MongoManager.UpdateItems(new List <ObjectId>()
            {
                configurations._id
            }, update);
        }
Esempio n. 3
0
 /// <summary>
 /// Get the user by a given user id.
 /// </summary>
 /// <param name="userId"></param>
 public static Users GetUser(ObjectId userId) => MongoManager.First <Users>(x => x._id == userId);