参考:
https://manual-cn.seafile.com/deploy_pro/two_factor_authentication.html
使用Twilio服务支持短信方式。
首先你需要安装 Twilio python库:
pip install twilio
然后添加以下配置项到 seahub_settings.py
:
#Twilio 集成,短信两步验证
TWO_FACTOR_SMS_GATEWAY = 'seahub.two_factor.gateways.twilio.gateway.Twilio'
TWILIO_ACCOUNT_SID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx'
TWILIO_AUTH_TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxx'
TWILIO_CALLER_ID = '+1xxxxxxxx'
EXTRA_MIDDLEWARE_CLASSES = (
'seahub.two_factor.gateways.twilio.middleware.ThreadLocals',
)
注意:如果你已经定义了 EXTRA_MIDDLEWARE_CLASSES
,请使用 EXTRA_MIDDLEWARE_CLASSES += (
替换掉 EXTRA_MIDDLEWARE_CLASSES = (
然后重启,当用户为其帐户启用两步认证时,将会显示“短信”方法。
修改/seahub/seahub/two_factor/gateways/twilio/geteway.py 文件
from twilio.rest import TwilioRestClient
改为:
from twilio.rest import Client
self.client = TwilioRestClient(getattr(settings, 'TWILIO_ACCOUNT_SID'),
改为:
self.client = Client(getattr(settings, 'TWILIO_ACCOUNT_SID'),
self.client.sms.messages.create(
改为:
self.client.messages.create(