Some controllers.

master
Kaitlyn Parkhurst 3 years ago
parent c42c947a88
commit 4f4a4ae8d1
  1. 8
      Web/lib/MJB/Web.pm
  2. 64
      Web/lib/MJB/Web/Controller/Blog.pm
  3. 8
      Web/lib/MJB/Web/Controller/Dashboard.pm
  4. 66
      Web/templates/blog/create.html.ep
  5. 5
      Web/templates/dashboard/index.html.ep

@ -86,6 +86,14 @@ sub startup ($self) {
$auth->get ( '/password' )->to('UserSettings#change_password' )->name('show_change_password' );
$auth->post( '/password' )->to('UserSettings#do_change_password' )->name('do_change_password' );
# Dashboard
$auth->get ( '/dashboard' )->to('Dashboard#index' )->name('show_dashboard' );
# Blog Management
$auth->get ( '/blog/create' )->to('Blog#create' )->name('show_blog_create' );
$auth->post( '/blog/create' )->to('Blog#do_create' )->name('do_blog_create' );
}

@ -0,0 +1,64 @@
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};
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,
});
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};
# Create the Jekyll repo for the site
# Configure DNS to point to the blog
# Schedule a job to deploy the website
# Take the user to the management panel for the site
}
1;

@ -0,0 +1,8 @@
package MJB::Web::Controller::Dashboard;
use Mojo::Base 'Mojolicious::Controller', -signatures;
sub index ($c) {
}
1;

@ -0,0 +1,66 @@
% layout 'standard', title => 'Create Blog', sb_active => 'dashboard';
<h2 class="mt-5 display-6 mb-4">Create a new blog</h2>
<div class="mt-5">
<div class="progress" style="height: 1px;">
<div class="progress-bar bg-light" role="progressbar" style="width: 33%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar" role="progressbar" style="width: 34%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-light" role="progressbar" style="width: 33%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div class="progress mt-1" style="height: 20px;">
<div class="progress-bar bg-success" role="progressbar" style="width: 33%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">Connect Repo</div>
<div class="progress-bar" role="progressbar" style="width: 34%;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">Choose Domain</div>
<div class="text-center progress-bar-striped" style="width: 33%">Select Builder</div>
</div>
</div>
<h2 style="margin-top: 1.5em; margin-bottom: 1em" class="h2">Choose a domain</h2>
<p>Next you can choose a domain name for your website. You can host your website on a subdomain of <%= $c->config->{customer_domain} %> without any further configuration on your part, just enter YourSiteName below.</p>
<p>If you have your own domain, you can also use that. Be sure to set your DNS records to match *.<%= $c->config->{customer_domain} %>.<p>
% if ( $c->stash->{success} ) {
<div style="margin-top: 2em" class="alert alert-success" role="alert">
<%= $c->stash->{success_message} %>
</div>
% }
% if ( $c->stash->{errors} ) {
<div style="margin-top: 2em" class="alert alert-danger" role="alert">
There were errors with your request that could not be resolved:
<ul>
% for my $error ( @{$c->stash->{errors}} ) {
<li><%= $error %></li>
% }
</ul>
</div>
% }
<form style="margin-top: 1.5em" method="POST" action="<%= $c->url_for( 'do_blog_create' ) %>">
<div class="row">
<input type="hidden" name="repo_id" value="<%= stash 'form_repo_id' %>">
<div class="col">
<div class="mb-4 form-check form-check-inline">
<input class="form-check-input" type="radio" name="domain_type" id="inlineRadio1" value="hosted" checked>
<label class="form-check-label" for="inlineRadio1">Use our domain</label>
</div>
<div class="input-group mb-3">
<input type="text" name="hosted_subdomain" class="form-control" placeholder="YourSiteName" aria-label="domain name" aria-describedby="domain-addon">
<span class="input-group-text" id="domain-addon">.<%= $c->config->{customer_domain} %></span>
</div>
</div>
<div class="col" style="border-left: 1px solid #ccc">
<div class="mb-4 form-check form-check-inline">
<input class="form-check-input" type="radio" name="domain_type" id="inlineRadio2" value="owned">
<label class="form-check-label" for="inlineRadio2">Use a domain you own</label>
</div>
<div class="input-group mb-3">
<input type="text" name ="owned_domain" class="form-control" placeholder="your.domain.com" aria-label="domain name">
</div>
</div>
</div>
<button type="submit" class="btn btn-primary float-end mt-3">Continue &rarr;</button>
</form>

@ -0,0 +1,5 @@
% layout 'standard', title => 'Dashboard', sb_active => 'dashboard';
<h2 class="mt-5 display-6 mb-4">This is totes the dashboard</h2>
<a href="<%= $c->url_for( 'show_blog_create' ) %>">Create a new blog</a>
Loading…
Cancel
Save