Exemple #1
0
    def get(self, **kwargs):
        """Return user sessions info."""
        sessions = SessionActivity.query_by_user(user_id=current_user.get_id())
        results = [{
            'created': s.created,
            'current': SessionActivity.is_current(s.sid_s),
            'browser': s.browser,
            'browser_version': s.browser_version,
            'os': s.os,
            'device': s.device,
            'country': s.country
        } for s in sessions]

        return jsonify({'total': sessions.count(), 'results': results})
Exemple #2
0
 def delete(self, sid_s=None, **kwargs):
     """Revoke the given user session."""
     if SessionActivity.query_by_user(current_user.get_id()) \
             .filter_by(sid_s=sid_s).count() == 1:
         delete_session(sid_s=sid_s)
         db.session.commit()
         message = 'Session {0} successfully removed. {1}.'
         if SessionActivity.is_current(sid_s=sid_s):
             message = message.format(sid_s, "Logged out")
         else:
             message = message.format(sid_s, "Revoked")
         return jsonify({'message': message})
     else:
         return jsonify(
             {'message':
              'Unable to remove session {0}.'.format(sid_s)}), 400
Exemple #3
0
    def get(self, **kwargs):
        """Return user sessions info."""
        sessions = SessionActivity.query_by_user(user_id=current_user.get_id())
        results = [
            {
                "created": s.created,
                "current": SessionActivity.is_current(s.sid_s),
                "browser": s.browser,
                "browser_version": s.browser_version,
                "os": s.os,
                "device": s.device,
                "country": s.country,
            }
            for s in sessions
        ]

        return jsonify({"total": sessions.count(), "results": results})