本文整理汇总了Python中django.contrib.auth.tokens.default_token_generator方法的典型用法代码示例。如果您正苦于以下问题:Python tokens.default_token_generator方法的具体用法?Python tokens.default_token_generator怎么用?Python tokens.default_token_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.tokens
的用法示例。
在下文中一共展示了tokens.default_token_generator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def send(self, users: List[UserProfile]) -> None:
"""Sends one-use only links for resetting password to target users
"""
for user_profile in users:
context = {
'email': user_profile.delivery_email,
'reset_url': generate_password_reset_url(user_profile, default_token_generator),
'realm_uri': user_profile.realm.uri,
'realm_name': user_profile.realm.name,
'active_account_in_realm': True,
}
send_email('zerver/emails/password_reset', to_user_ids=[user_profile.id],
from_address=FromAddress.tokenized_no_reply_address(),
from_name=FromAddress.security_email_from_name(user_profile=user_profile),
context=context)
示例2: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(
self,
domain_override=None,
email_template=None,
email_subject=None,
email_sender=None,
subject_template_name='', # not used
email_template_name='', # not used
use_https=False,
token_generator=default_token_generator,
from_email=None,
request=None
):
"""Generates a one-use only link for resetting password and sends to the user
"""
domain = request.get_host()
password_reset_email(
self.user_cache,
token_generator,
use_https=use_https,
domain=domain,
template=email_template,
subject=email_subject,
sender=email_sender
)
示例3: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None, # pylint: disable=too-many-arguments
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
current_site = Site.objects.get(pk=settings.SITE_ID)
# call the stock method and just overrides the domain
super().save(
current_site.domain,
subject_template_name,
email_template_name,
use_https,
token_generator,
from_email,
request,
html_email_template_name,
extra_email_context,
)
示例4: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
**kwargs):
# Complete override, because we have to use our sendmail()
for user in self.users_cache:
# Update verification token
profile = user.userprofile
profile.email_token = token_generator.make_token(user)
profile.save()
sendmail(user, subject_template_name, email_template_name, extra_context={
'user': user,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': profile.email_token,
'protocol': use_https and 'https' or 'http',
})
示例5: password_reset
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
domain_override='example.com',
email_template_name='registration/password_reset_email.html',
password_reset_form=PasswordResetForm, token_generator=default_token_generator,
post_reset_redirect=None):
if post_reset_redirect is None:
post_reset_redirect = reverse('drawquest.apps.drawquest_auth.views.password_reset_done')
if request.method == "POST":
form = password_reset_form(request.POST)
if form.is_valid():
opts = {}
opts['use_https'] = request.is_secure()
opts['token_generator'] = token_generator
opts['email_template_name'] = email_template_name
opts['request'] = request
if domain_override:
opts['domain_override'] = domain_override
if is_admin_site:
opts['domain_override'] = request.META['HTTP_HOST']
form.save(**opts)
return HttpResponseRedirect(post_reset_redirect)
else:
form = password_reset_form()
return r2r_jinja(template_name, {'form': form}, request)
示例6: send_registration_mail
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def send_registration_mail(
request,
user,
template=None,
sender=None,
token_generator=default_token_generator,
extra_context=None,
):
template = template or mailutil.get_email_template(
default_registration_template_name(), default_registration_template()
)
return send_auth_token_mail(
user,
request.get_host(),
request.build_absolute_uri(
reverse(
'tracker:confirm_registration',
kwargs={
'uidb64': urlsafe_base64_encode(force_bytes(user.pk)),
'token': token_generator.make_token(user),
},
)
),
template,
sender,
extra_context,
)
示例7: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(
self,
email_template=None,
token_generator=default_token_generator,
from_email=None,
request=None,
**kwargs,
):
if not email_template:
email_template = auth.default_registration_template()
user = self.get_existing_user()
if user is None:
email = self.cleaned_data['email']
username = email
if len(username) > 30:
username = email[:30]
AuthUser = get_user_model()
tries = 0
while user is None and tries < 5:
try:
user = AuthUser.objects.create(
username=username, email=email, is_active=False
)
except django.db.utils.IntegrityError:
tries += 1
username = tracker.util.random_num_replace(
username, 8, max_length=30
)
if tries >= 5:
raise forms.ValidationError(
'Something horrible happened, please try again'
)
return auth.send_registration_mail(
request,
user,
template=email_template,
sender=from_email,
token_generator=token_generator,
)
示例8: __init__
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def __init__(
self, user, token, token_generator=default_token_generator, *args, **kwargs
):
super(RegistrationConfirmationForm, self).__init__(*args, **kwargs)
self.user = user
self.token = token
self.token_generator = token_generator
if not self.check_token():
self.fields = {}
示例9: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None, subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html', use_https=False,
token_generator=default_token_generator, from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
PasswordResetEmail(
user,
site_name=site_name,
domain=domain,
extra_email_context=extra_email_context,
use_https=use_https,
token_generator=token_generator,
subject_template_name=subject_template_name,
email_template_name=email_template_name,
html_email_template_name=html_email_template_name
).send()
示例10: __init__
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def __init__(self, user, site_name=None, domain=None, extra_email_context=None, use_https=False,
token_generator=default_token_generator,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html', html_email_template_name=None):
self.to_emails = [user.email]
self.site_name = site_name
self.domain = domain
self.user = user
self.token_generator = token_generator
self.use_https = use_https
self.extra_email_context = extra_email_context
self.subject_template_name = subject_template_name
self.email_template_name = email_template_name
self.html_email_template_name = html_email_template_name
示例11: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
context = {
'email': user.email,
'domain': domain,
'site_name': site_name,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'user': user,
'token': token_generator.make_token(user),
'protocol': 'https' if use_https else 'http',
}
self.send_mail(subject_template_name, email_template_name,
context, from_email, user.email,
html_email_template_name=html_email_template_name)
示例12: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
"""
Generate a one-use only link for resetting password and send it to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
context = {
'email': email,
'domain': domain,
'site_name': site_name,
'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
'user': user,
'token': token_generator.make_token(user),
'protocol': 'https' if use_https else 'http',
}
if extra_email_context is not None:
context.update(extra_email_context)
self.send_mail(
subject_template_name, email_template_name, context, from_email,
email, html_email_template_name=html_email_template_name,
)
示例13: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
"""
Generate a one-use only link for resetting password and send it to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
context = {
'email': email,
'domain': domain,
'site_name': site_name,
'uid': urlsafe_base64_encode(force_bytes(user.pk)).decode(),
'user': user,
'token': token_generator.make_token(user),
'protocol': 'https' if use_https else 'http',
**(extra_email_context or {}),
}
self.send_mail(
subject_template_name, email_template_name, context, from_email,
email, html_email_template_name=html_email_template_name,
)
示例14: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
context = {
'email': user.email,
'domain': domain,
'site_name': site_name,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'user': user,
'token': token_generator.make_token(user),
'protocol': 'https' if use_https else 'http',
}
if extra_email_context is not None:
context.update(extra_email_context)
self.send_mail(subject_template_name, email_template_name,
context, from_email, user.email,
html_email_template_name=html_email_template_name)
示例15: save
# 需要导入模块: from django.contrib.auth import tokens [as 别名]
# 或者: from django.contrib.auth.tokens import default_token_generator [as 别名]
def save(self, domain_override=None,
subject_template_name='registration/password_reset_subject.txt',
email_template_name='registration/password_reset_email.html',
use_https=False, token_generator=default_token_generator,
from_email=None, request=None, html_email_template_name=None,
extra_email_context=None):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
email = self.cleaned_data["email"]
for user in self.get_users(email):
if not domain_override:
current_site = get_current_site(request)
site_name = current_site.name
domain = current_site.domain
else:
site_name = domain = domain_override
context = {
'email': email,
'domain': domain,
'site_name': site_name,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'user': user,
'token': token_generator.make_token(user),
'protocol': 'https' if use_https else 'http',
}
if extra_email_context is not None:
context.update(extra_email_context)
self.send_mail(
subject_template_name, email_template_name, context, from_email,
email, html_email_template_name=html_email_template_name,
)