带钩子的涡轮齿轮2精细定制可插拔注册应用
tgapp-registration的Python项目详细描述
关于TGApp注册
注册是TurboGears2的可插入注册应用程序。 默认情况下,它将使用快速启动涡轮齿轮用户模型 但提供了一堆挂钩,可以用来更改注册 形式和大部分注册方面。
注册当前同时支持SQLAlchemy和MongoDB 用于数据库存储。
注册同时支持Turbomail和tgext.mailer发送电子邮件。
安装
tgapp注册既可以从pypi安装,也可以从bitbucket安装:
pip install tgapp-registration
应该只对大多数用户有效
如果要使用turbomail作为发件人,请从pypi安装:
pip install turbomail
如果要使用tgext.mailer作为发件人,请从pypi或bitbucket安装它:
pip install tgext.mailer
插入注册
在应用程序中config/app_cfg.py导入plug:
from tgext.pluggable import plug
然后在文件的结尾处调用带有注册的插件:
plug(base_config, 'registration')
如果使用tgext.mailer则需要插入:
plug(base_config, 'tgext.mailer')
您将可以在 http://localhost:8080/registration。
有些选项可以在^{tt5}上设置$ 应用程序的配置文件。 制作激活电子邮件至少需要一个选项 工作:
- registration.email_sender -> Outgoing mails sender address (like ^{tt6}$)
如果您正在使用tgext.mailer您需要设置一些配置,请在此处查看可用选项: https://github.com/amol--/tgext.mailer。
如果不使用turbomail或tgext.mailer更多配置 必须设置选项才能使激活电子邮件正常工作:
- registration.smtp_host -> SMTP server to use to send emails
- registration.smtp_login -> Login for authentication on SMTP server
- registration.smtp_passwd -> Password for authentication on SMTP server
插件选项
当插入tgapp-registration时,以下选项 可以传递到插头呼叫:
- registration.form -> Full python path of the form class to use for Registration form. By default registration.lib.forms.RegistrationForm is used.
可用挂钩
注册公开一些钩子来配置它的行为, 可与涡轮齿轮2寄存器挂钩一起使用的挂钩是:
- registration.before_registration_form(arguments) -> Runs before rendering the form. Can be used to insert preconditions to limit the registration for example just to invited users. You can fill the form inserting data into arguments, you might want to put a json serialized dictionary into arguments[‘extra’] that is an HiddenField in the form
- registration.before_registration(submitted_values) -> Runs after form submission. Can be used to change the values submitted by the form before they are used
- registration.after_registration(registration, submitted_values) -> Runs after form submission. Can be used to store eventual data that the form sent and that the Registration model doesn’t support.
- registration.on_complete(registration, email_data) -> Runs after registration completion before sending activation email, can be used to change outgoing email.
- registration.before_activation(registration, user) -> Runs at activation before creating the user and setting the registration as active
- registration.after_activation(registration, user) -> Runs after creating user, can be used to call redirect to redirect to a different page at registration completion.
公开模板
注册使用的模板,可以替换为 tgext.pluggable.replace_template是:
- registration.templates.register
- registration.templates.complete