本文整理汇总了Python中socialregistration.utils._https函数的典型用法代码示例。如果您正苦于以下问题:Python _https函数的具体用法?Python _https怎么用?Python _https使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_https函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: facebook_js
def facebook_js():
id = getattr(settings, 'FACEBOOK_APP_ID', None)
key = getattr(settings, 'FACEBOOK_API_KEY', None)
perms = getattr(settings, 'FACEBOOK_REQUEST_PERMISSIONS', None)
if not id:
warnings.warn("django-socialregistration: Please update your settings.py and add a FACEBOOK_APP_ID key", Warning)
return {'facebook_app_id': id, 'facebook_api_key': key, 'is_https' : bool(_https()), 'facebook_req_perms' : perms }
示例2: _callback_url
def _callback_url(request):
site_domain = Site.objects.get_current().domain
if site_domain != 'example.com':
# Site is properly configured. Use it
return 'http%s://%s%s' % (
_https(),
Site.objects.get_current().domain,
reverse('openid_callback')
)
# django.site is not configured. Figure out the domain from the request
# Why not just always do this?
url = request.build_absolute_uri( reverse('openid_callback') )
if _https():
url = re.sub('http://','https://',url)
return url
示例3: facebook_js
def facebook_js():
id = getattr(settings, "FACEBOOK_APP_ID", None)
key = getattr(settings, "FACEBOOK_API_KEY", None)
perms = getattr(settings, "FACEBOOK_REQUEST_PERMISSIONS", None)
if not id:
warnings.warn(
"django-socialregistration: Please update your settings.py and add a FACEBOOK_APP_ID key", Warning
)
return {"facebook_app_id": id, "facebook_api_key": key, "is_https": bool(_https()), "facebook_req_perms": perms}
示例4: openid_callback
def openid_callback(request, template='socialregistration/openid.html',
extra_context=dict(), account_inactive_template='socialregistration/account_inactive.html',
client_class = None):
"""
Catches the user when he's redirected back from the provider to our site
"""
client = client_class(
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)
_connect(request.user, profile, client)
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
)
# Client is not pickleable with the request on it
client.request = None
request.session['socialregistration_client'] = client
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, OpenIDProfile.objects.get(user = user), client)
return HttpResponseRedirect(_get_next(request))
return render_to_response(
template,
dict(),
context_instance=RequestContext(request)
)
示例5: openid_callback
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)
)
示例6: openid_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()
示例7: openid_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(), 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)
示例8: openid_callback
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)
)
示例9: openid_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()
示例10: openid_redirect
def openid_redirect(request, client_class=None):
"""
Redirect the user to the openid provider
"""
request.session["next"] = _get_next(request)
request.session["openid_provider"] = request.GET.get("openid_provider")
client = client_class(
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)
示例11: openid_callback
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))
示例12: openid_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')
)
try:
return client.get_redirect()
except DiscoveryFailure:
request.session['openid_error'] = True
return HttpResponseRedirect(settings.LOGIN_URL)
示例13: openid_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')
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)
示例14: openid_callback
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
示例15: openid_callback
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)
)