本文整理汇总了Python中h.accounts.models.User.activation方法的典型用法代码示例。如果您正苦于以下问题:Python User.activation方法的具体用法?Python User.activation怎么用?Python User.activation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类h.accounts.models.User
的用法示例。
在下文中一共展示了User.activation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register
# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import activation [as 别名]
def _register(self, username, email, password):
user = User(username=username, email=email, password=password)
self.request.db.add(user)
# Create a new activation for the user
activation = Activation()
self.request.db.add(activation)
user.activation = activation
# Flush the session to ensure that the user can be created and the
# activation is successfully wired up
self.request.db.flush()
# Send the activation email
message = activation_email(self.request, user)
mailer = get_mailer(self.request)
mailer.send(message)
self.request.session.flash(
jinja2.Markup(
_(
"Thank you for creating an account! "
"We've sent you an email with an activation link, "
"before you can sign in <strong>please check your email and open "
"the link to activate your account</strong>."
)
),
"success",
)
self.request.registry.notify(RegistrationEvent(self.request, user))
示例2: register
# 需要导入模块: from h.accounts.models import User [as 别名]
# 或者: from h.accounts.models.User import activation [as 别名]
def register(self):
"""
Handle submission of the new user registration form.
Validates the form data, creates a new activation for the user, sends
the activation mail, and then redirects the user to the index.
"""
err, appstruct = validate_form(self.form, self.request.POST.items())
if err is not None:
return err
# Create the new user from selected form fields
props = {k: appstruct[k] for k in ["username", "email", "password"]}
user = User(**props)
self.request.db.add(user)
# Create a new activation for the user
activation = Activation()
self.request.db.add(activation)
user.activation = activation
# Flush the session to ensure that the user can be created and the
# activation is successfully wired up
self.request.db.flush()
# Send the activation email
message = activation_email(self.request, user)
mailer = get_mailer(self.request)
mailer.send(message)
self.request.session.flash(
_(
"Thank you for registering! Please check "
"your e-mail now. You can continue by "
"clicking the activation link we have "
"sent you."
),
"success",
)
self.request.registry.notify(RegistrationEvent(self.request, user))
return httpexceptions.HTTPFound(location=self.request.route_url("index"))