Refactored and documented.

master
Manager Bot 3 years ago
parent 2697610c4c
commit f08a530c9f
  1. 6
      Web/lib/MJB/Web/Controller/Admin.pm
  2. 11
      Web/lib/MJB/Web/Controller/Auth.pm
  3. 97
      Web/lib/MJB/Web/Controller/Blog.pm
  4. 6
      Web/lib/MJB/Web/Controller/Dashboard.pm
  5. 6
      Web/lib/MJB/Web/Controller/Root.pm
  6. 6
      Web/lib/MJB/Web/Controller/UserSettings.pm
  7. 4
      Web/templates/blog/domain_hosted.html.ep

@ -2,6 +2,12 @@ package MJB::Web::Controller::Admin;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use Try::Tiny;
#=====
# This file handles the admin panel
#
# It is a controller, the template files live in templates/admin.
#=====
#==
# GET /admin | show_admin
#

@ -3,13 +3,12 @@ use Mojo::Base 'Mojolicious::Controller', -signatures;
use Try::Tiny;
use DateTime;
#==
# Auth Controller
#
# This controller handles the user registration, login/logout,
#=====
# This file handles the the user registration, login/logout,
# and resetting a forgotten password.
#==
#
# It is a controller, the template files live in templates/auth.
#=====
#==
# GET /register | show_register | templates/auth/register.html.ep

