Fixing expiration and js warning.
This commit is contained in:
parent
010bd1840d
commit
1b90285833
@ -59,8 +59,10 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
executeAndroidExclusiveCode(Android)
|
executeAndroidExclusiveCode(Android)
|
||||||
}
|
}
|
||||||
searchMobile = document.querySelector('nav.mobile-shortcuts div.search')
|
searchMobile = document.querySelector('nav.mobile-shortcuts div.search')
|
||||||
fakeSearchInput = searchMobile.querySelector('input')
|
if (searchMobile !== null) {
|
||||||
addListenersSearch()
|
fakeSearchInput = searchMobile.querySelector('input')
|
||||||
|
addListenersSearch()
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
function fillFarmaciaGuardia() {
|
function fillFarmaciaGuardia() {
|
||||||
|
@ -17,16 +17,17 @@ use Crypt::Bcrypt qw/bcrypt bcrypt_check/;
|
|||||||
|
|
||||||
my $tracking;
|
my $tracking;
|
||||||
|
|
||||||
my $iso8601 = DateTime::Format::ISO8601->new;
|
my $iso8601 = DateTime::Format::ISO8601->new;
|
||||||
|
|
||||||
sub request {
|
sub request {
|
||||||
shift;
|
shift;
|
||||||
eval {
|
eval {
|
||||||
my $c = shift;
|
my $c = shift;
|
||||||
my $app = $c->app;
|
my $app = $c->app;
|
||||||
if (!defined $tracking) {
|
if ( !defined $tracking ) {
|
||||||
$tracking = BurguillosInfo::Tracking->new($app);
|
$tracking = BurguillosInfo::Tracking->new($app);
|
||||||
}
|
}
|
||||||
$tracking->register_request($c);
|
$tracking->register_request($c);
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
say STDERR $@;
|
say STDERR $@;
|
||||||
@ -34,29 +35,34 @@ sub request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub stats {
|
sub stats {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if (!$self->valid_login) {
|
if ( !$self->valid_login ) {
|
||||||
$self->res->headers->location('/stats/login');
|
$self->res->headers->location('/stats/login');
|
||||||
$self->render(text => 'You must login', status => 302);
|
$self->render( text => 'You must login', status => 302 );
|
||||||
return;
|
|
||||||
}
|
|
||||||
my $data = $tracking->get_global_data($self);
|
|
||||||
my $data_per_url = $tracking->get_data_for_urls($self);
|
|
||||||
my $google_data = $tracking->get_google_data($self);
|
|
||||||
$self->_filter_data_per_url($data_per_url);
|
|
||||||
$self->_filter_data_per_url($google_data);
|
|
||||||
$self->render(tracking_data => $data, tracking_by_url => $data_per_url, google_data => $google_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
sub _filter_data_per_url($self, $data_per_url) {
|
|
||||||
my $filter = $self->param('filter');
|
|
||||||
if (!defined $filter) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my @new_data_per_url;
|
$self->session( expiration => 0 );
|
||||||
if ($filter eq 'remove-extensions') {
|
my $data = $tracking->get_global_data($self);
|
||||||
|
my $data_per_url = $tracking->get_data_for_urls($self);
|
||||||
|
my $google_data = $tracking->get_google_data($self);
|
||||||
|
$self->_filter_data_per_url($data_per_url);
|
||||||
|
$self->_filter_data_per_url($google_data);
|
||||||
|
$self->render(
|
||||||
|
tracking_data => $data,
|
||||||
|
tracking_by_url => $data_per_url,
|
||||||
|
google_data => $google_data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _filter_data_per_url ( $self, $data_per_url ) {
|
||||||
|
my $filter = $self->param('filter');
|
||||||
|
if ( !defined $filter ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
my @new_data_per_url;
|
||||||
|
if ( $filter eq 'remove-extensions' ) {
|
||||||
for my $url (@$data_per_url) {
|
for my $url (@$data_per_url) {
|
||||||
if ($url->{path} =~ /\.\w+$/) {
|
if ( $url->{path} =~ /\.\w+$/ ) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
push @new_data_per_url, $url;
|
push @new_data_per_url, $url;
|
||||||
@ -66,67 +72,65 @@ sub _filter_data_per_url($self, $data_per_url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub submit_login {
|
sub submit_login {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if ($self->valid_login) {
|
if ( $self->valid_login ) {
|
||||||
$self->res->headers->location('/stats');
|
$self->res->headers->location('/stats');
|
||||||
$self->render(text => 'Already logged in.', status => 302);
|
$self->render( text => 'Already logged in.', status => 302 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $password = $self->param('password');
|
my $password = $self->param('password');
|
||||||
if (!defined $password) {
|
if ( !defined $password ) {
|
||||||
$self->render(text => 'No password passed.', status => 400);
|
$self->render( text => 'No password passed.', status => 400 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $bcrypted_pass = $self->config->{bcrypt_pass_stats};
|
my $bcrypted_pass = $self->config->{bcrypt_pass_stats};
|
||||||
if (!defined $bcrypted_pass) {
|
if ( !defined $bcrypted_pass ) {
|
||||||
warn "No bcrypt pass.";
|
warn "No bcrypt pass.";
|
||||||
$self->render(text => 'Server error.', status => 500);
|
$self->render( text => 'Server error.', status => 500 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
say $password;
|
say $password;
|
||||||
say $bcrypted_pass;
|
say $bcrypted_pass;
|
||||||
if (!bcrypt_check( $password, $bcrypted_pass )) {
|
if ( !bcrypt_check( $password, $bcrypted_pass ) ) {
|
||||||
$self->render(text => 'Wrong password', status => 401);
|
$self->render( text => 'Wrong password', status => 401 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
say STDERR 'Login success.';
|
say STDERR 'Login success.';
|
||||||
my $expiration_date = DateTime->now->add( days => 1);
|
my $expiration_date = DateTime->now->add( days => 1 );
|
||||||
$self->session->{login} = "date_end_login:$expiration_date";
|
$self->session->{login} = "date_end_login:$expiration_date";
|
||||||
$self->res->headers->location('/stats');
|
$self->res->headers->location('/stats');
|
||||||
$self->render(text => 'Login success.', status => 302);
|
$self->render( text => 'Login success.', status => 302 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub valid_login {
|
sub valid_login {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $login_cookie = $self->session->{login};
|
my $login_cookie = $self->session->{login};
|
||||||
if (!defined $login_cookie) {
|
if ( !defined $login_cookie ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($date_text) = $login_cookie =~ /^date_end_login:(.*)$/;
|
my ($date_text) = $login_cookie =~ /^date_end_login:(.*)$/;
|
||||||
my $date;
|
my $date;
|
||||||
eval {
|
eval { $date = $iso8601->parse_datetime($date_text); };
|
||||||
$date = $iso8601->parse_datetime($date_text);
|
if ($@) {
|
||||||
};
|
warn "Bad date in cookie $login_cookie.";
|
||||||
if ($@) {
|
return;
|
||||||
warn "Bad date in cookie $login_cookie.";
|
}
|
||||||
return;
|
my $current_date = DateTime->now();
|
||||||
}
|
if ( $current_date > $date ) {
|
||||||
my $current_date = DateTime->now();
|
return;
|
||||||
if ($current_date > $date) {
|
}
|
||||||
return;
|
return 1;
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub login {
|
sub login {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if ($self->valid_login) {
|
if ( $self->valid_login ) {
|
||||||
$self->res->headers->location('/stats');
|
$self->res->headers->location('/stats');
|
||||||
$self->render(text => 'You are already logged in.', status => 302);
|
$self->render( text => 'You are already logged in.', status => 302 );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$self->render;
|
$self->render;
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user