You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.3 KiB
79 lines
2.3 KiB
package MJB::Web::Controller::Blog;
|
|
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
|
use Try::Tiny;
|
|
|
|
sub create ($c) {
|
|
|
|
}
|
|
|
|
sub do_create ($c) {
|
|
my $domain_type = $c->stash->{form_domain_type} = $c->param('domain_type');
|
|
my $domain = $c->stash->{form_owned_domain} = $c->param('owned_domain');
|
|
my $subdomain = $c->stash->{form_hosted_subdomain} = $c->param('hosted_subdomain');
|
|
|
|
push @{$c->stash->{errors}}, "Unknown domain type submitted."
|
|
unless $domain_type eq 'owned' or $domain_type eq 'hosted';
|
|
|
|
if ( $domain_type eq 'hosted' ) {
|
|
push @{$c->stash->{errors}}, "You must enter a subdomain."
|
|
unless $subdomain;
|
|
|
|
} elsif ( $domain_type eq 'owned' ) {
|
|
push @{$c->stash->{errors}}, "You must enter a domain."
|
|
unless $domain;
|
|
}
|
|
|
|
return if $c->stash->{errors};
|
|
|
|
$domain = $domain ? $domain : $subdomain . '.' . $c->config->{customer_domain};
|
|
|
|
# Create the Jekyll repo for the site
|
|
my $jekyll = $c->jekyll($domain)->init;
|
|
|
|
my $blog = try {
|
|
$c->db->storage->schema->txn_do( sub {
|
|
# Make the domain name record.
|
|
my $domain_record = $c->stash->{person}->create_related('domains', {
|
|
name => $domain,
|
|
});
|
|
|
|
# Make the website record
|
|
my $blog = $c->stash->{person}->create_related('blogs', {
|
|
domain_id => $domain_record->id,
|
|
});
|
|
|
|
$blog->create_related( 'repoes', {
|
|
url => $jekyll->repo,
|
|
});
|
|
|
|
return $blog;
|
|
});
|
|
} catch {
|
|
push @{$c->stash->{errors}}, "Account could not be created: $_";
|
|
};
|
|
|
|
# Choose a web server to deploy to
|
|
return if $c->stash->{errors};
|
|
|
|
$domain = $domain ? $domain : $subdomain . '.' . $c->config->{hosted_domain};
|
|
|
|
|
|
# Configure DNS to point to the blog
|
|
|
|
# Schedule a job to deploy the website
|
|
my $ssl_job_id = $c->minion->enqueue( 'create_ssl_cert', [ $blog->id ], {
|
|
notes => { '_mjb_bid_' . $blog->id => 1 },
|
|
queue => 'certbot',
|
|
});
|
|
|
|
$c->minion->enqueue( 'deploy_blog', [ $blog->id ], {
|
|
notes => { '_mjb_bid_' . $blog->id => 1 },
|
|
parents => [ $ssl_job_id ],
|
|
});
|
|
|
|
# Take the user to the management panel for the site
|
|
|
|
}
|
|
|
|
|
|
1;
|
|
|