diff options
author | hrcerqueira <hrcerqueira@gmail.com> | 2010-01-22 01:39:13 +0000 |
---|---|---|
committer | hrcerqueira <hrcerqueira@gmail.com> | 2010-01-22 01:39:13 +0000 |
commit | d305ad98090558eb872c97f69addd2163f8ba5bd (patch) | |
tree | 08472efc2490125d56c6dd3274f4e06fd2db147f /fbconnect/views.py | |
parent | c18bda49f13afb4e2eaaf9ccb35098ee174e3afc (diff) | |
download | askbot-d305ad98090558eb872c97f69addd2163f8ba5bd.tar.gz askbot-d305ad98090558eb872c97f69addd2163f8ba5bd.tar.bz2 askbot-d305ad98090558eb872c97f69addd2163f8ba5bd.zip |
Handle the case were user logs in with facebook for the first time.
Diffstat (limited to 'fbconnect/views.py')
-rwxr-xr-x | fbconnect/views.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/fbconnect/views.py b/fbconnect/views.py new file mode 100755 index 00000000..2acb1dc0 --- /dev/null +++ b/fbconnect/views.py @@ -0,0 +1,63 @@ +from django.shortcuts import render_to_response as render
+from django.template import RequestContext +from django.http import HttpResponseRedirect +from django.utils.safestring import mark_safe +from django.core.urlresolvers import reverse +from django.contrib.auth.models import User +from django.contrib.auth import login +from models import FBAssociation +from forum.forms import EditUserEmailFeedsForm +from django.conf import settings + +import fb +import forms + +import logging + +def signin(request): + user_state = fb.get_user_state(request) + + if user_state == fb.STATES['FIRSTTIMER']: + return HttpResponseRedirect(reverse('fb_user_register')) + + return HttpResponseRedirect('/') + +def register(request): + if fb.get_user_state(request) == fb.STATES['FIRSTTIMER']: + user_data = fb.get_user_data(request.COOKIES) + + if 'bnewaccount' in request.POST.keys(): + form1 = forms.FBConnectRegisterForm(request.POST) + email_feeds_form = EditUserEmailFeedsForm(request.POST) + + if (form1.is_valid() and email_feeds_form.is_valid()): + tmp_pwd = User.objects.make_random_password()
+ user_ = User.objects.create_user(form1.cleaned_data['username'],
+ form1.cleaned_data['email'], tmp_pwd)
+
+ user_.set_unusable_password() + + uassoc = FBAssociation(user=user_, fbuid=user_data['uid']) + uassoc.save() + + user_.backend = "django.contrib.auth.backends.ModelBackend"
+ login(request, user_)
+ email_feeds_form.save(user_) + + return HttpResponseRedirect('/') + else: + form1 = forms.FBConnectRegisterForm(initial={
+ 'next': '/',
+ 'username': user_data['name'],
+ 'email': '',
+ }) + + email_feeds_form = EditUserEmailFeedsForm() + + return render('authopenid/complete.html', {
+ 'form1': form1,
+ 'email_feeds_form': email_feeds_form,
+ 'provider':mark_safe('facebook'),
+ 'login_type':'facebook',
+ 'gravatar_faq_url':reverse('faq') + '#gravatar',
+ }, context_instance=RequestContext(request)) |