예제 #1
0
파일: views.py 프로젝트: tendaitt/LitHub
def assoc_with_curr_user(request):
    code = request.GET.get('code', '')
    if code:
        try:
            uid = fb_utils.get_userid(code, assoc_with_curr_user)
            matches = FBProfile.objects.filter(fb_userid=uid).count()
            if matches:
                messages.error(request, "This facebook is already " +\
                        "associated with an account on LitHub")
                return redirect('bookswap.views.my_account')
            try:
                profile = FBProfile.objects.get(user=request.user)
            except ObjectDoesNotExist:
                profile = FBProfile(user=request.user)
            profile.fb_userid = uid
            profile.save()
            messages.success(request, "LitHub now recognizes your " +\
                    "facebook account.")
            return redirect('bookswap.views.my_account')
        except ValueError:
            return render(request, "fbconnect/code_error.html")
    else:
        messages.error(request, "There was an error getting your " +\
            "information from facebook.")
    return redirect('django.contrib.auth.views.login')
예제 #2
0
파일: views.py 프로젝트: umangv/LitHub
def assoc_with_curr_user(request):
    try:
        fb = fb_utils.FBConnect(request.GET.get('code', ''),
                assoc_with_curr_user)
        uid = fb.userid
        matches = FBProfile.objects.filter(fb_userid=uid).count()
        if matches:
            messages.error(request, "Your facebook account is already " +\
                    "associated with another account on LitHub")
            return redirect('bookswap.views.my_account')
        try:
            profile = FBProfile.objects.get(user=request.user)
        except ObjectDoesNotExist:
            profile = FBProfile(user=request.user)
        profile.fb_userid = uid
        profile.save()
        messages.success(request, "LitHub now recognizes your " +\
                "facebook account.")
    except ValueError:
        messages.error(request, "There was an error getting your " +\
            "information from facebook.")
    return redirect('bookswap.views.my_account')