@ -2,28 +2,46 @@ package MJB::Web::Controller::Blog;
use Mojo::Base 'Mojolicious::Controller', -signatures;
use Try::Tiny;
# Blog Create Work Flow:
# 1. Choose Domain
# 2. Choose Blog Settings
# 3. Information Page For Initial Instructions
#=====
# This file handles the initial creation of a blog.
#
# It is a controller, the template files live in templates/blog.
#=====
#==
# GET /blog | show_blog
#
# Redirect the user to the initial step of the blog creation process.
#==
sub index ( $c ) {
$c->redirect_to( 'show_blog_domain_hosted' );
}
# Initial blog creation entry point when the user
# wants to use one of the domains that we provide.
#==
# GET /blog/domain/hosted | show_blog_domain_hosted
#
# The initial entrypoint for blog creation.
#==
sub domain_hosted ( $c ) {
push @{$c->stash->{errors}}, $c->flash('error_message')
if $c->flash('error_message');
}
#==
# POST /blog/domain/hosted | do_blog_domain_hosted
# subdomain | A subdomain that the user would like to use
# hosted_domain_id | The id of a hosted_domain that the user wants to use
#
# This route will create a blog as a subdomain of a hosted domain. We control
# the DNS, SSL, etc.
#==
sub do_domain_hosted ( $c ) {
my $sub_domain = $c->param('subdomain');
my $sub_domain = $c->stash->{form}->{subdomain} = $c->param('subdomain');
my $top_domain = $c->db->hosted_domain( $c->param('hosted_domain_id') );
# Store the hosted domain id so we can have the right domain selected on the drop down
# for errors.
$c->stash->{form}->{hdid} = $top_domain->id;
$sub_domain = lc($sub_domain);
push @{$c->stash->{errors}}, "Please select a domain from the drop down menu."
@ -38,28 +56,35 @@ sub do_domain_hosted ( $c ) {
push @{$c->stash->{errors}}, "That domain name is already being used."
unless $c->db->domains( { name => $sub_domain . '.' . $top_domain->name } )->count == 0;
if ( $c->stash->{errors} ) {
$c->flash( errors => $c->stash->{errors} );
$c->redirect_to( $c->url_for( 'show_blog_domain_hosted' ) );
return;
}
return $c->redirect_error( 'show_blog_domain_hosted' )
if $c->stash->{errors};
# ( $top_domain->letsencrypt_challenge ne 'http' ? )$top_domain->name
my $domain_name = $sub_domain . '.' . $top_domain->name;
my $domain_ssl = $top_domain->letsencrypt_challenge ne 'http' ? $top_domain->name : '';
return $c->_initialize_blog( $domain_name, 'show_blog_domain_hosted', $domain_ssl );
}
# Initial blog creation entry point when the user
# wants to use a domain that they own.
#==
# GET /blog/domain/owned | show_blog_domain_owned
#
# The initial entrypoint for blog creation on a domain that the user controls
# DNS for.
#==
sub domain_owned ( $c ) {
$c->stash->{dns_record} = 'external.' . $c->db->hosted_domains->first->name;
}
#==
# POST /blog/domain/owned | do_blog_domain_owned
# domain_name | The domain name that the user would like to use
#
# This route will create a blog with whatever domain the user supplies. They will
# need to have ensured that DNS is pointed to the correct addresses so that it works.
#==
sub do_domain_owned ( $c ) {
my $domain_name = $c->param('domain_name');
my $domain_name = $c->stash->{form}->{domain_name} = $c->param('domain_name');
$domain_name = lc($domain_name);
@ -69,19 +94,18 @@ sub do_domain_owned ( $c ) {
push @{$c->stash->{errors}}, "That domain name is already being used."
unless $c->db->domains( { name => $domain_name } )->count == 0;
if ( $c->stash->{errors} ) {
$c->flash( errors => $c->stash->{errors} );
$c->redirect_to( $c->url_for( 'show_blog_domain_owned' ) );
return;
}
return $c->redirect_error( 'show_blog_domain_owned' )
if $c->stash->{errors};
return $c->_initialize_blog( $domain_name, 'show_blog_domain_owned', '' );
}
# This is a special exception, it's actually a get request, because we want it
# forwarded from the domain_hosted / domain_owned requests, and redirecting to
# a post doesn't work. However, since we're doing things rather than displaying
# things, it'll be named with the do_
#==
# Helper Function...
#
# This will make the blog after domain_hosted / domain_owned figures out what
# it's making.
#==
sub _initialize_blog ( $c, $domain, $from, $ssl_domain ) {
# Do we already have this domain name?
@ -138,10 +162,24 @@ sub _initialize_blog ( $c, $domain, $from, $ssl_domain ) {
$c->redirect_to( $c->url_for( 'show_blog_settings', { id => $blog->id } ) );
}
#==
# GET /blog/:id/settings | show_blog_settings
#
# This page gives the user the chance to set the title, description, email, etc.
#==
sub settings ( $c ) {
}
#==
# POST /blog/:id/settings | show_blog_settings
# configTitle | The title for the blog
# configDesc | The description for the blog
# configEmail | An email address for the blog's author
#
# This route handles the initial configuration of the blog, and schedules
# the minion job to initialize it.
#==
sub do_settings ( $c ) {
my $blog = $c->stash->{blog} = $c->db->blog( $c->param('id') );
@ -177,5 +215,4 @@ sub do_settings ( $c ) {
$c->redirect_to( $c->url_for( 'show_dashboard_blog', { id => $blog->id } ) );
}
1;

@ -1,6 +1,12 @@
package MJB::Web::Controller::Dashboard;
use Mojo::Base 'Mojolicious::Controller', -signatures;
#=====
# This file handles the dashboard panel
#
# It is a controller, the template files live in templates/dashboard.
#=====
#==
# GET /dashboard | show_dashboard
#==

@ -3,6 +3,12 @@ use Mojo::Base 'Mojolicious::Controller', -signatures;
use Try::Tiny;
use DateTime;
#=====
# This file handles the more-or-less static pages.
#
# It is a controller, the template files live in templates/root.
#=====
#==
# GET / | show_homepage
#==

@ -1,6 +1,12 @@
package MJB::Web::Controller::UserSettings;
use Mojo::Base 'Mojolicious::Controller', -signatures;
#=====
# This file handles the My Info / User Settings panels.
#
# It is a controller, the template files live in templates/user_settings.
#=====
#==
# GET /profile | show_profile | templates/user_settings/profile.html.ep
#==

@ -31,11 +31,11 @@
<div class="col-8">
<div class="input-group mb-3">
<span class="input-group-text" id="domain-addon-1">https://</span>
<input type="text" name="subdomain" class="form-control" placeholder="YourSiteName" aria-label="domain name" aria-describedby="domain-addon">
<input type="text" name="subdomain" class="form-control" value="<%= $c->stash->{form}->{subdomain} %>" placeholder="YourSiteName" aria-label="domain name" aria-describedby="domain-addon">
<span class="input-group-text" id="domain-addon-2">.
<select name="hosted_domain_id" class="form-select" aria-label="Select Domain Name">
% foreach my $hosted_domain ( $c->db->hosted_domains->all ) {
<option name="hosted_domain_id" value="<%= $hosted_domain->id %>"><%= $hosted_domain->name %></option>
<option name="hosted_domain_id" value="<%= $hosted_domain->id %>" <%= $c->stash->{form}->{hdid} == $hosted_domain->id ? 'selected' : '' %>><%= $hosted_domain->name %></option>
% }
</select>
</span>

Loading…
Cancel
Save