两步验证的广义app
django-verification的Python项目详细描述
两步验证的广义app。
支持Python2.7、3.5、3.6、3.7、Django1.8和Django1.11。
安装
安装库,例如使用pip:
pip install django-verification
将库添加到退出项目的应用程序:
INSTALLED_APPS += ['verification']
将表添加到现有项目:
python manage.py migrate verification
升级
到0.4.1(需要django 1.7+):
python manage.py migrate --fake verification 0001_initial
演示
将整个django验证目录复制到某个位置,设置并输入 virtualenv,如果你在某些un*x:
make demo
这将自动生成一个密码为“demo”的用户“admin”。
演示现在应该运行在http://127.0.0.1/
再次运行make demo将从上一次运行中删除数据库。
测试
要运行测试,请首先安装测试要求:
pip install -r requirements/test.txt
然后使用以下命令运行测试:
make test APP=verification
用法
创建密钥组。密钥组保存密钥的配置,因此您可能需要 把它们固定下来。
fromverification.modelsimportKeyGroupkeygroup=KeyGroup(name='activate_account',# Uniquegenerator='sha1',# See verification.generators)
在某些事件上创建密钥,例如当用户单击按钮时:
fromverification.modelsimportKeyKey.generate(group=keygroup)
设置key.send_func到一些可调用的:
fromdjango.core.mailimportsend_mail# In this minimal example, the contents of the email is created earlierdefemail_key(recipient,content):subject="Activate account on FooBlog"recipient=''.join(recipient.strip().split())# Use any kind of messaging-system heresend_mail(subject,content,'noreply@example.com',[recipient])key.send_func=email_key
选择索赔视图,制作电子邮件内容,将其与 key.send_key():
fromdjango.core.urlresolversimportreverseactivate_url=reverse('verification-claim-post-url',kwargs={'key':key,'group':key.group})content="Click on %s to activate your account on FooBlog!"%activate_urlrecipient='john.oe@example.com'key.send_key(recipient,content)
挂起key_claimed-信号,以便在声明密钥后执行操作:
fromdjango.dispatchimportreceiverfromverification.signalsimportkey_claimed@receiver(key_claimed)defuser_created_key_claimed(sender,**kwargs):claimant=kwargs['claimant']claimant.is_active=Trueclaimant.save()
Version: | 1.0.0 |
---|