本文整理汇总了Python中dekicompat.backends.DekiUserBackend.post_mindtouch_user方法的典型用法代码示例。如果您正苦于以下问题:Python DekiUserBackend.post_mindtouch_user方法的具体用法?Python DekiUserBackend.post_mindtouch_user怎么用?Python DekiUserBackend.post_mindtouch_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dekicompat.backends.DekiUserBackend
的用法示例。
在下文中一共展示了DekiUserBackend.post_mindtouch_user方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_inactive_user
# 需要导入模块: from dekicompat.backends import DekiUserBackend [as 别名]
# 或者: from dekicompat.backends.DekiUserBackend import post_mindtouch_user [as 别名]
def create_inactive_user(self, username, password, email):
"""
Create a new, inactive ``User`` and ``Profile``, generates a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
"""
new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
profile = UserProfile.objects.create(user=new_user)
try:
deki_user = DekiUserBackend.post_mindtouch_user(new_user)
except MindTouchAPIError, e:
new_user.delete()
raise e
示例2: create_inactive_user
# 需要导入模块: from dekicompat.backends import DekiUserBackend [as 别名]
# 或者: from dekicompat.backends.DekiUserBackend import post_mindtouch_user [as 别名]
def create_inactive_user(self, username, password, email):
"""
Create a new, inactive ``User`` and ``Profile``, generates a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
"""
new_user = User.objects.create_user(username, email, password)
new_user.is_active = False
new_user.save()
profile = UserProfile.objects.create(user=new_user)
deki_user = DekiUserBackend.post_mindtouch_user(new_user)
profile.deki_user_id = deki_user.id
profile.save()
registration_profile = self.create_profile(new_user)
self.send_confirmation_email(registration_profile)
return new_user
示例3: browserid_register
# 需要导入模块: from dekicompat.backends import DekiUserBackend [as 别名]
# 或者: from dekicompat.backends.DekiUserBackend import post_mindtouch_user [as 别名]
def browserid_register(request):
"""Handle user creation when assertion is valid, but no existing user"""
statsd_waffle_incr('users.browserid_register', 'signin_metrics')
redirect_to = request.session.get(SESSION_REDIRECT_TO,
getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
email = request.session.get(SESSION_VERIFIED_EMAIL, None)
if not email:
# This is pointless without a verified email.
return HttpResponseRedirect(redirect_to)
# Set up the initial forms
register_form = BrowserIDRegisterForm()
login_form = AuthenticationForm()
if request.method == 'POST':
statsd_waffle_incr('users.browserid_register.POST', 'signin_metrics')
# If the profile creation form was submitted...
if 'register' == request.POST.get('action', None):
register_form = BrowserIDRegisterForm(request.POST)
if register_form.is_valid():
try:
# If the registration form is valid, then create a new
# Django user, a new MindTouch user, and link the two
# together.
# TODO: This all belongs in model classes
username = register_form.cleaned_data['username']
user = User.objects.create(username=username, email=email)
user.set_unusable_password()
user.save()
profile = UserProfile.objects.create(user=user)
if settings.DEKIWIKI_ENDPOINT:
deki_user = DekiUserBackend.post_mindtouch_user(user)
profile.deki_user_id = deki_user.id
profile.save()
user.backend = 'django_browserid.auth.BrowserIDBackend'
auth.login(request, user)
# Bounce to the newly created profile page, since the user
# might want to review & edit.
statsd_waffle_incr('users.browserid_register.POST.SUCCESS',
'signin_metrics')
redirect_to = request.session.get(SESSION_REDIRECT_TO,
profile.get_absolute_url())
return set_browserid_explained(
_redirect_with_mindtouch_login(redirect_to,
user.username))
except MindTouchAPIError:
if user:
user.delete()
return render(request, '500.html',
{'error_message': "We couldn't "
"register a new account at this time. "
"Please try again later."})
# HACK: Pretend the session was modified. Otherwise, the data disappears
# for the next request.
request.session.modified = True
return render(request, 'users/browserid_register.html',
{'login_form': login_form,
'register_form': register_form})
示例4: browserid_register
# 需要导入模块: from dekicompat.backends import DekiUserBackend [as 别名]
# 或者: from dekicompat.backends.DekiUserBackend import post_mindtouch_user [as 别名]
def browserid_register(request):
"""Handle user creation when assertion is valid, but no existing user"""
redirect_to = request.session.get(SESSION_REDIRECT_TO,
getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
email = request.session.get(SESSION_VERIFIED_EMAIL, None)
if not email:
# This is pointless without a verified email.
return HttpResponseRedirect(redirect_to)
# Set up the initial forms
register_form = BrowserIDRegisterForm()
login_form = AuthenticationForm()
if request.method == 'POST':
# If the profile creation form was submitted...
if 'register' == request.POST.get('action', None):
register_form = BrowserIDRegisterForm(request.POST)
if register_form.is_valid():
# If the registration form is valid, then create a new Django
# user, a new MindTouch user, and link the two together.
# TODO: This all belongs in model classes
username = register_form.cleaned_data['username']
user = User.objects.create(username=username, email=email)
user.set_unusable_password()
user.save()
profile = UserProfile.objects.create(user=user)
deki_user = DekiUserBackend.post_mindtouch_user(user)
profile.deki_user_id = deki_user.id
profile.save()
user.backend = 'django_browserid.auth.BrowserIDBackend'
auth.login(request, user)
# Bounce to the newly created profile page, since the user
# might want to review & edit.
return HttpResponseRedirect(profile.get_absolute_url())
else:
# If login was valid, then set to the verified email
login_form = handle_login(request)
if login_form.is_valid():
if request.user.is_authenticated():
# Change email to new verified email, for next time
user = request.user
user.email = email
user.save()
return _redirect_with_mindtouch_login(redirect_to,
login_form.cleaned_data.get('username'),
login_form.cleaned_data.get('password'))
# HACK: Pretend the session was modified. Otherwise, the data disappears
# for the next request.
request.session.modified = True
return jingo.render(request, 'users/browserid_register.html',
{'login_form': login_form,
'register_form': register_form})