def login(request):
    facebook_user = facebook.get_user_from_cookie(request.COOKIES,
        settings.FACEBOOK_APPID, settings.FACEBOOK_SECRET)
    next = request.GET.get("next", None)
    if facebook_user:
        access_token = facebook_user["access_token"]
        graph = facebook.GraphAPI(access_token)
        facebook_user = graph.get_object("me")
        email = facebook_user["email"]
        if graph:
            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                username = hashlib.md5(email).hexdigest()[:30]
                user = User.objects.create_user(username, email, "")
                user.first_name = facebook_user["first_name"]
                user.last_name = facebook_user["last_name"]
                user.save()
            is_new_user = "******" in locals()
            profile = user.get_profile()
            profile.facebook_access_token = access_token
            if is_new_user:
                profile.facebook_connect_only = True
            profile.save()
            user = auth.authenticate(username=profile.user.email, is_facebook_connect=True)
            logged_in.send(sender=None, request=request, user=user, is_new_user=is_new_user)
            auth.login(request, user)
            return redirect(next or "index")
    messages.error(request, "Facebook login credentials could not be verified, please try again.")
    return redirect(next or "login")
Example #2
0
def rsvp_account(request, event_id):
    event = get_object_or_404(Event, id=event_id)
    guest = event.current_guest(request)
    form = RsvpAccountForm(instance=guest, data=(request.POST or None))
    if form.is_valid():
        guest = form.save(request)
        user = auth.authenticate(username=guest.contributor.email, password=form.cleaned_data["password1"])
        logged_in.send(sender=None, request=request, user=user, is_new_user=True)
        auth.login(request, user)
        return redirect(event)
    return render_to_response("events/rsvp_account.html", locals(), context_instance=RequestContext(request))
Example #3
0
def login(request):
    facebook_user = facebook.get_user_from_cookie(request.COOKIES,
                                                  settings.FACEBOOK_APPID,
                                                  settings.FACEBOOK_SECRET)
    next = request.GET.get("next", None)
    if facebook_user:
        access_token = facebook_user["access_token"]
        graph = facebook.GraphAPI(access_token)
        facebook_user = graph.get_object("me")
        email = facebook_user["email"]
        if graph:
            try:
                user = User.objects.get(email=email)
            except User.DoesNotExist:
                username = hashlib.md5(email).hexdigest()[:30]
                user = User.objects.create_user(username, email, "")
                user.first_name = facebook_user["first_name"]
                user.last_name = facebook_user["last_name"]
                user.save()
            is_new_user = "******" in locals()
            profile = user.get_profile()
            profile.facebook_access_token = access_token
            if is_new_user:
                profile.facebook_connect_only = True
            profile.save()
            user = auth.authenticate(username=profile.user.email,
                                     is_facebook_connect=True)
            logged_in.send(sender=None,
                           request=request,
                           user=user,
                           is_new_user=is_new_user)
            auth.login(request, user)
            return redirect(next or "index")
    messages.error(
        request,
        "Facebook login credentials could not be verified, please try again.")
    return redirect(next or "login")