简体   繁体   English

如何根据HybridAuth中的某些条件禁用FB登录

[英]How to disable fb login based on some condition in hybridauth

How can we disable FB login based on some condition. 我们如何根据某些条件禁用FB登录。 For example if the time is between 2am and 4am disable the facebook login ( just an example) . 例如,如果时间在凌晨2点到凌晨4点之间,则禁用facebook登录(仅作为示例)。 My problem is not with the logic of the condition, I can certainly apply that. 我的问题不是条件的逻辑,我当然可以适用。 but my problem is once the condition is met then how to disable the fb login programmatically in hybridauth 但是我的问题是一旦满足条件,那么如何在hybridauth中以编程方式禁用fb登录

Thank you in advance 先感谢您

Ps. 附言 you may wanna look into the code here: https://github.com/hybridauth/hybridauth 您可能想在这里查看代码: https : //github.com/hybridauth/hybridauth

http://hybridauth.sourceforge.net/ http://hybridauth.sourceforge.net/

In your super simplified example you could just add logic to build a configuration array on the fly as appropriate and then inject that into your hybridauth instance. 在您的超级简化示例中,您可以添加逻辑以根据需要即时构建配置数组,然后将其注入到hybridauth实例中。 This could be achieved by loading in the standard config array and then manipulating according to whatever business logic rules you have. 这可以通过加载标准配置数组,然后根据您拥有的任何业务逻辑规则进行操作来实现。

You could always extend Hybridauth but that seems overkill for the relatively simple example that you have provided. 您始终可以扩展Hybridauth,但是对于您提供的相对简单的示例来说,这似乎有些过头了。

From the documentation we can see this entry; 文档中,我们可以看到该条目。

enabled can be true or false ; enabled可以为truefalse if you don't want to use a specific provider then set it to false 如果您不想使用特定的提供程序,则将其设置为false

If you open hybridauth/config.php , you'll see a configuration array, which holds configurations for different authentication methods. 如果打开hybridauth/config.php ,则会看到一个配置数组,其中包含用于不同身份验证方法的配置。 Most interestingly, we can see an key named enabled , which we can manipulate. 最有趣的是,我们可以看到一个名为enabled的键,可以对其进行操作。

Modifying the value directly. 直接修改值。

We can modify the value directly, by using the ternary operator . 我们可以使用三元运算符直接修改值。 For example; 例如;

...

"Facebook" => array ( 
                "enabled" => (condition ? true : false), //Ternary operator modifying `enabled` value.
                "keys"    => array ( "id" => "", "secret" => "" ),
                "trustForwarded" => false
            ),
....

However, we can do this by modifying it after the configuration has been loaded. 但是,我们可以通过在加载配置后对其进行修改来做到这一点。

Modifying the value later on. 稍后修改值。

If you open up examples/social_hub/login.php , you'll see we load the config file and use it. 如果打开examples/social_hub/login.php ,您将看到我们加载了配置文件并使用了它。 Here is where we can modify that enabled key. 在这里我们可以修改已enabled密钥。

The configuration is held within the variable $config , so; 配置保存在变量$config

if( condition ) {
  $config['providers']['Facebook']['enabled'] = FALSE;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM