# Path: openid_consumer/views.py
# def complete(request, on_success=None, on_failure=None, 
#              failure_template='openid_consumer/failure.html'):
#     
#     on_success = on_success or default_on_success
#     on_failure = on_failure or default_on_failure
#     
#     consumer = Consumer(request.session, DjangoOpenIDStore())
#     #dummydebug
#     #for r in request.GET.items():
#     #    print r
# 
#     # JanRain library raises a warning if passed unicode objects as the keys,
#     # so we convert to bytestrings before passing to the library
#     query_dict = dict([
#         (k.encode('utf8'),
#          v.encode('utf8')) for k, v in request.REQUEST.items()
#     ])
# 
#     url = get_url_host(request) + request.path
#     openid_response = consumer.complete(query_dict, url)
#     if openid_response.status == SUCCESS:
#         return on_success(request,
#                           openid_response.identity_url,
#                           openid_response)
#     elif openid_response.status == CANCEL:
#         return on_failure(request, 
#                           _('The request was cancelled'), failure_template)
#     elif openid_response.status == FAILURE:
#         return on_failure(request, openid_response.message, failure_template)
#     elif openid_response.status == SETUP_NEEDED:
#         return on_failure(request, _('Setup needed'), failure_template)
#     else:
#         assert False, "Bad openid status: %s" % openid_response.status
# 
# def signout(request):
#     request.session['openids'] = []
#     next = request.GET.get('next', '/')
#     if not is_valid_next_url(next):
#         next = '/'
#     return HttpResponseRedirect(next)


from django.conf.urls.defaults import *
from openid_consumer.views import complete, signout
from django.views.generic.base import TemplateView

#Login Views
urlpatterns = patterns('socialauth.views',
    url(r'^facebook_login/xd_receiver.htm$', TemplateView.as_view(template_name='socialauth/xd_receiver.htm'), name='socialauth_xd_receiver'),
    url(r'^facebook_login/$', 'facebook_login', name='socialauth_facebook_login'),
    url(r'^facebook_login/done/$', 'facebook_login_done', name='socialauth_facebook_login_done'),
    url(r'^login/$', 'login_page', name='socialauth_login_page'),
    url(r'^openid_login/$', 'openid_login_page', name='socialauth_openid_login_page'),
    url(r'^twitter_login/$', 'twitter_login', name='socialauth_twitter_login'),
    url(r'^twitter_login/done/$', 'twitter_login_done', name='socialauth_twitter_login_done'),
    url(r'^linkedin_login/$', 'linkedin_login', name='socialauth_linkedin_login'),
    url(r'^linkedin_login/done/$', 'linkedin_login_done', name='socialauth_linkedin_login_done'),
    url(r'^yahoo_login/$', 'yahoo_login', name='socialauth_yahoo_login'),
    url(r'^yahoo_login/complete/$', complete, name='socialauth_yahoo_complete'),
    url(r'^gmail_login/$', 'gmail_login', name='socialauth_google_login'),

# Path: openid_consumer/views.py
# def complete(request, on_success=None, on_failure=None, 
#              failure_template='openid_consumer/failure.html'):
#     
#     on_success = on_success or default_on_success
#     on_failure = on_failure or default_on_failure
#     
#     consumer = Consumer(request.session, DjangoOpenIDStore())
#     #dummydebug
#     #for r in request.GET.items():
#     #    print r
# 
#     # JanRain library raises a warning if passed unicode objects as the keys,
#     # so we convert to bytestrings before passing to the library
#     query_dict = dict([
#         (k.encode('utf8'),
#          v.encode('utf8')) for k, v in request.REQUEST.items()
#     ])
# 
#     url = get_url_host(request) + request.path
#     openid_response = consumer.complete(query_dict, url)
#     if openid_response.status == SUCCESS:
#         return on_success(request,
#                           openid_response.identity_url,
#                           openid_response)
#     elif openid_response.status == CANCEL:
#         return on_failure(request, 
#                           _('The request was cancelled'), failure_template)
#     elif openid_response.status == FAILURE:
#         return on_failure(request, openid_response.message, failure_template)
#     elif openid_response.status == SETUP_NEEDED:
#         return on_failure(request, _('Setup needed'), failure_template)
#     else:
#         assert False, "Bad openid status: %s" % openid_response.status
# 
# def signout(request):
#     request.session['openids'] = []
#     next = request.GET.get('next', '/')
#     if not is_valid_next_url(next):
#         next = '/'
#     return HttpResponseRedirect(next)


# Path: socialauth/urls.py
from django.conf.urls.defaults import *
from openid_consumer.views import complete, signout
from django.views.generic.base import TemplateView


#Login Views
urlpatterns = patterns('socialauth.views',
    url(r'^facebook_login/xd_receiver.htm$', TemplateView.as_view(template_name='socialauth/xd_receiver.htm'), name='socialauth_xd_receiver'),
    url(r'^facebook_login/$', 'facebook_login', name='socialauth_facebook_login'),
    url(r'^facebook_login/done/$', 'facebook_login_done', name='socialauth_facebook_login_done'),
    url(r'^login/$', 'login_page', name='socialauth_login_page'),
    url(r'^openid_login/$', 'openid_login_page', name='socialauth_openid_login_page'),
    url(r'^twitter_login/$', 'twitter_login', name='socialauth_twitter_login'),
    url(r'^twitter_login/done/$', 'twitter_login_done', name='socialauth_twitter_login_done'),
    url(r'^linkedin_login/$', 'linkedin_login', name='socialauth_linkedin_login'),
    url(r'^linkedin_login/done/$', 'linkedin_login_done', name='socialauth_linkedin_login_done'),
    url(r'^yahoo_login/$', 'yahoo_login', name='socialauth_yahoo_login'),
    url(r'^yahoo_login/complete/$', complete, name='socialauth_yahoo_complete'),
    url(r'^gmail_login/$', 'gmail_login', name='socialauth_google_login'),

    url(r'^gmail_login/complete/$', complete, name='socialauth_google_complete'),