本文整理汇总了Python中user.models.User.get_email方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_email方法的具体用法?Python User.get_email怎么用?Python User.get_email使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.models.User
的用法示例。
在下文中一共展示了User.get_email方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attempt_registration_nonmember
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_email [as 别名]
def attempt_registration_nonmember(request):
error_messages = []
# Check that name is provided
if not validator.name(request.POST['name']):
error_messages.append('invalid_name')
# Check that the email address is valid
if not validator.email(request.POST['email']):
error_messages.append('invalid_email')
# Check that the email address isn't in use
if User.objects.filter(identifier=request.POST['email']).exists():
error_messages.append('email_exists')
# Check that the password is long enough
if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
error_messages.append('too_short_password')
if len(error_messages) > 0:
request.session['user.registration_nonmember_attempt'] = {
'name': request.POST['name'],
'email': request.POST['email']
}
return None, error_messages
user = User(identifier=request.POST['email'], email=request.POST['email'])
user.first_name, user.last_name = request.POST['name'].rsplit(maxsplit=1)
user.set_consent_accepted_privacy_policy_date(None, False)
user.set_password(request.POST['password'])
user.save()
user.set_consent_dnt(
Forening.DNT_CENTRAL_ID,
'email',
True if request.POST.get('consent-dnt-communication-email') else False,
save=True,
)
authenticate(user=user)
log_user_in(request, user)
try:
message = render_to_string('common/user/login/registered_nonmember_email.txt', request=request)
send_mail(EMAIL_REGISTERED_SUBJECT, message, settings.DEFAULT_FROM_EMAIL, [user.get_email()])
except (SMTPException, SSLError, UnicodeEncodeError):
# Silently log and ignore this error. Consider warning the user that the email wasn't sent?
logger.warning(
"Klarte ikke å sende registreringskvitteringepost",
exc_info=sys.exc_info(),
extra={'request': request}
)
return user, None
示例2: attempt_registration_nonmember
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_email [as 别名]
def attempt_registration_nonmember(request):
error_messages = []
# Check that name is provided
if not validator.name(request.POST['name']):
error_messages.append('invalid_name')
# Check that the email address is valid
if not validator.email(request.POST['email']):
error_messages.append('invalid_email')
# Check that the email address isn't in use
if User.objects.filter(identifier=request.POST['email']).exists():
error_messages.append('email_exists')
# Check that the password is long enough
if len(request.POST['password']) < settings.USER_PASSWORD_LENGTH:
error_messages.append('too_short_password')
if len(error_messages) > 0:
request.session['user.registration_nonmember_attempt'] = {
'name': request.POST['name'],
'email': request.POST['email']
}
return None, error_messages
user = User(identifier=request.POST['email'], email=request.POST['email'])
user.first_name, user.last_name = request.POST['name'].rsplit(' ', 1)
user.set_password(request.POST['password'])
user.save()
authenticate(user=user)
log_user_in(request, user)
try:
t = loader.get_template('common/user/login/registered_nonmember_email.txt')
c = RequestContext(request)
send_mail(EMAIL_REGISTERED_SUBJECT, t.render(c), settings.DEFAULT_FROM_EMAIL, [user.get_email()])
except (SMTPException, SSLError):
# Silently log and ignore this error. Consider warning the user that the email wasn't sent?
logger.warning(u"Klarte ikke å sende registreringskvitteringepost",
exc_info=sys.exc_info(),
extra={'request': request}
)
return user, None