TurboGears2的可插拔应用程序,允许更改用户密码或在丢失时重置密码,具有SQLA和Ming兼容性
tgapp-resetpassword的Python项目详细描述
关于重置密码
ResetPassword是TurboGears2的可插入应用程序 允许更改用户密码或在丢失时重置密码。
安装
resetpassword既可以从pypi安装,也可以从bitbucket安装:
pip install tgapp-resetpassword
应该只对大多数用户有效
插入重置密码
在应用程序中config/app_cfg.py导入plug:
from tgext.pluggable import plug
然后在文件的结尾处使用resetpassword调用plug:
plug(base_config, 'resetpassword')
您可以在 http://localhost:8080/resetpassword。
如果使用tgext.mailer则需要插入:
plug(base_config, 'tgext.mailer')
有些选项可以在^{tt1}上设置$ 应用程序的配置文件。 制作激活电子邮件至少需要一个选项 工作:
- resetpassword.email_sender -> Outgoing mails sender
如果您正在使用tgext.mailer您需要设置一些配置,请在此处查看可用选项: https://github.com/amol--/tgext.mailer。
如果不使用turbomail或tgext.mailer更多配置 必须设置选项才能使激活电子邮件正常工作:
- resetpassword.smtp_host -> SMTP server to use to send emails
- resetpassword.smtp_port -> SMTP server port
- resetpassword.smtp_login -> Login for authentication on SMTP server
- resetpassword.smtp_passwd -> Password for authentication on SMTP server
插件选项
插入tgapp-resetpassword时,以下选项 可以传递到插头呼叫:
- reset_password_form -> Full python path of the form class to use for Reset Password form. By default resetpassword.lib.forms.ResetPasswordForm is used.
- new_password_form -> Full python path of the form class to use for New Password form. By default registration.lib.forms.NewPasswordForm is used.
因此,插头呼叫可能如下所示:
plug( base_config, 'resetpassword', reset_password_form='myproject.lib.resetpassword_forms.ResetPasswordForm', new_password_form='myproject.lib.resetpassword_forms.NewPasswordForm', )
可用挂钩
resetpassword提供了一些钩子 在某些操作期间调用以更改默认值 应用程序的行为:
- resetpassword.on_request(user, email_data, reset_link)
- resetpassword.before_render_change_password_template(user, deserialized_data)
- resetpassword.before_redirect(redirect_url)
公开模板
resetpassword使用的模板,可替换为 tgext.pluggable.replace_template是:
- resetpassword.templates.index -> Page with password reset request form
- resetpassword.templates.change_password -> Page with change password request
示例用法(在plug调用之后):
from tgext.pluggable import replace_template replace_template(base_config, 'resetpassword.templates.index', 'myproject.templates.reset_password') replace_template(base_config, 'resetpassword.templates.change_password', 'myproject.templates.change_password')