def openid_callback(request, template='socialregistration/openid.html', extra_context=dict()): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http://%s%s' % ( Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): user = authenticate(identity=request.GET.get('openid.claimed_id')) if user is None: request.session['socialregistration_user'] = User(username="******") request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id') ) return HttpResponseRedirect(reverse('socialregistration_setup')) else: login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict()): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http://%s%s' % (Site.objects.get_current().domain, reverse('openid_callback')), request.session.get('openid_provider')) if client.is_valid(): user = authenticate(identity=request.GET.get('openid.claimed_id')) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id')) return HttpResponseRedirect(reverse('socialregistration_setup')) else: login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response(template, dict(), context_instance=RequestContext(request))
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get(identity=request.GET.get('openid.claimed_id')) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(user=request.user, identity=request.GET.get('openid.claimed_id')) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=request.GET.get('openid.claimed_id')) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id') ) for key, value in getattr(client, 'registration_data', {}).items(): request.session['social_suggested_%s' % key] = value return HttpResponseRedirect(reverse('socialregistration_setup')) else: login(request, user) return HttpResponseRedirect(_get_next(request)) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): identity = client.result.identity_url if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get(identity=identity) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(user=request.user, identity=identity) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=identity) if user is None: user = User() user_info = client.get_user_info() user.first_name, user.last_name = user_info.get('fullname', ' ').split(' ', 1) user.email = user_info.get('email', '') request.session['socialregistration_user'] = user request.session['socialregistration_profile'] = OpenIDProfile( identity=identity ) return HttpResponseRedirect(reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') client = OpenID( request, 'http://%s%s' % (Site.objects.get_current().domain, reverse('openid_callback')), request.GET.get('openid_provider')) return client.get_redirect()
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session["next"] = _get_next(request) request.session["openid_provider"] = request.GET.get("openid_provider") client = OpenID( request, "http%s://%s%s" % (_https(), Site.objects.get_current().domain, reverse("openid_callback")), request.GET.get("openid_provider"), ) return client.get_redirect()
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ if request.GET.get("openid.mode", "") == "cancel": return HttpResponseRedirect(_get_next(request)) client = OpenID( request, _openid_callback_url(), request.session.get('openid_provider') ) if client.is_valid(): identity = client.result.identity_url if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get( identity=identity, site=Site.objects.get_current()) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(user=request.user, identity=identity) return successful_account_link(request, profile) user = authenticate(identity=identity) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=identity ) return HttpResponseRedirect(reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): identity = client.result.identity_url if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get(identity=identity) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(user=request.user, identity=identity) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=identity) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=identity ) return HttpResponseRedirect(reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session["next"] = _get_next(request) request.session["openid_provider"] = request.GET.get("openid_provider") client = OpenID( request, "http%s://%s%s" % (_https(), request.get_host(), reverse("openid_callback")), request.GET.get("openid_provider"), ) try: return client.get_redirect() except DiscoveryFailure: request.session["openid_error"] = True return HttpResponseRedirect(settings.LOGIN_URL)
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') client = OpenID( request, 'http://%s%s' % ( Site.objects.get_current().domain, reverse('openid_callback') ), request.GET.get('openid_provider') ) return client.get_redirect()
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile, created = OpenIDProfile.objects.get_or_create(user=request.user, identity=request.GET.get('openid.claimed_id')) except IntegrityError: request.user.message_set.create(message=_('This openid has already been connected to a user.')) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=request.GET.get('openid.claimed_id')) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id') ) return HttpResponseRedirect(reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') client = OpenID( request, 'http%s://%s%s' % (_https(), Site.objects.get_current().domain, reverse('openid_callback')), request.GET.get('openid_provider')) try: return client.get_redirect() except DiscoveryFailure: request.session['openid_error'] = True return HttpResponseRedirect(settings.LOGIN_URL)
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') client = OpenID( request, _callback_url(request), request.GET.get('openid_provider') ) try: return client.get_redirect() except DiscoveryFailure: request.session['openid_error'] = True return HttpResponseRedirect(settings.LOGIN_URL)
def openid_callback( request, template="socialregistration/openid.html", extra_context=dict(), account_inactive_template="socialregistration/account_inactive.html", ): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, "http%s://%s%s" % (_https(), Site.objects.get_current().domain, reverse("openid_callback")), request.session.get("openid_provider"), ) if client.is_valid(): identity = client.result.identity_url if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get(identity=identity) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(user=request.user, identity=identity) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=identity) if user is None: request.session["socialregistration_user"] = User() request.session["socialregistration_profile"] = OpenIDProfile(identity=identity) return HttpResponseRedirect(reverse("socialregistration_setup")) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response(template, dict(), context_instance=RequestContext(request))
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') provider = request.GET.get('openid_provider') client = OpenID( request, _openid_callback_url(), provider ) try: return client.get_redirect() except DiscoveryFailure: return render_to_response( 'socialregistration/provider_failure.html', dict(provider=provider), context_instance=RequestContext(request) )
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.GET.get('openid_provider') ) try: return client.get_redirect() except DiscoveryFailure: request.session['openid_error'] = True return HttpResponseRedirect(settings.LOGIN_URL)
def openid_redirect(request): """ Redirect the user to the openid provider """ request.session['next'] = _get_next(request) request.session['openid_provider'] = request.GET.get('openid_provider') request.session['socialregistration_connect_object'] = get_object(request.GET) client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.GET.get('openid_provider') ) try: logger.info("Received redirect to %s from OpenID" % client.get_redirect()) return client.get_redirect() except DiscoveryFailure: request.session['openid_error'] = True logger.info("OpenID failure, sending user to login.") return HttpResponseRedirect(settings.LOGIN_URL)
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) if client.is_valid(): identity = client.result.identity_url if 'socialregistration_connect_object' in request.session and request.session['socialregistration_connect_object'] != None: # this exists so that social credentials can be attached to any arbitrary object using the same callbacks. # Under normal circumstances it will not be used. Put an object in request.session named 'socialregistration_connect_object' and it will be used instead. # After the connection is made it will redirect to request.session value 'socialregistration_connect_redirect' or settings.LOGIN_REDIRECT_URL or / try: # get the profile for this facebook UID and type of connected object profile = OpenIDProfile.objects.get(identity=identity, content_type=ContentType.objects.get_for_model(request.session['socialregistration_connect_object'].__class__), object_id=request.session['socialregistration_connect_object'].pk) except OpenIDProfile.DoesNotExist: OpenIDProfile.objects.create(content_object=request.session['socialregistration_connect_object'], identity=identity) del request.session['socialregistration_connect_object'] else: if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get(identity=identity, content_type=ContentType.objects.get_for_model(User)) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create(content_object=request.user, identity=identity) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=identity) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=identity ) return HttpResponseRedirect(reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) try: request_args = util.normalDict(request.GET) if request.method == 'POST': request_args.update(util.normalDict(request.POST)) if request_args: client.complete() c = client.consumer return_to = util.getViewURL(request, openid_callback) response = client.result ax_items = {} if response.status == consumer.SUCCESS: provider = request.session.get('openid_provider') # Set the schema uri depending on who the openid provier is: # request only name and email by default (same as Google schemas): schemas = GoogleOpenIDSchemas() if 'yahoo' in provider: schemas = YahooOpenIDSchemas() if 'myopenid' in provider: schemas = MyOpenIDSchemas() ax_response = {} ax_response = ax.FetchResponse.fromSuccessResponse(response) if ax_response: # Name and email schemas are always set, but not others so check if they are not empty first: birth_date = zip = gender = [] if schemas.birth_date_schema: birth_date = ax_response.get(schemas.birth_date_schema) if schemas.zip_schema: zip = ax_response.get(schemas.zip_schema) if schemas.gender_schema: gender = ax_response.get(schemas.gender_schema) ax_items = { 'display_name': ax_response.get(schemas.name_schema), 'email': ax_response.get(schemas.email_schema), 'birth_date': birth_date, 'home_zip': zip, 'gender': gender, } request.session['ax_items'] = ax_items except Exception, e: pass
def openid_callback( request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % (_https(), Site.objects.get_current().domain, reverse('openid_callback')), request.session.get('openid_provider')) try: request_args = util.normalDict(request.GET) if request.method == 'POST': request_args.update(util.normalDict(request.POST)) if request_args: client.complete() c = client.consumer return_to = util.getViewURL(request, openid_callback) response = client.result ax_items = {} if response.status == consumer.SUCCESS: provider = request.session.get('openid_provider') # Set the schema uri depending on who the openid provier is: # request only name and email by default (same as Google schemas): schemas = GoogleOpenIDSchemas() if 'yahoo' in provider: schemas = YahooOpenIDSchemas() if 'myopenid' in provider: schemas = MyOpenIDSchemas() ax_response = {} ax_response = ax.FetchResponse.fromSuccessResponse(response) if ax_response: # Name and email schemas are always set, but not others so check if they are not empty first: birth_date = zip = gender = [] if schemas.birth_date_schema: birth_date = ax_response.get(schemas.birth_date_schema) if schemas.zip_schema: zip = ax_response.get(schemas.zip_schema) if schemas.gender_schema: gender = ax_response.get(schemas.gender_schema) ax_items = { 'display_name': ax_response.get(schemas.name_schema), 'email': ax_response.get(schemas.email_schema), 'birth_date': birth_date, 'home_zip': zip, 'gender': gender, } request.session['ax_items'] = ax_items except Exception, e: pass
def openid_callback(request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % ( _https(), Site.objects.get_current().domain, reverse('openid_callback') ), request.session.get('openid_provider') ) # print 'hi' # print request.GET if client.is_valid(): if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.all().filter('identity=',request.GET.get('openid.claimed_id')).fetch(1)[0] except IndexError: # There can only be one profile with the same identity profile = OpenIDProfile( user = request.user, identity=request.GET.get('openid.claimed_id'), real_name=request.GET.get('openid.ax.value.fullname'), username=request.GET.get('openid.ax.value.nickname'), email=request.GET.get('openid.ax.value.email'), pic_url=request.GET.get('openid.ax.value.image'), ) profile.save() return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=request.GET.get('openid.claimed_id')) if user is None: user = User(username='******') request.session['social_suggested_username'] = request.GET.get('openid.ax.value.nickname') request.session['socialregistration_user'] = user if request.GET.get('openid.ext2.value.email'): request.session['social_suggested_username'] = request.GET.get('openid.ext2.value.email').split('@')[0] request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id'), internal_username=request.session['social_suggested_username'], email=request.GET.get('openid.ext2.value.email'), pic_url= "http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.ext2.value.email')).hexdigest() , ) elif request.GET.get('openid.sreg.email'): request.session['social_suggested_username'] = request.GET.get('openid.sreg.nickname') request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id'), real_name=request.GET.get('openid.sreg.fullname'), internal_username=request.GET.get('openid.sreg.nickname'), email=request.GET.get('openid.sreg.email'), pic_url="http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.sreg.email')).hexdigest(), ) elif request.GET.get('openid.ext1.value.email'): request.session['social_suggested_username'] = request.GET.get('openid.ext1.value.email').split('@')[0] request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id'), internal_username=request.session['social_suggested_username'], email=request.GET.get('openid.ext1.value.email'), pic_url= "http://www.gravatar.com/avatar/" + md5.md5(request.GET.get('openid.ext1.value.email')).hexdigest() , ) else: request.session['socialregistration_profile'] = OpenIDProfile( identity=request.GET.get('openid.claimed_id'), real_name=request.GET.get('openid.ax.value.fullname'), internal_username=request.GET.get('openid.ax.value.nickname'), email=request.GET.get('openid.ax.value.email'), pic_url=request.GET.get('openid.ax.value.image'), ) for key, value in getattr(client, 'registration_data', {}).items(): request.session['social_suggested_%s' % key] = value return HttpResponseRedirect(reverse('socialregistration_setup')) else: login(request, user) return HttpResponseRedirect(_get_next(request)) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request) ) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response( template, dict(), context_instance=RequestContext(request) )
def openid_callback( request, template='socialregistration/openid.html', extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html'): """ Catches the user when he's redirected back from the provider to our site """ client = OpenID( request, 'http%s://%s%s' % (_https(), Site.objects.get_current().domain, reverse('openid_callback')), request.session.get('openid_provider')) if client.is_valid(): identity = client.result.identity_url if 'socialregistration_connect_object' in request.session and request.session[ 'socialregistration_connect_object'] != None: # this exists so that social credentials can be attached to any arbitrary object using the same callbacks. # Under normal circumstances it will not be used. Put an object in request.session named 'socialregistration_connect_object' and it will be used instead. # After the connection is made it will redirect to request.session value 'socialregistration_connect_redirect' or settings.LOGIN_REDIRECT_URL or / try: # get the profile for this facebook UID and type of connected object profile = OpenIDProfile.objects.get( identity=identity, content_type=ContentType.objects.get_for_model( request.session['socialregistration_connect_object']. __class__), object_id=request. session['socialregistration_connect_object'].pk) except OpenIDProfile.DoesNotExist: OpenIDProfile.objects.create( content_object=request. session['socialregistration_connect_object'], identity=identity) del request.session['socialregistration_connect_object'] else: if request.user.is_authenticated(): # Handling already logged in users just connecting their accounts try: profile = OpenIDProfile.objects.get( identity=identity, content_type=ContentType.objects.get_for_model(User)) except OpenIDProfile.DoesNotExist: # There can only be one profile with the same identity profile = OpenIDProfile.objects.create( content_object=request.user, identity=identity) return HttpResponseRedirect(_get_next(request)) user = authenticate(identity=identity) if user is None: request.session['socialregistration_user'] = User() request.session['socialregistration_profile'] = OpenIDProfile( identity=identity) return HttpResponseRedirect( reverse('socialregistration_setup')) if not user.is_active: return render_to_response( account_inactive_template, extra_context, context_instance=RequestContext(request)) login(request, user) return HttpResponseRedirect(_get_next(request)) return render_to_response(template, dict(), context_instance=RequestContext(request))