While using this module, I got an idea, that add rules support for this module.

We should only add rules condition,but this will give extra flexible for this module.

For example:
event => system init
condition => IP is XX(country)
action => redirect to specific page or set a welcome message etc

This will make thing more interesting.

meanwhile, I would like to request as co-maintainer to work on this feature. and I am sure this feature will make this module more welcome:)

Thank you for your attention.

Comments

zterry95’s picture

StatusFileSize
new1.4 KB

Here is the patch and it has actually used in one of our production site and works well.

Below is a rules example for explain the usage.

{ "rules_user_restrict" : {
    "LABEL" : "user restrict",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "davidkippot", "rules" ],
    "ON" : [ "init" ],
    "IF" : [
      { "ip2countryis" : { "iscountry" : { "value" : { "CN" : "CN" } } } },
      { "NOT text_matches" : { "text" : [ "site:current-page:path" ], "match" : "user" } },
      { "data_is" : { "data" : [ "site:current-user:uid" ], "value" : "0" } }
    ],
    "DO" : [ { "redirect" : { "url" : "user" } } ]
  }
}

Attachment is the patch.

jantoine’s picture

Status: Active » Needs review
StatusFileSize
new3.91 KB

I have attempted to make the following improvements to the patch in #1:

  • Abstract debug mode into it's own function so that it can be used by more than just the login process.
  • Align code to more closely match code that is already used in the ip2country module.
  • Align labels, descriptions and help text to closer match existing rules from the rules module.
  • Added debug functionality to the rule.

Status: Needs review » Needs work

The last submitted patch, ip2country-rules-support-2023471-2.patch.patch, failed testing.

tr’s picture

Status: Needs work » Needs review
StatusFileSize
new2.74 KB

I rewrote #2 to be more like I think it should be, and I also added a Rules action to Set the country.

I would appreciate it if someone could give this patch a test. I welcome any suggestions for additional rules integration, and it would be great if someone could post some useful examples for the documentation.

yurg’s picture

Hi,

Thank you for patch: it works great for me so far. There is one issue remains, may be if it's Rules-specific though: redirect works everywhere but front page.

tr’s picture

Status: Needs review » Fixed

Committed. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.