70 lines
2.2 KiB
Perl
70 lines
2.2 KiB
Perl
package MyRedland;
|
|
|
|
use MyRedland::Lusers;
|
|
use MyRedland::Controller::Metrics;
|
|
|
|
use Mojo::Base 'Mojolicious', -signatures;
|
|
|
|
# This method will run once at server start
|
|
sub startup ($self) {
|
|
my $metrics = MyRedland::Controller::Metrics->new;
|
|
$self->hook(
|
|
around_dispatch => sub {
|
|
my $next = shift;
|
|
my $c = shift;
|
|
$metrics->request($c);
|
|
if ( defined $next ) {
|
|
$next->();
|
|
}
|
|
}
|
|
);
|
|
my $config = $self->plugin('JSONConfig');
|
|
$self->config(
|
|
hypnotoad => { proxy => 1, listen => ['http://localhost:3000'] } );
|
|
$self->secrets($self->config->{secrets});
|
|
$self->sessions->default_expiration(0);
|
|
my $luser_dao = MyRedland::Lusers->new(app => $self);
|
|
$self->helper( current_user => sub {
|
|
my $c = shift;
|
|
my $user_uuid = $c->session->{user_uuid};
|
|
if (!defined $user_uuid) {
|
|
return;
|
|
}
|
|
my $user = $luser_dao->find_by_uuid(uuid => $user_uuid);
|
|
if (!defined $user) {
|
|
delete $c->session->{user_uuid};
|
|
return;
|
|
}
|
|
return $user;
|
|
});
|
|
|
|
# Router
|
|
my $r = $self->routes;
|
|
|
|
# Normal route to controller
|
|
$r->get('/')->to('Page#index');
|
|
|
|
# $r->get('/:post')->to('Page#post');
|
|
$r->get('/perfil')->to('User#profile');
|
|
$r->get('/usuario/:username/verificacion')->to('User#user_verification');
|
|
$r->get('/usuario/avatar')->to('User#get_avatar');
|
|
$r->get('/perfil/verifica-el-correo')->to('User#mail_verify');
|
|
$r->post('/usuario/actualizar-avatar')->to('User#setup_avatar');
|
|
$r->get('/perfil/configura-tu-avatar')->to('User#setup_avatar_get');
|
|
$r->get('/logout')->to('User#logout_get');
|
|
$r->post('/logout')->to('User#logout');
|
|
$r->get('/login')->to('User#login_get');
|
|
$r->post('/login')->to('User#login');
|
|
$r->get('/registrate')->to('User#sign_up_get');
|
|
$r->post('/registrate')->to('User#sign_up');
|
|
$r->get('/stats')->to('Metrics#stats');
|
|
$r->get('/<:category>.rss')->to('Page#category_rss');
|
|
$r->get('/:category')->to('Page#category');
|
|
$r->get('/posts/<:slug>-preview.png')->to('Page#get_post_preview');
|
|
$r->get('/posts/:slug')->to('Page#post');
|
|
$r->get('/stats/login')->to('Metrics#login');
|
|
$r->post('/stats/login')->to('Metrics#submit_login');
|
|
}
|
|
|
|
1;
|