OSDN Git Service

Plugin::Stories: add storiees->latest helper
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Web.pm
index 9d13d11..a497974 100644 (file)
@@ -4,11 +4,16 @@ use Mojo::Util qw(dumper);
 use List::Util qw(any);
 
 use constant CONFIG_FILE => '/etc/newslash/newslash.conf';
+has subcommand => "";
 
 # This method will run once at server start
 sub startup {
     my $app = shift;
 
+    if ($ARGV[0]) {
+        $app->subcommand($ARGV[0]);
+    }
+
     # add commands in Newslash::Command
     push @{$app->commands->namespaces}, 'Newslash::Command';
 
@@ -18,7 +23,7 @@ sub startup {
         $app->plugin('Newslash::Plugin::YAMLConfig', file => CONFIG_FILE);
     }
     else {
-       if ($ARGV[0] && $ARGV[0] eq "configdump") {
+       if ($app->subcommand eq "configdump") {
            $app->plugin('Newslash::Plugin::YAMLConfig', default => {});
        }
        else {
@@ -97,10 +102,10 @@ sub startup {
 
     # check if 'maintenance' mode
     my $maintenance_mode = 0;
-    if (!$ARGV[0]
-       || any { $ARGV[0] eq $_ } qw[configdump configimport databaseinit
-                                    testdatainsert useradd usermod
-                                  ]) {
+    if ($app->subcommand
+        && any { $app->subcommand eq $_ } qw[configdump configimport databaseinit
+                                             testdatainsert useradd usermod
+                                           ]) {
        $maintenance_mode = 1;
     }
 
@@ -167,10 +172,10 @@ sub startup {
     # javascript loader
     $app->plugin('Newslash::Plugin::JavaScriptLoader');
     if ($maintenance_mode) {
-        $app->log->info("bypassing javasciprt loading...");
+        $app->log->info("bypassing javascriptloader...");
     }
     else {
-       $app->javascript_loader->load_all;
+       $app->javascript_loader->load_all_bundles;
     }
 
     # user authorization
@@ -206,6 +211,17 @@ sub startup {
     # AD renderer
     $app->plugin('Newslash::Plugin::ADRenderer');
 
+    # HTTP Compression
+    $app->plugin('Newslash::Plugin::HttpCompression');
+
+    # Users helper
+    $app->plugin('Newslash::Plugin::Users');
+
+    # Stories helper
+    $app->plugin('Newslash::Plugin::Stories');
+
+    # Sendmail helper
+    $app->plugin('Newslash::Plugin::Sendmail');
 
     ############################################################
     #
@@ -224,6 +240,9 @@ sub startup {
     $r->get('/submissions')->to('timeline#submissions');
     $r->get('/polls')->to('timeline#polls');
 
+    # RSS
+    $r->get('/rss/sradjp' => [format => ['rss', 'xml']])->to('rss#sradjp');
+
     # Banned page
     $r->get('/banned')->to('index#banned', noindex => 1);
 
@@ -232,10 +251,6 @@ sub startup {
     $r->post('/login')->to('login#login');
     $r->get('/logout')->to('login#logout');
 
-    # User Register
-    $r->get('/my/newuser')->to('login#newuser');
-    $r->post('/my/newuser')->to('login#newuser', captcha_check => 1);
-
     # story page
     $r->get('/story/:sid/' => [sid => qr|\d\d/\d\d/\d\d/\d+|])
       ->to('story#single');
@@ -284,6 +299,16 @@ sub startup {
     $r->get('/my/messages')->to('my#messages', seclev => 1);
     $r->get('/my/')->to('user#home', seclev => 1);
 
+    # User Register
+    $r->get('/my/newuser')->to('login#newuser');
+    $r->post('/my/newuser')->to('login#newuser', captcha_check => 1);
+    $r->get('/my/activation')->to('login#activation');
+    $r->get('/my/resetpassword')->to('login#reset_password');
+    $r->post('/my/resetpassword')->to('login#reset_password', captcha_check => 1);
+
+    # Change Email
+    $r->get('/my/change_email')->to('my#change_email', seclev => 1);
+
     # search page
     $r->get('/search')->to('search#search');
 
@@ -333,6 +358,10 @@ sub startup {
     my $api = $r->under('/api/v1');
     $api->post('/login')->to('API::Login#login');
 
+    $api->post('/newuser/validate')->to('API::User#validate_new_user');
+    $api->post('/newuser/create')->to('API::User#create_new_user');
+    $api->post('/newuser/password')->to('API::User#newuser_password');
+
     $api->get('/sidebar/item')->to('API::SidebarItem#get', seclev => 1);
 
     $api->get('/comment')->to('API::Comment#get');