diff --git a/Web/lib/MJB/Web.pm b/Web/lib/MJB/Web.pm index 6690d6b..8ad8204 100644 --- a/Web/lib/MJB/Web.pm +++ b/Web/lib/MJB/Web.pm @@ -10,6 +10,9 @@ sub startup ($self) { : '/etc/mjb.yml' }); + # Some quick configs.... + $self->config->{register}->{require_invite} = 1; + # Configure the application $self->secrets($config->{secrets}); @@ -202,13 +205,6 @@ sub startup ($self) { $auth->get ( '/blog/initialize' )->to('Blog#do_initialize' )->name('do_blog_initialize' ); $auth->get ( '/blog/:id/settings' )->to('Blog#settings' )->name('show_blog_settings' ); $auth->post( '/blog/:id/settings' )->to('Blog#do_settings' )->name('do_blog_settings' ); - # - # - # - #$auth->get ( '/blog' )->to('Blog#create' )->name('show_blog_create' ); - #$auth->post( '/blog' )->to('Blog#do_create' )->name('do_blog_create' ); - #$auth->get ( '/blog/:id/settings' )->to('Blog#settings' )->name('show_blog_settings' ); - #$auth->post( '/blog/:id/settings' )->to('Blog#do_settings' )->name('do_blog_settings' ); # Admin Dashboard $admin->get ( '/admin' )->to('Admin#index' )->name('show_admin' ); @@ -223,6 +219,9 @@ sub startup ($self) { $admin->post( '/admin/server' )->to('Admin#do_server' )->name('do_admin_server' ); $admin->post( '/admin/server/remove' )->to('Admin#do_server_remove' )->name('do_admin_server_remove' ); $admin->get ( '/admin/settings' )->to('Admin#settings' )->name('show_admin_settings' ); + $admin->get ( '/admin/invites' )->to('Admin#invites' )->name('show_admin_invites' ); + $admin->post( '/admin/invite' )->to('Admin#do_invite' )->name('do_admin_invite' ); + $admin->post( '/admin/invite/remove' )->to('Admin#do_invite_remove' )->name('do_admin_invite_remove' ); } diff --git a/Web/lib/MJB/Web/Controller/Admin.pm b/Web/lib/MJB/Web/Controller/Admin.pm index 336787c..0b1ca77 100644 --- a/Web/lib/MJB/Web/Controller/Admin.pm +++ b/Web/lib/MJB/Web/Controller/Admin.pm @@ -56,6 +56,46 @@ sub servers ( $c ) { } +sub invites ( $c ) { + my $invites = $c->stash->{invites} = [ $c->db->invites->all ]; + +} + +sub do_invite ( $c ) { + my $code = $c->param('code'); + my $is_multi_use = $c->param('is_multi_use' ); + + try { + $c->db->storage->schema->txn_do( sub { + $c->db->invites->create({ + code => $code, + ( $is_multi_use ? ( is_one_time_use => 0 ) : ( is_one_time_use => 1 ) ), + }); + }); + } catch { + $c->flash( error_message => "Invite Code could not be created: $_" ); + }; + + $c->redirect_to( $c->url_for( 'show_admin_invites' ) ); + return; +} + +sub do_invite_remove ( $c ) { + my $invite = $c->db->invite($c->param('iid')); + + if ( ! $invite ) { + $c->flash( error_message => "Invite could not be removed, because it doesn't exist?" ); + $c->redirect_to( $c->url_for( 'show_admin_invites' ) ); + return; + } + + my $code = $invite->code; + $invite->delete; + + $c->flash( confirmation => "Removed $code from invite pool." ); + $c->redirect_to( $c->url_for( 'show_admin_invites' ) ); +} + sub do_server ( $c ) { my $fqdn = $c->param('server_fqdn'); diff --git a/Web/lib/MJB/Web/Controller/Auth.pm b/Web/lib/MJB/Web/Controller/Auth.pm index e31b730..38ecd02 100644 --- a/Web/lib/MJB/Web/Controller/Auth.pm +++ b/Web/lib/MJB/Web/Controller/Auth.pm @@ -17,11 +17,16 @@ sub do_register ( $c ) { my $email = $c->stash->{form_email} = $c->param('email'); my $password = $c->stash->{form_password} = $c->param('password'); my $p_confirm = $c->stash->{form_password_confirm} = $c->param('password_confirm'); + my $invite = $c->stash->{form_invite_code} = $c->param('invite_code'); push @{$c->stash->{errors}}, "Name is required" unless $name; push @{$c->stash->{errors}}, "Email is required" unless $email; push @{$c->stash->{errors}}, "Password is required" unless $password; push @{$c->stash->{errors}}, "Confirm Password is required" unless $p_confirm; + + if ( $c->config->{register}->{require_invite} ) { + push @{$c->stash->{errors}}, "Invite code is required" unless $invite; + } return if $c->stash->{errors}; @@ -34,6 +39,11 @@ sub do_register ( $c ) { push @{$c->stash->{errors}}, "That email address is already registered." if $c->db->people( { email => $email } )->count; + if ( $c->config->{register}->{require_invite} ) { + push @{$c->stash->{errors}}, "That invite code is not valid." + unless $c->db->invites( { code => $invite, is_active => 1 } )->count >= 1; + } + return if $c->stash->{errors}; my $person = try { diff --git a/Web/templates/admin/_nav.html.ep b/Web/templates/admin/_nav.html.ep index 30931ed..94f7b98 100644 --- a/Web/templates/admin/_nav.html.ep +++ b/Web/templates/admin/_nav.html.ep @@ -23,6 +23,10 @@ + +
diff --git a/Web/templates/admin/invites.html.ep b/Web/templates/admin/invites.html.ep new file mode 100644 index 0000000..5383ddc --- /dev/null +++ b/Web/templates/admin/invites.html.ep @@ -0,0 +1,57 @@ +% layout 'standard', title => 'Admin Panel', sb_active => 'admin'; + +%= include 'admin/_nav', page => 'invites' + +%= include '_base/status_window'; + +
+
+ +
+ +
+ +
+ +
+
+ + +
+
+ +
+ +
+
+ + + + + + + + + + + + + + % for my $invite ( @{$invites} ) { + + + + + + + + + % } + +
IDCodeOne time use?Is active?CreatedRemove
<%= $invite->id %><%= $invite->code %><%= $invite->is_one_time_use %><%= $invite->is_active %><%= $invite->created_at->strftime( "%F" ) %> +
+ + +
+
+ diff --git a/Web/templates/auth/register.html.ep b/Web/templates/auth/register.html.ep index a26a897..c5ce86e 100644 --- a/Web/templates/auth/register.html.ep +++ b/Web/templates/auth/register.html.ep @@ -29,6 +29,14 @@ help => '', value => $c->stash->{form_password_confirm} %> + + % if ( $c->config->{register}->{require_invite} ) { + <%= include '_base/form/input', type => 'text', name => 'invite_code', + title => 'Invitation Code', + help => '', + value => $c->stash->{form_invite_code} + %> + % }