-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.php
147 lines (115 loc) · 3.27 KB
/
routes.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
use PassKitServer\Libraries\PassSigner;
use PassKitServer\Models\Device;
use PassKitServer\Models\Pass;
use PassKitServer\Models\Registration;
Route::get('(:bundle)', function()
{
$c_url = Config::get('passkitserver::config.certificate_url');
$c_pass = 'passkitcertificate';
$p_url = Config::get('passkitserver::config.pass_url');
$o_url = Config::get('passkitserver::config.output_url');
$pass_signer = new PassSigner($p_url, $c_url, $c_pass, $o_url);
$pass_signer->sign(true);
});
Route::get('(:bundle)/devices/(:any)/registrations/(:any)', array(
'name' => 'get_updated_passes',
function($device_id, $pass_type)
{
$last_update = Input::get('passesUpdatedSince', false);
$registrations = Registration::with(array('pass' => function($query) use ($last_update)
{
if($last_update !== false)
{
$query->where('updated_at','>',$last_update);
}
}))
->where('pass_type', '=', $pass_type)
->where('device_id', '=', $device_id)
->get();
// prepare the response
$response = array();
$serials = array();
$new_last_updated = 0;
if(!empty($registrations))
{
foreach($registrations as $registration)
{
$pass = $registration->pass;
if($pass != null)
{
$serials[] = $pass->serial_number;
// get the latest date from all the updated passes, use it as the new last_update tag
if(strtotime($pass->updated_at) > $new_last_updated)
{
$new_last_updated = strtotime($pass->updated_at);
}
}
}
}
$response['serialNumbers'] = $serials;
$response['lastUpdated'] = $new_last_updated;
Log::info(json_encode($response));
return Response::json($response);
}
));
Event::listen('laravel.query', function($sql, $bindings, $time)
{
//echo $sql;
//print_r($bindings);
});
Route::post('(:bundle)/devices/(:any)/registrations/(:any)/(:any)', array(
'name' => 'post_device',
'before' => 'check_auth_token',
function($device_id, $pass_type, $serial_number)
{
Log::info('device_id: '.$device_id);
Log::info('pass_type: '.$pass_type);
Log::info('serial_number: '.$serial_number);
$json_payload = Input::json();
Log::info(json_encode($json_payload));
}
));
Route::delete('(:bundle)/devices/(:any)/registrations/(:any)/(:any)', array(
'name' => 'delete_device',
'before' => 'check_auth_token',
function($device_id, $pass_type, $serial_number)
{
Log::info('device_id: '.$device_id);
Log::info('pass_type: '.$pass_type);
Log::info('serial_number: '.$serial_number);
}
));
Route::get('(:bundle)/passes/(:any)/(:any)', array(
'name' => 'get_pass',
'before' => 'check_auth_token',
function($pass_type, $serial_number)
{
// check the auth token, how?
// get the pass data, check for modifications
// if modified send the pass otherwise 304
// do the procedure to render, sign and compress the pass.
}
));
Route::get('(:bundle)/log', array(
'name' => 'get_log',
function()
{
$it = new \RecursiveDirectoryIterator(path('storage').'logs');
foreach(new \RecursiveIteratorIterator($it) as $file)
{
echo File::get($file->getPathname());
}
}
));
Route::post('(:bundle)/log', array(
'name' => 'post_log',
'before' => 'check_auth_token',
function()
{
Log::info(json_encode(Input::all()));
}
));
Route::filter('check_auth_token', function(){
});
?>