Esempio n. 1
0
def get_test_user_token(request: GetTestUserTokenInRequest,
                        auth_checker_response: dict = Depends(admin_checker)):
    try:
        user = views.get_user(uow=bus.uow,
                              user_id=request.user_id,
                              app_id=auth_checker_response['app_id'])
        data = {"token": create_user_token(user)}
    except Exception as ex:
        raise HTTPException(status_code=400, detail=str(ex))
    return data
Esempio n. 2
0
def update_queue(request, drawid):
    user = get_user(request.user.username)
    if not user:
        return HttpResponse('forbidden')
    draw = Draw.objects.get(pk=drawid)
    qlist = json.loads(request.POST['queue'])
    queue = user.queues.filter(draw=draw)[0]
    if not queue:
        return HttpResponse('no queue')
    try:
        return json_response(edit(user, queue.id, qlist, draw))
    except Exception as e:
        return HttpResponse(e)
Esempio n. 3
0
def update_queue(request, drawid):
    user = get_user(request.user.username)
    if not user:
        return HttpResponse("forbidden")
    draw = Draw.objects.get(pk=drawid)
    qlist = json.loads(request.POST["queue"])
    queue = user.queues.filter(draw=draw)[0]
    if not queue:
        return HttpResponse("no queue")
    try:
        return json_response(edit(user, queue.id, qlist, draw))
    except Exception as e:
        return HttpResponse(e)
Esempio n. 4
0
def get_queue(request, drawid, last_version=0):
    user = get_user(request.user.username)
    last_version = int(last_version)
    if not user:
        return HttpResponse('no user')
    try:
        draw = Draw.objects.get(pk=drawid)
        queue = user.queues.get(draw=draw)
    except Exception as e:
        return HttpResponse(traceback.format_exc(2) + str(draw))
    try:
        return json_response(check(user, queue.id, last_version))
    except Exception as e:
        return HttpResponse(traceback.format_exc(2))
Esempio n. 5
0
def get_queue(request, drawid, last_version=0):
    user = get_user(request.user.username)
    last_version = int(last_version)
    if not user:
        return HttpResponse("no user")
    try:
        draw = Draw.objects.get(pk=drawid)
        queue = user.queues.get(draw=draw)
    except Exception as e:
        return HttpResponse(traceback.format_exc(2) + str(draw))
    try:
        return json_response(check(user, queue.id, last_version))
    except Exception as e:
        return HttpResponse(traceback.format_exc(2))
Esempio n. 6
0
def check_token(auth_checker_response: dict = Depends(user_checker)):
    try:
        user = views.get_user(uow=bus.uow,
                              user_id=auth_checker_response['user_id'],
                              app_id=auth_checker_response['app_id'])
        change_pass_on = user["change_pass_time"]
        output = {"message": "token valid"}
        un_auth_output = {"message": "token invalid"}
        if change_pass_on is None:
            return output
        if change_pass_on > auth_checker_response['change_pass_time']:
            return un_auth_output
        else:
            return output
    except Exception as ex:
        raise HTTPException(status_code=400, detail=str(ex))
 def test_get_user_with_no_uuid(self, mock_create_new_ureporter):
     mock_create_new_ureporter.return_value = 'mock Ureport instance'
     request = self.factory.post('/register/', {})
     get_user(request)
     mock_create_new_ureporter.assert_called_once_with()
 def test_get_user_with_uuid(self):
     request = self.factory.post('/register/', {'uuid': self.uuid})
     ureporter = get_user(request)
     self.assertEqual(ureporter, self.ureporter)