def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): token = form.cleaned_data['access_token'] g = GraphAPI(token) facebook_me = g.get_object("me") email = valid_email_or_none(facebook_me.get('email')) social_id = facebook_me['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) account.link = facebook_me['link'] account.name = facebook_me['name'] if account.pk: account.save() data = dict(email=email, facebook_me=facebook_me) # some facebook accounts don't have this data data.update((k,v) for (k,v) in facebook_me.items() if k in ['username', 'first_name', 'last_name']) ret = complete_social_login(request, data, account) if not ret: ret = render_authentication_error(request) return ret
def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): try: token = form.cleaned_data['access_token'] g = GraphAPI(token) facebook_me = g.get_object("me") email = valid_email_or_none(facebook_me.get('email')) social_id = facebook_me['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) data = dict(email=email, facebook_access_token=token, facebook_me=facebook_me) # some facebook accounts don't have this data data.update((k,v) for (k,v) in facebook_me.items() if k in ['username', 'first_name', 'last_name']) # Don't save partial/temporary accounts that haven't # gone through the full signup yet, as there is no # User attached yet. if account.pk: account.sync(data) ret = complete_social_login(request, data, account) except (GraphAPIError, IOError): pass if not ret: ret = render_authentication_error(request) return ret
def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): try: token = form.cleaned_data['access_token'] g = GraphAPI(token) facebook_me = g.get_object("me") email = valid_email_or_none(facebook_me.get('email')) social_id = facebook_me['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) data = dict(email=email, facebook_access_token=token, facebook_me=facebook_me) # some facebook accounts don't have this data data.update((k, v) for (k, v) in facebook_me.items() if k in ['username', 'first_name', 'last_name']) # Don't save partial/temporary accounts that haven't # gone through the full signup yet, as there is no # User attached yet. if account.pk: account.sync(data) ret = complete_social_login(request, data, account) except (GraphAPIError, IOError): pass if not ret: ret = render_authentication_error(request) return ret
def facebook_callback(request): if request.GET.get('access_token') != None: fb_access_token = request.POST.get('access_token') facebook_account = FacebookAccount(user_id=request.user, access_token=fb_access_token) facebook_account.save() return_dict = {} return_dict['success'] = 'true' return HttpResponse(json.dumps(return_dict)) else: return render(request, 'channel.html')
def facebook_access(request): print "got to fb access" fb_access_token = request.POST.get('token') print "trying to get user data from db" fb_account = FacebookAccount.get_account(request.user.id) if fb_account is None: print "was not able to get user data from db" fb_account = FacebookAccount(user_id=request.user, access_token=fb_access_token) else: fb_account.access_token = fb_access_token fb_account.save() print "should be returning success" return_dict = {} return_dict['success'] = 'true' return HttpResponse(json.dumps(return_dict))
def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): token = form.cleaned_data['access_token'] g = GraphAPI(token) data = g.get_object("me") email = valid_email_or_none(data.get('email')) social_id = data['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) account.link = data['link'] account.name = data['name'] #adding the storing of users accesstoken account.access_token = token if account.pk: account.save() data = dict(email=email,facebook_me=data) ret = complete_social_login(request, data, account) if not ret: ret = render_authentication_error(request) return ret
def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): token = form.cleaned_data['access_token'] g = GraphAPI(token) facebook_me = g.get_object("me") email = valid_email_or_none(facebook_me.get('email')) social_id = facebook_me['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) account.link = facebook_me['link'] account.name = facebook_me['name'] if account.pk: account.save() data = dict(email=email, facebook_me=facebook_me) # some facebook accounts don't have this data data.update((k, v) for (k, v) in facebook_me.items() if k in ['username', 'first_name', 'last_name']) ret = complete_social_login(request, data, account) if not ret: ret = render_authentication_error(request) return ret
def facebook_comment(request): response = {} fb_account = FacebookAccount.get_account(request.user.id) if fb_account is None: response['success'] = 'false' response['message'] = 'Failed to get data for user' return response response['success'] = 'true' try: facebook_api.facebook_comment_post(request.POST.get('postId'), request.POST.get('message'), fb_account.access_token) except urllib2.HTTPError: print "Error: Token is invalid" return get_fb_url(1) return response
def facebook_like(request): response = {} fb_account = FacebookAccount.get_account(request.user.id) if fb_account is None: response['success'] = 'false' response['message'] = 'Failed to get data for user' return response response['success'] = 'true' try: facebook_api.facebook_like_post(request.POST.get('postId'), fb_account.access_token) except urllib2.HTTPError: print "Error: Token is invalid" return get_fb_url(1) return response
def facebook_feed_request(request): response = {} fb_account = FacebookAccount.get_account(request.user.id) #case where user has not added FB account yet if fb_account is None: response['success'] = 'false' response['message'] = 'Failed to get data for user' return response try: #success case, we can get their print "trying to get stuff from fb" response['success'] = 'true' response['updates'] = facebook_api.facebook_read_user_status_updates(fb_account.access_token) except Exception: #invalid token print "FB Error: Token is invalid" return get_fb_url(1) return response
def facebook_feed_request(request): response = {} fb_account = FacebookAccount.get_account(request.user.id) #case where user has not added FB account yet if fb_account is None: response['success'] = 'false' response['message'] = 'Failed to get data for user' return response try: #success case, we can get their print "trying to get stuff from fb" response['success'] = 'true' response['updates'] = facebook_api.facebook_read_user_status_updates( fb_account.access_token) except Exception: #invalid token print "FB Error: Token is invalid" return get_fb_url(1) return response
def signin(request): if request.method == 'POST': email = request.POST['email'] password = request.POST['password'] user = authenticate(email=email, password=password) if (user is not None) and (user.is_active): login(request, user) facebook_account = FacebookAccount.get_account(request_id=request.user.id) twitter_account = TwitterAccount.get_account(request_id=request.user.id) if facebook_account is None and twitter_account is None: return redirect('/feed/', {'username': email}) else: return redirect('/feed/', {'username': email}) else: form = EmailAuthenticationForm() form.non_field_errors = 'Your email and password were incorrect.' return render(request, 'index.html', {'form': form}) else: form = EmailAuthenticationForm() return render(request, 'index.html', {'form': form})
def signin(request): if request.method == 'POST': email = request.POST['email'] password = request.POST['password'] user = authenticate(email=email, password=password) if (user is not None) and (user.is_active): login(request, user) facebook_account = FacebookAccount.get_account( request_id=request.user.id) twitter_account = TwitterAccount.get_account( request_id=request.user.id) if facebook_account is None and twitter_account is None: return redirect('/feed/', {'username': email}) else: return redirect('/feed/', {'username': email}) else: form = EmailAuthenticationForm() form.non_field_errors = 'Your email and password were incorrect.' return render(request, 'index.html', {'form': form}) else: form = EmailAuthenticationForm() return render(request, 'index.html', {'form': form})
def login(request): ret = None if request.method == 'POST': form = FacebookConnectForm(request.POST) if form.is_valid(): token = form.cleaned_data['access_token'] g = GraphAPI(token) data = g.get_object("me") email = valid_email_or_none(data.get('email')) social_id = data['id'] try: account = FacebookAccount.objects.get(social_id=social_id) except FacebookAccount.DoesNotExist: account = FacebookAccount(social_id=social_id) account.link = data['link'] account.name = data['name'] if account.pk: account.save() data = dict(email=email, facebook_me=data) ret = complete_social_login(request, data, account) if not ret: ret = render_authentication_error(request) return ret