两步验证的广义app

django-verification的Python项目详细描述


两步验证的广义app。

支持Python2.7、3.5、3.6、3.7、Django1.8和Django1.11。

安装

  1. 安装库,例如使用pip:

    pip install django-verification
    
  2. 将库添加到退出项目的应用程序:

    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

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java从8位二进制到十六进制的转换   Java流API映射参数   java Dropwizard从POST方法更新视图   java如何制作onetoone映射playframework   java中的Eclipse代码检查样式缩进模块?   java Maven无法正确安装   java将此关键字作为参数传递   java Mandelbrot设置了错误的形状   Java中的哈希表内存使用   安卓 java:如何在两个微调器之间切换按钮并获取微调器的文本?   java从其他位置(数据库、http…)加载JSF facelets文件(模板、视图)   java Spring休眠悲观锁定   通过rest和html作为客户端上传java文件