Skip to content

Commit ea53f40

Browse files
committed
Enhance customer access configuration and validation logic.
1 parent e1bdae6 commit ea53f40

3 files changed

Lines changed: 80 additions & 4 deletions

File tree

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ A browser-centric troubleshooting tool for OpenMage developers. Features:
3636

3737
## Quick Start
3838

39-
You need to be able to access the customers in the database. The first 20 customers with ID from 1 to 20 are allowed to view the output in the browser. You can edit the `entity_id` in the table `customer_entity` for these users.
39+
You need to be able to access the customers in the database. By default, the first 20 customers with ID from 1 to 20 are allowed to view the output in the browser. You can edit the `entity_id` in the table `customer_entity` for these users. To allow access for specified customer IDs, see [Configuration](#configuration).
4040

4141
### Debug Helper
4242

@@ -132,6 +132,46 @@ For public accessible URLs, tools like [SSL Labs](https://www.ssllabs.com/ssltes
132132

133133
Refer to [SslController.php](app/code/community/Kiatng/Shooter/controllers/SslController.php) for more details.
134134

135+
## Configuration
136+
137+
### Customizing Customer IDs for Access
138+
139+
By default, the module allows the first 20 customers (with IDs from 1 to 20) to access the output in the browser. To customize this behavior, you can define the allowed customer IDs in your module `config.xml` configuration file.
140+
141+
1. Open the file `etc/config.xml` in in your module.
142+
2. Add the following configuration under the `<global>` section:
143+
144+
```xml
145+
<config>
146+
<!-- Add the following nodes -->
147+
<shooter>
148+
<access>
149+
<up_to_ids>5</up_to_ids> <!-- For the first 5 customer IDs -->
150+
<other_ids>100,200</other_ids> <!-- Add additional IDs separated by commas -->
151+
</access>
152+
</shooter>
153+
<!-- end config -->
154+
</config>
155+
```
156+
157+
3. Save the file and clear the `config` cache to apply the changes.
158+
4. Because the access is saved in frontend session, re-login may be required.
159+
4. If your config doesn't work, add dependency in `/app/etc/modules/Your_Module.xml`:
160+
161+
```xml
162+
<config>
163+
<modules>
164+
<Your_Module>
165+
<active>true</active>
166+
<codePool>local</codePool>
167+
<depends> <!-- Add dependency here -->
168+
<Kiatng_Shooter />
169+
</depends>
170+
</Your_Module>
171+
</modules>
172+
</config>
173+
```
174+
135175
## Installation
136176

137177
### modman
@@ -176,5 +216,5 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
176216

177217
## License
178218

179-
@copyright 2024 Ng Kiat Siong
219+
@copyright 2024-2025 Ng Kiat Siong
180220
This module is licensed under the GNU GPL v3.0.

app/code/community/Kiatng/Shooter/Controller/Abstract.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract class Kiatng_Shooter_Controller_Abstract extends Mage_Core_Controller_F
1111
protected $_t2;
1212

1313
/**
14-
* Only allow access for customer_id < 20
14+
* Validate allowed customer_id.
1515
*
1616
* @inheritdoc
1717
*/
@@ -21,14 +21,44 @@ public function preDispatch()
2121
$session = Mage::getSingleton('customer/session');
2222
if (!$session->authenticate($this)) {
2323
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
24-
} elseif ($session->getCustomerId() > 20) {
24+
} elseif (!$this->_isAllowed()) {
2525
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
2626
$this->norouteAction();
2727
}
2828
$this->_t2 = microtime(true);
2929
return;
3030
}
3131

32+
/**
33+
* Check if the login user is allowed access.
34+
*
35+
* @return bool
36+
*/
37+
protected function _isAllowed(): bool
38+
{
39+
$session = Mage::getSingleton('customer/session');
40+
if (is_bool($session->getIsAllowShooter())) {
41+
return $session->getIsAllowShooter();
42+
}
43+
44+
$allow = false;
45+
$id = (int) $session->getCustomerId();
46+
if ($id <= (int) Mage::getConfig()->getNode('shooter/access/up_to_ids')) {
47+
$allow = true;
48+
}
49+
50+
$ids = (string) Mage::getConfig()->getNode('shooter/access/other_ids');
51+
if ($ids && !$allow) {
52+
$ids = explode(',', $ids);
53+
if (in_array($id, $ids)) {
54+
$allow = true;
55+
}
56+
}
57+
58+
$session->setIsAllowShooter($allow);
59+
return $allow;
60+
}
61+
3262
/**
3363
* Display the output of a variable.
3464
*

app/code/community/Kiatng/Shooter/etc/config.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
</modules>
3030
</translate>
3131
</global>
32+
<shooter>
33+
<access>
34+
<up_to_ids>20</up_to_ids>
35+
<other_ids>0</other_ids>
36+
</access>
37+
</shooter>
3238
<frontend>
3339
<routers>
3440
<shooter>

0 commit comments

Comments
 (0)