예제 #1
0
 def __call__ (self, *args, **kwargs):
   request = args[0]
   request.json = json.loads(request.body)
   
   if 'token' in request.json:
     session = User.get_session(request.json['token'])
     
     user = None
     try:
       user_id = session[SESSION_KEY]
       backend_path = session[BACKEND_SESSION_KEY]
       
     except KeyError:
       pass
       
     else:
       if backend_path in settings.AUTHENTICATION_BACKENDS:
         backend = load_backend(backend_path)
         user = backend.get_user(user_id)
         
     if user:
       request.user = user
       return self.target(*args, **kwargs)
       
   return http.JsonResponse({'status': 'login-required'})
   
예제 #2
0
    def __call__(self, *args, **kwargs):
        request = args[0]
        request.json = json.loads(request.body)

        if 'token' in request.json:
            session = User.get_session(request.json['token'])

            user = None
            try:
                user_id = session[SESSION_KEY]
                backend_path = session[BACKEND_SESSION_KEY]

            except KeyError:
                pass

            else:
                if backend_path in settings.AUTHENTICATION_BACKENDS:
                    backend = load_backend(backend_path)
                    user = backend.get_user(user_id)

            if user:
                request.user = user
                return self.target(*args, **kwargs)

        return http.JsonResponse({'status': 'login-required'})
예제 #3
0
def logout_view (request, token):
  try:
    session = User.get_session(token)
    
  except:
    raise http.Http404
    
  else:
    session.flush()
    
  return http.JsonResponse({'result': 'OK'})
예제 #4
0
def logout_view(request, token):
    try:
        session = User.get_session(token)

    except:
        raise http.Http404

    else:
        session.flush()

    return http.JsonResponse({'result': 'OK'})