本文整理汇总了Python中django_openid_auth.models.UserOpenID.user方法的典型用法代码示例。如果您正苦于以下问题:Python UserOpenID.user方法的具体用法?Python UserOpenID.user怎么用?Python UserOpenID.user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django_openid_auth.models.UserOpenID
的用法示例。
在下文中一共展示了UserOpenID.user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from django_openid_auth.models import UserOpenID [as 别名]
# 或者: from django_openid_auth.models.UserOpenID import user [as 别名]
def execute(self, args):
self._prepare(args)
from django.contrib.auth.models import User
from django_openid_auth.models import UserOpenID
# Django took over logging and we need it back
self.reset_logger(args, True)
try:
user = User.objects.get(username=args.username)
except User.DoesNotExist:
# We can only give up at that point, the user must exist.
self.logger.error('Error: No such user [{}]'.format(args.username))
sys.exit(self.SYS_ERROR.NO_SUCH_WEB_ADMIN_USER)
claimed_id = getattr(args, 'claimed-id')
try:
user_open_id = UserOpenID.objects.get(user=user)
except UserOpenID.DoesNotExist:
user_open_id = UserOpenID()
user_open_id.user = user
user_open_id.claimed_id = claimed_id
user_open_id.display_id = claimed_id # Same value for display_id
user_open_id.save()
self._ok(args)
示例2: confirm_openid
# 需要导入模块: from django_openid_auth.models import UserOpenID [as 别名]
# 或者: from django_openid_auth.models.UserOpenID import user [as 别名]
def confirm_openid(request, openid_id):
session = {'id': request.session.session_key}
current_url = settings.SITE_URL + request.path
oidutil.log = openid_logging
openid_consumer = consumer.Consumer(session, DjangoOpenIDStore())
if request.method == 'POST':
info = openid_consumer.complete(request.POST, current_url)
else:
info = openid_consumer.complete(request.GET, current_url)
if info.status == consumer.FAILURE:
return render_to_response('account/openid_confirmationfailed.html', {'message': info.message},
context_instance=RequestContext(request))
elif info.status == consumer.CANCEL:
return render_to_response('account/openid_confirmationfailed.html', {'message': '(cancelled by user)'},
context_instance=RequestContext(request))
elif info.status != consumer.SUCCESS:
return render_to_response('account/openid_confirmationfailed.html', {'message': '(unknown verification error)'},
context_instance=RequestContext(request))
try:
unconfirmed = UnconfirmedOpenId.objects.get(id=openid_id, user=request.user)
except UnconfirmedOpenId.DoesNotExist:
return render_to_response('account/openid_confirmationfailed.html',
{'message': 'ID %s not found in the database.' % openid_id},
context_instance=RequestContext(request))
# TODO: check for a reasonable expiration time
confirmed = ConfirmedOpenId()
confirmed.user = unconfirmed.user
confirmed.ip_address = '0.0.0.0'
confirmed.openid = unconfirmed.openid
confirmed.save()
unconfirmed.delete()
# if there's a single image in this user's profile, assign it to the new email
photos = confirmed.user.photos
if photos.count() == 1:
confirmed.set_photo(photos.get())
# Also allow user to login using this OpenID (if not taken already)
if not UserOpenID.objects.filter(claimed_id=confirmed.openid).exists():
user_openid = UserOpenID()
user_openid.user = request.user
user_openid.claimed_id = confirmed.openid
user_openid.display_id = confirmed.openid
user_openid.save()
return HttpResponseRedirect(reverse('libravatar.account.views.profile'))