Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSGI fixes #69

Open
wants to merge 27 commits into
base: psgi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c2bc593
Add session parameters
ichesnokov Sep 3, 2016
415324a
Proper logging
ichesnokov Sep 3, 2016
9df28f6
Ignore more stuff
ichesnokov Sep 3, 2016
ab966d8
Add position / phone to .po files
ichesnokov Sep 3, 2016
3ef2088
Update $self, do not get user from Request
ichesnokov Sep 3, 2016
35b7592
Better diagnostics
ichesnokov Sep 3, 2016
8b9cc82
Use Plack::Response; properly retrieve error
ichesnokov Sep 3, 2016
d642607
Use set_locale() on DateTime object as proposed by docs
ichesnokov Sep 3, 2016
237953b
Convert handlers to app
ichesnokov Sep 3, 2016
4015e47
Specify path to lib via lib::abs
ichesnokov Sep 3, 2016
3264348
mod_perl had this function: need a workaround
ichesnokov Sep 3, 2016
72a2661
Add dbhost attribute; without it act user cannot be authenticated for…
ichesnokov Sep 3, 2016
aa5fc67
Set pg_enable_utf8 to 0: Wiki::Toolkit encodes text itself
ichesnokov Sep 3, 2016
79b3c72
Make session expiry in 24 hours
ichesnokov Sep 3, 2016
27d8cf7
Sometimes it's still array
ichesnokov Sep 3, 2016
b40b093
Use HTTP_HOST instead of SERVER_NAME
ichesnokov Sep 3, 2016
acb64c6
Ignore 'git' directory as well
ichesnokov Sep 3, 2016
79aad60
s/connection->remote_ip/address/
ichesnokov Sep 4, 2016
767969e
Avoid 'uninitialized value' warning
ichesnokov Sep 4, 2016
7b768ca
Save language in session, dammit
ichesnokov Sep 4, 2016
d852257
Properly use session middleware
ichesnokov Sep 4, 2016
e59ddae
Ignore vim files
ichesnokov Aug 15, 2017
4a83d72
Add cpanfile
ichesnokov Aug 15, 2017
5a270da
Static handler also needs to know about authenticated user
ichesnokov Aug 15, 2017
33ca578
Escape \$ in regex
ichesnokov Sep 5, 2017
27807f7
Make sure there is no trailing slash in base_url
ichesnokov Jul 30, 2018
f39d748
Fix weird bug of Locale::Maketext
ichesnokov Jul 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/META.yml
/Makefile
/inc
*.bak
*.old
*.log
var
wwwdocs
actdocs
git
github-hook
conf
*.sw[p-z]
1 change: 1 addition & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ requires(
'JSON::XS' => 0,
'LWP::Simple' => 0,
'LWP::UserAgent' => 0,
'lib::abs' => '0.93',
'List::Pairwise' => 0,
'Locale::Maketext::Lexicon' => 0,
'Net::OpenID::Server' => 0,
Expand Down
8 changes: 5 additions & 3 deletions app.psgi
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/usr/bin/env perl

use strict;
use warnings;
use lib 'lib';
use lib::abs 'lib';

use Act::Dispatcher;
use Plack::Builder;

builder {
enable 'Session::Cookie';
enable 'Session',
session_key => 'act_session',
expires => 3600 * 24 * 30, # 30 days
secret => 'abcddcba';
enable "SimpleLogger", level => "warn";
Act::Dispatcher->to_app;
};
56 changes: 56 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
requires 'AppConfig' => 0;
requires 'Clone' => 0;
requires 'Crypt::Eksblowfish::Bcrypt' => 0;
requires 'DBI' => 0;
requires 'DBD::Pg' => 1.22;
requires 'Data::ICal' => '0.16'; # Data::ICal::Entry::Event
requires 'Data::ICal::DateTime' => 0;
requires 'Data::ICal::TimeZone' => 0;
requires 'DateTime::Format::Pg' => 0;
requires 'DateTime::Locale' => 0;
requires 'DateTime::TimeZone' => 0;
requires 'DateTime' => 0;
requires 'Digest::HMAC_SHA1' => 0;
requires 'Email::Address' => 0;
requires 'Email::Date' => 0;
requires 'Email::MessageID' => 1.4;
requires 'Email::Send' => 0;
requires 'Email::Send::Sendmail' => 0;
requires 'Email::Simple::Creator' => 0;
requires 'Email::Simple' => 0;
requires 'Email::Valid' => 0;
requires 'Flickr::API' => 0;
requires 'HTML::Entities' => 0;
requires 'HTML::TagCloud' => 0;
requires 'HTTP::Request::Common' => 0;
requires 'Imager' => 0;
requires 'JSON::XS' => 0;
requires 'LWP::Simple' => 0;
requires 'LWP::UserAgent' => 0;
requires 'lib::abs' => '0.93';
requires 'List::Pairwise' => 0;
requires 'Locale::Maketext::Lexicon' => 0;
requires 'Net::OpenID::Server' => 0;
requires 'Pod::POM' => 0;
requires 'Plack' => 0;
requires 'Plack::App::Cascade' => 0;
requires 'Plack::Builder' => 0;
requires 'Plack::Middleware::Session::Cookie' => 0;
requires 'Plack::Request' => 0;
requires 'Plack::Util::Accessor' => 0;
requires 'Plack::Test' => 0;
requires 'Template' => 2.16; # Template::Constants
requires 'Template::Multilingual::Parser' => 0;
requires 'Term::ReadKey' => 0;
requires 'Test::Deep::NoTest' => 0;
requires 'Test::MockObject' => 0;
requires 'Text::Diff' => 0;
requires 'Text::WikiFormat' => 0;
requires 'Text::xSV' => 0;
requires 'Try::Tiny' => 0;
requires 'URI::Escape' => 0;
requires 'URI' => 1.31;
requires 'Wiki::Toolkit' => 0; # Wiki::Toolkit::Formatter::Default Wiki::Toolkit::Store::Pg
requires 'XML::Atom' => '0.20'; # XML::Atom::Entry XML::Atom::Feed XML::Atom::Link
requires 'parent' => 0;
requires 'version' => 0;
13 changes: 10 additions & 3 deletions lib/Act/Dispatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ sub to_app {
sub {
my $env = shift;
my $req = Plack::Request->new($env);
$env->{'act.base_url'} = $req->base->as_string;

# Make sure there is no trailing slash in base_url
my $base_url = $req->base->as_string;
$base_url =~ s{/$}{};
$env->{'act.base_url'} = $base_url;
$env->{'act.dbh'} = Act::Util::db_connect();
$app->($env);
};
Expand All @@ -101,7 +105,10 @@ sub to_app {
}

sub conference_app {
my $static_app = Act::Handler::Static->new;
my $static_app = builder {
enable '+Act::Middleware::Auth';
Act::Handler::Static->new->to_app;
};
builder {
enable '+Act::Middleware::Language';
enable sub {
Expand Down Expand Up @@ -158,7 +165,7 @@ sub _handler_app {
my $subhandler = $1;
}
_load($handler);
return $handler->new(subhandler => $subhandler);
return $handler->new(subhandler => $subhandler)->to_app;
}

sub _load {
Expand Down
2 changes: 1 addition & 1 deletion lib/Act/Handler/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ sub handler
error => $env->{'act.login.error'},
destination => $uri,
action => join('/', '', $Request{conference}, 'LOGIN'),
domain => join('.', (split /\./, $r->env->{SERVER_NAME})[-2, -1]),
domain => join('.', (split /\./, $r->env->{HTTP_HOST})[-2, -1]),
);
$template->process('login');
$Request{status} = 200;
Expand Down
2 changes: 1 addition & 1 deletion lib/Act/Handler/User/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sub handler
"INSERT INTO participations (user_id, conf_id, datetime, ip) VALUES (?,?, NOW(), ?);"
);
$sth->execute( $Request{user}->user_id, $Request{conference},
$Request{r}->connection->remote_ip );
$Request{r}->address );
$sth->finish();
$Request{dbh}->commit;
return Act::Util::redirect(make_uri('main'))
Expand Down
9 changes: 5 additions & 4 deletions lib/Act/Middleware/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use warnings;

use parent qw(Plack::Middleware);
use Plack::Request;
use Plack::Response;
use Act::Config ();
use Try::Tiny;
use Plack::Util::Accessor qw(private);
Expand Down Expand Up @@ -97,7 +98,7 @@ sub check_login {
$user->check_password($sent_pw);
}
catch {
die ['Bad password'];
die ["Bad password. (Error: $_)"];
};

# user is authenticated - create a session
Expand All @@ -110,14 +111,14 @@ sub check_login {
catch {
my $env = $req->env;

my $error = $_->[0];
my $error = ref $_ eq 'ARRAY' ? $_->[0] : $_;
my $full_error = join ' ', map { "[$_]" }
$env->{SERVER_NAME},
$env->{HTTP_HOST},
$req->address,
$login,
$error;

$req->logger->({ level => 'error', $full_error });
$req->logger->({ level => 'error', message => $full_error });

$env->{'act.login.destination'} = $dest;
$env->{'act.login.error'} = 1;
Expand Down
3 changes: 2 additions & 1 deletion lib/Act/Middleware/Language.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ sub call {
$language = $s->{language} = $force_language;
my $uri = $req->uri;
my @query = $uri->query_form;
for (my $i; $i < @query; $i+=2 ) {
for (my $i = 0; $i < @query; $i += 2 ) {
if ($query[$i] eq 'language') {
splice @query, $i, 2;
}
}
$uri->query_form(\@query);
my $resp = Plack::Response->new;
$resp->redirect($uri->as_string);
$env->{'psgix.session'}->{'act'}->{language} = $language;
return $resp->finalize;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Act/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ sub upload {
# XXX returned value must support fh method (return psgi.input? but that only supports readline...)
}

sub header_in {
shift->header(@_);
}

1;

__END__
Expand Down
7 changes: 4 additions & 3 deletions lib/Act/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,9 @@ sub possible_duplicates {
for my $attr (qw( login email nick_name full_name last_name )) {
push @twins, grep { !$seen{ $_->user_id }++ }
map {@$_}
Act::User->get_items( $attr => map { s/([.*(){}^$?])/\\$1/g; $_ }
$self->$attr() )
Act::User->get_items(
$attr => map { s/([.*(){}^\$?])/\\$1/g; $_ } $self->$attr()
)
if $self->$attr();
}
$_->most_recent_participation() for @twins;
Expand Down Expand Up @@ -381,7 +382,7 @@ sub set_password {
my $self = shift;
my $password = shift;
my $crypted = $self->_crypt_password($password);
$Request{user}->update( passwd => $crypted );
$self->update( passwd => $crypted );
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Act/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ sub date_format
my $dt = ref $s ? $s : DateTime::Format::Pg->parse_timestamp($s);
my $lang = $Request{language} || $Config->general_default_language;
my $variant = $Config->language_variants->{$lang} || $lang;
$dt->set(locale => $variant);
$dt->set_locale($variant);

if ($variant =~ /^((\w+)_.*)$/) { # $1 = en_US, $2 = en
$variant = $2 unless exists $Act::Config::Languages{$variant};
Expand Down
8 changes: 5 additions & 3 deletions lib/Act/Wiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ use Act::Wiki::Store;
sub new
{
return Wiki::Toolkit->new(
store => Act::Wiki::Store->new(charset => 'UTF-8',
map { $_ => $Config->get("wiki_$_") }
qw(dbname dbuser dbpass)),
store => Act::Wiki::Store->new(
charset => 'UTF-8',
map { $_ => $Config->get("wiki_$_") }
qw(dbhost dbname dbuser dbpass)
),
formatter => Act::Wiki::Formatter->new(),
);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/Act/Wiki/Store.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ sub check_and_write_node
$self->write_node_post_locking( %args );
return 1;
}

sub _get_dbh_connect_attr {
my ($self) = @_;

return {
%{ $self->SUPER::_get_dbh_connect_attr() },
pg_enable_utf8 => 0,
};
}

1;
6 changes: 6 additions & 0 deletions po/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ msgstr "Perl mongers group"
msgid "Company"
msgstr "Company"

msgid "Position"
msgstr "Position"

msgid "Email"
msgstr "Email"

msgid "Phone"
msgstr "Phone"

msgid "Web page"
msgstr "Web page"

Expand Down
6 changes: 6 additions & 0 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ msgstr "PM-группа"
msgid "Company"
msgstr "Компания"

msgid "Position"
msgstr "Должность"

msgid "Email"
msgstr "Электронная почта"

msgid "Phone"
msgstr "Телефон"

msgid "Web page"
msgstr "Сайт"

Expand Down
2 changes: 1 addition & 1 deletion templates/talk/notify_body
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@
[% talk.abstract %]


{{Comments:}}
{{Comments}}:
[% talk.comment %]