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')
def change_pass(request): code = request.GET.get('code', '') if code: try: uid = fb_utils.get_userid(code, change_pass) if uid != request.user.fbprofile.fb_userid: messages.error(request, "Your facebook account did not" +\ " match the one registered with LitHub.") return redirect('bookswap.views.my_account') form = SetPasswordForm(user=request.user) if request.method=="POST": form = SetPasswordForm(request.user, request.POST) if form.is_valid(): form.save() messages.success(request, "Your password was "+\ "successfully changed.") return redirect("bookswap.views.my_account") return render(request, "fbconnect/password_change.html", {'form':form},) except ObjectDoesNotExist: 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')