Ejemplo n.º 1
0
    def get_session(self, request):
        # Set last activity on session to the current time to prevent session timeout
        request.session['last_session_request'] = int(time.time())
        # Default to active, only assume not active when explicitly set.
        active = True if request.GET.get('active', 'true') == 'true' else False
        user = get_user(request)
        if isinstance(user, AnonymousUser):
            return {
                'id': 'current',
                'username': '',
                'full_name': '',
                'user_id': None,
                'facility_id': getattr(Facility.get_default_facility(), 'id',
                                       None),
                'kind': ['anonymous'],
                'error': '200'
            }

        session = {
            'id': 'current',
            'username': user.username,
            'full_name': user.full_name,
            'user_id': user.id,
            'can_manage_content': user.can_manage_content
        }
        roles = Role.objects.filter(user_id=user.id)

        if len(roles) is 0:
            session.update({
                'facility_id': user.facility_id,
                'kind': ['learner'],
                'error': '200'
            })
        else:
            session.update({
                'facility_id': user.facility_id,
                'kind': [],
                'error': '200'
            })
            for role in roles:
                if role.kind == 'admin':
                    session['kind'].append('admin')
                elif role.kind == 'coach':
                    session['kind'].append('coach')
                elif role.kind == 'classroom assignable coach':
                    session['kind'].append('classroom assignable coach')

        if user.is_superuser:
            session['kind'].insert(0, 'superuser')

        if active:
            UserSessionLog.update_log(user)

        return session
Ejemplo n.º 2
0
    def get_session(self, request):
        user = get_user(request)
        if isinstance(user, AnonymousUser):
            return {
                'id': 'current',
                'username': '',
                'full_name': '',
                'user_id': None,
                'facility_id': getattr(Facility.get_default_facility(), 'id',
                                       None),
                'kind': ['anonymous'],
                'error': '200'
            }

        session = {
            'id': 'current',
            'username': user.username,
            'full_name': user.full_name,
            'user_id': user.id
        }
        if isinstance(user, DeviceOwner):
            session.update({
                'facility_id':
                getattr(Facility.get_default_facility(), 'id', None),
                'kind': ['superuser'],
                'error':
                '200'
            })
            return session
        else:
            roles = Role.objects.filter(user_id=user.id)
            if len(roles) is not 0:
                session.update({
                    'facility_id': user.facility_id,
                    'kind': [],
                    'error': '200'
                })
                for role in roles:
                    if role.kind == 'admin':
                        session['kind'].append('admin')
                    else:
                        session['kind'].append('coach')
            else:
                session.update({
                    'facility_id': user.facility_id,
                    'kind': ['learner'],
                    'error': '200'
                })

            UserSessionLog.update_log(user)

            return session
Ejemplo n.º 3
0
    def get_session(self, request):
        # Set last activity on session to the current time to prevent session timeout
        request.session['last_session_request'] = int(time.time())
        # Default to active, only assume not active when explicitly set.
        active = True if request.GET.get('active', 'true') == 'true' else False
        user = get_user(request)
        if isinstance(user, AnonymousUser):
            return {'id': 'current',
                    'username': '',
                    'full_name': '',
                    'user_id': None,
                    'facility_id': getattr(Facility.get_default_facility(), 'id', None),
                    'kind': ['anonymous'],
                    'error': '200'}

        session = {'id': 'current',
                   'username': user.username,
                   'full_name': user.full_name,
                   'user_id': user.id,
                   'can_manage_content': user.can_manage_content}
        roles = Role.objects.filter(user_id=user.id)

        if len(roles) is 0:
            session.update({'facility_id': user.facility_id,
                            'kind': ['learner'],
                            'error': '200'})
        else:
            session.update({'facility_id': user.facility_id,
                            'kind': [],
                            'error': '200'})
            for role in roles:
                if role.kind == 'admin':
                    session['kind'].append('admin')
                elif role.kind == 'coach':
                    session['kind'].append('coach')

        if user.is_superuser:
            session['kind'].insert(0, 'superuser')

        if active:
            UserSessionLog.update_log(user)

        return session