本文整理汇总了Python中mongoengine.django.auth.User.name方法的典型用法代码示例。如果您正苦于以下问题:Python User.name方法的具体用法?Python User.name怎么用?Python User.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoengine.django.auth.User
的用法示例。
在下文中一共展示了User.name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_new_observer
# 需要导入模块: from mongoengine.django.auth import User [as 别名]
# 或者: from mongoengine.django.auth.User import name [as 别名]
def create_new_observer(self, email, name, surname, affiliation, password):
"""
Create a new, inactive ``Observer``, generates a
``profile`` and emails its activation key,
returning the new ``Observer``.
"""
new_observer = RegisteredObserver()
user = User()
user.email = email
user.username = email
user.is_active = False
new_observer.name = name
new_observer.surname = surname
user.name = name + surname
new_observer.affiliation = affiliation
user.set_password(password)
new_observer.set_password(password)
new_observer.approved = False
new_observer.registration_confirmed = False
sha1 = hashlib.sha1()
sha1.update(str(random.random()))
salt = sha1.hexdigest()[:5]
sha1 = hashlib.sha1()
sha1.update(salt.encode('ascii', 'ignore') + email.encode('ascii', 'ignore') + name.encode('ascii', 'ignore') + affiliation.encode('ascii', 'ignore'))
new_observer.activation_key = sha1.hexdigest()
user.save()
new_observer.user = user
new_observer.save()
from django.core.mail import send_mail
subject = "Registration activation request for NZDIS: Tobacco Free"
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('activation_email.txt',
{ 'activation_key': new_observer.activation_key,
'name': new_observer.name,
})
logger.debug("Trying to email this:\n" + message)
try:
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [new_observer.user.email])
except:
pass
# TODO what should we do if the email connection fails?
# should never happen on the server
return new_observer