Skip to content

Commit 7511fec

Browse files
committed
recent only shows identifiable users and limits content
1 parent 0af63dd commit 7511fec

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

app.psgi

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env perl
2+
3+
use lib './lib';
4+
use PeopleAPI::App::Web;
5+
use Plack::Builder;
6+
7+
builder {
8+
enable 'CrossOrigin', origins => 'http://skiffprofile.herokuapp.com', headers => ['*'];
9+
enable "JSONP", callback_key => 'callback';
10+
PeopleAPI::App::Web->new->to_psgi_app;
11+
};

lib/PeopleAPI/App/Web.pm

+12-17
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ sub dispatch_request {
2121
my @all = $machines->refresh->active->all;
2222
$self->json_response({json => {
2323
total => scalar @all,
24-
recent => [ map {$_->TO_JSON} @all ]
24+
recent => [
25+
map { {
26+
hash => $_->email,
27+
last_seen => $_->last_seen.""
28+
} } @all
29+
]
2530
}})
2631
},
27-
sub (PUT + /ident) {
32+
sub (PUT | POST + /ident) {
2833
my $data = decode_json $self->req->content;
2934
#get the local IP of the request
3035
#machine should've already broadcast for IP so we should have current
3136
#mac address
32-
if(my $client = $machines->search({ ip => $self->req->address }, {
37+
if(my $client = $machines->refresh->search({ ip => $self->req->address }, {
3338
order_by => {-desc => ['last_seen'] }
3439
})->first) {
3540
$client->update({email => $data->{'hash'}});
@@ -39,15 +44,15 @@ sub dispatch_request {
3944
},
4045
sub (GET + /status/* ) {
4146
my ($self, $hash ) = @_;
42-
if(my $client = $machines->search({ email => $hash})->first) {
47+
if(my $client = $machines->refresh->active->search({ email => $hash })->first) {
4348
$self->json_response({json => {
4449
status => JSON::XS::true,
45-
seen => $client->last_seen
46-
});
50+
seen => $client->last_seen->ymd('-')
51+
}});
4752
} else {
4853
$self->json_response({json => {
4954
status => JSON::XS::false,
50-
});
55+
}});
5156
}
5257
},
5358
sub (GET + /all) {
@@ -73,14 +78,4 @@ sub json_response {
7378
], [ encode_json $json ] ];
7479
}
7580

76-
around 'to_psgi_app', sub {
77-
my ($orig,$self) = (shift, shift);
78-
my $app = $self->$orig(@_);
79-
builder {
80-
enable 'CrossOrigin', origins => 'http://skiffprofile.herokuapp.com', headers => ['*'];
81-
#enable "JSONP", callback_key => 'callback';
82-
$app;
83-
};
84-
};
85-
8681
__PACKAGE__->run_if_script;

lib/PeopleAPI/Database/Schema/ResultSet/Machines.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sub active {
99
#sqlite doesn't stringify datetime correctly, DBIC fault
1010
my $dtf = $self->result_source->schema->storage->datetime_parser;
1111
$self->search_rs({
12+
'email' => { '!=', undef },
1213
'last_seen' =>
1314
{ '>=' => $dtf->format_datetime(
1415
DateTime->now->subtract_duration($considered_new)) }
@@ -30,7 +31,6 @@ sub active {
3031

3132
}
3233

33-
3434
sub today {
3535
my $self = shift;
3636
my $dtf = $self->result_source->schema->storage->datetime_parser;

0 commit comments

Comments
 (0)