revstrat / silverstripe-agegate
为验证访客是否有权查看受限制的内容添加年龄门
v1.2.10
2019-01-10 19:27 UTC
Requires
- geoip2/geoip2: ~2.0
- jaybizzle/crawler-detect: 1.*
- silverstripe/framework: >=4.0
README
本模块提供了一个年龄门功能,支持IPStack API或GeoLite2数据库。请在data
文件夹中提供自己的GeoLite2数据库。
重要通知
此插件不再维护。如果您希望接管维护,请与我联系,我将很高兴将维护权转交给您。
安装
composer require revstrat/silverstripe-agegate
用法
将<% include AgeGate %>
放在您的<body>
标签内部。
正常的模板继承允许自定义年龄门的外观。
通过在您的app的yml文件中设置以下内容来配置所需的GeoIP服务
RevStrat\AgeGate\PageControllerExtension:
geoip_source: "RevStrat\\AgeGate\\IPStack"
其中RevStrat\\AgeGate\\IPStack
是处理GeoIP查找的命名空间类。要创建自己的类,只需实现GeoIPServiceInterface
接口,并将geoip_source
更新为您的完整命名空间类。
IPStack接口使用了两个环境变量
- IPSTACK_ENDPOINT="http://api.ipstack.com/%s?access_key=%s"
- IPSTACK_ACCESS_KEY="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
IPSTACK_ENDPOINT键指向端点URL,并用sprintf解析。更新为兼容的服务(如Nekudo)或更改协议(IPStack的付费账户可以使用https进行查找)。IPSTACK_ACCESS_KEY应设置为您的访问密钥。
一切配置完成后,请确保运行/dev/build?flush=all
。
在设置 > 年龄门控制下配置按国家限制的年龄。
覆盖表单
在您的PageController上实现这些方法。这些方法是如何在年龄门上使用两个按钮的示例。
public function updateGetShowAgeGate(&$ageGateActive, &$sufficientAge) {
}
public function updateAgeGateForm(&$fields, &$actions, $minimumAge) {
$fields->removeByName('OfAge');
$actions = new FieldList(
FormAction::create('passAgeGate')->setTitle("Yes I'm over $minimumAge"),
FormAction::create('failAgeGate')->setTitle("I'm not $minimumAge yet")
);
}
public function passAgeGate($data, Form $form) {
$data['OfAge'] = true;
return $this->doAgeGate($data, $form);
}
public function failAgeGate($data, Form $form) {
$data["OfAge"] = false;
return $this->doAgeGate($data, $form);
}