Skip to content

Commit f77829e

Browse files
author
Kaitlyn Parkhurst
committed
Submit a blog entry.
1 parent f71eaf8 commit f77829e

3 files changed

Lines changed: 44 additions & 13 deletions

File tree

Web/lib/BlogDB/Web.pm

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,21 @@ sub startup ($self) {
8585
$auth->post( '/user/settings/email' )->to( 'User#post_email' )->name( 'do_user_email' );
8686

8787
# /blog/ routes
88-
$r->get ( '/blog/:name' )->to( 'Blog#get_blog' )->name( 'blog' ); # View A Specific Blog.
89-
90-
$auth->get ( '/blog/new' )->to( 'Blog#get_new_blogs' )->name( 'new_blogs' ); # List pending blogs for approval.
9188
$r->post ( '/blog/new' )->to( 'Blog#post_new_blog' )->name( 'do_new_blog' ); # Create a new blog.
92-
$r->get ( '/blog/new/:name' )->to( 'Blog#get_edit_blog' )->name( 'edit_new_blog' ); # Get the edit page for a new blog.
93-
$r->post ( '/blog/new/:name' )->to( 'Blog#post_edit_blog' )->name( 'do_edit_new_blog' ); # Post an update with the edit page.
94-
95-
$auth->post( '/blog/:name/follow' )->to( 'Blog#post_follow' )->name( 'do_follow_blog' );
96-
$auth->post( '/blog/:name/unfollow' )->to( 'Blog#post_unfollow' )->name( 'do_unfollow_blog' );
97-
$auth->get ( '/blog/:name/settings' )->to( 'Blog#get_settings' )->name( 'blog_settings' );
98-
$auth->post( '/blog/:name' )->to( 'Blog#post_settings' )->name( 'do_blog_settings' );
99-
$auth->post( '/blog/:name/publish' )->to( 'Blog#post_publish' )->name( 'do_publish' );
100-
$auth->post( '/blog/:name/unpublish' )->to( 'Blog#post_unpublish')->name( 'do_unpublish' );
89+
90+
# $r->get ( '/view/:id/:name' )->to( 'Blog#get_blog' )->name( 'blog' ); # View A Specific Blog.
91+
#
92+
# $auth->get ( '/blog/new' )->to( 'Blog#get_new_blogs' )->name( 'new_blogs' ); # List pending blogs for approval.
93+
# $r->get ( '/blog/new/:id/:title' )->to( 'Blog#get_edit_blog' )->name( 'edit_new_blog' ); # Get the edit page for a new blog.
94+
# $r->post ( '/blog/new/:name' )->to( 'Blog#post_edit_blog' )->name( 'do_edit_new_blog' ); # Post an update with the edit page.
95+
#
96+
# $auth->post( '/blog/:name/follow' )->to( 'Blog#post_follow' )->name( 'do_follow_blog' );
97+
# $auth->post( '/blog/:name/unfollow' )->to( 'Blog#post_unfollow' )->name( 'do_unfollow_blog' );
98+
# $auth->get ( '/blog/:name/settings' )->to( 'Blog#get_settings' )->name( 'blog_settings' );
99+
# $auth->post( '/blog/:name' )->to( 'Blog#post_settings' )->name( 'do_blog_settings' );
100+
# $auth->post( '/blog/:name/publish' )->to( 'Blog#post_publish' )->name( 'do_publish' );
101+
# $auth->post( '/blog/:name/unpublish' )->to( 'Blog#post_unpublish')->name( 'do_unpublish' );
102+
101103

102104
# /tags/
103105
$r->get ( '/tags' )->to( 'Tags#get_tags' )->name( 'tags' );

Web/lib/BlogDB/Web/Controller/Blog.pm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package BlogDB::Web::Controller::Blog;
22
use Mojo::Base 'Mojolicious::Controller', -signatures;
3+
use Data::UUID;
34

45
sub get_blog ($c) {
56
$c->set_template( 'blog/index' );
@@ -44,6 +45,34 @@ sub get_new_blogs ($c) {
4445

4546
sub post_new_blog ($c) {
4647

48+
49+
$c->set_template( 'index' );
50+
51+
my $blog_url = $c->stash->{form_url} = $c->param('url');
52+
53+
# Error Checking - We have all of the information.
54+
push @{$c->stash->{errors}}, "URL is required." unless $blog_url;
55+
56+
# TODO: Valid URL?
57+
58+
return 0 if $c->stash->{errors};
59+
60+
# If an anonymous user submitted the blog, make an edit token
61+
# for them to use.
62+
if ( ! exists $c->session->{edit_token} ) {
63+
$c->session->{edit_token} = Data::UUID->new->create_str,
64+
}
65+
66+
my $blog = $c->db->resultset('PendingBlog')->create({
67+
state => 'initial',
68+
url => $blog_url,
69+
( exists $c->stash->{person}
70+
? ( submitter_id => $c->stash->{person}->id )
71+
: ( edit_token => $c->session->{edit_token} )
72+
),
73+
});
74+
75+
#$c->redirect_to( $c->url_for( 'do_blog_edit', id => $blog->id, title => 'new' ) );
4776
}
4877

4978
sub get_edit_new_blog ($c) {

Web/templates/default/index.html.tx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!-- Add New Blog Section -->
88
<div class="d-flex justify-content-center">
9-
<form method="post" class="row row-cols-lg-auto align-items-center" action="[% $c.url_for( 'do_add_blog' ) %]">
9+
<form method="post" class="row row-cols-lg-auto align-items-center" action="[% $c.url_for( 'do_new_blog' ) %]">
1010
<div class="col-12">
1111
<input placeholder="http://reallycoolblog.com" type="text" name="url" value="[% $form_blog_url %]">
1212
</div>

0 commit comments

Comments
 (0)