Пример #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));
        }