Example #1
0
def check_login(request):
    try:
        if not request.session.has_key('user_id'):
            raise User.DoesNotExist()
        user = User.objects.get(pk=request.session['user_id'])
        result = model_to_dict(user)
        result['signed_in'] = True
        if result.has_key('password_hash'):
            del result['password_hash']
    except User.DoesNotExist:
        return JsonResponse({'signed_in': False})
    return JsonResponse(result)
Example #2
0
def pick_item(request):
    try:
        form_data = json.loads(request.body)
    except:
        return JsonResponse({'errorMessage': 'Bad JSON format.'}, 400)
    try:
        result = {}
        if request.session.has_key('user_id'):
            user = User.objects.get(pk=request.session['user_id'])
        else:
            raise User.DoesNotExist()
        form = forms.PickItemForm(form_data)
        if form.is_valid():
            result = model_to_dict(form.pick(user))
        result['errors'] = form.errors
    except User.DoesNotExist:
        return JsonResponse({'errorMessage': 'Please login first.'}, 403)
    return JsonResponse(result)