|
|
|
|
@ -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; |
|
|
|
|
|