/
MapController.php
54 lines (47 loc) · 1.61 KB
/
MapController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use TheRestartProject\RepairDirectory\Domain\Enums\Category;
class MapController extends Controller
{
public function index(Request $request)
{
if ($this->isIpRestricted()) {
return response('', 403);
}
return view('map', [
'selectedLocation' => $request->input('location', 'London, UK'),
'categories' => Category::values(),
'selectedCategory' => $request->input('category', ''),
'radiusOptions' => config('map.radiuses'),
'selectedRadius' => $this->selectedRadius($request)
]);
}
private function isIpRestricted()
{
$allowedIps = getenv('ALLOWED_IPS');
$currentIp = getenv('REMOTE_ADDR');
if ($allowedIps && $currentIp) {
$allowedIps = explode(',', $allowedIps);
return !in_array($currentIp, $allowedIps);
}
return false;
}
/**
* Get the selected radius either from the request of use the default
*
* The selected radius is the radius that should be selected when the page is
* loaded. If the page is loaded without a query string then it should use the
* default value specified in the config, otherwise it will use the value
* in the query string for radius.
*
* @param Request $request The request object
*
* @return int
*/
protected function selectedRadius(Request $request)
{
$selectedRadius = $request->input('radius') ?: config('map.default_radius');
return (int) $selectedRadius;
}
}