diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 1ff310d..72fa68f 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -69,7 +69,7 @@ class BlogpostsController < ApplicationController end def auth - unless mod? + unless mod? && current_user.confirmed? flash[:alert] = "You are not allowed to edit posts!" redirect_to @post ? @post : blogposts_path end diff --git a/app/views/blogposts/edit.html.erb b/app/views/blogposts/edit.html.erb index 25da324..94bbc9f 100644 --- a/app/views/blogposts/edit.html.erb +++ b/app/views/blogposts/edit.html.erb @@ -1,10 +1,20 @@ <% title "Edit News: #{@post.title}" %> +<% + def can_edit? + mod? && current_user.confirmed? + end +%> +
<%= f.submit "Update Post", class: "btn blue left" %>
+ <%= f.text_field :title, disabled: !can_edit? %> + <%= render partial: "md_editor", locals: {name: "blogpost[content]", content: @post.content, options: {disabled: !can_edit?}} %> +<%= f.submit "Update Post", class: "btn blue left", disabled: !can_edit? %>
+<% end %> +<%= button_to "Delete post", @post, method: "delete", data: {confirm: "Delete post & comments forever?"}, class: "btn red right", disabled: !can_edit? %>
+ + +<% if !current_user.confirmed? %> + You must confirm your email before you can edit blog posts. <% end %> -<%= button_to "Delete post", @post, method: "delete", data: {confirm: "Delete post & comments forever?"}, class: "btn red right" %>
- \ No newline at end of file diff --git a/app/views/blogposts/new.html.erb b/app/views/blogposts/new.html.erb index b923002..64a69c4 100644 --- a/app/views/blogposts/new.html.erb +++ b/app/views/blogposts/new.html.erb @@ -1,9 +1,19 @@ <% title "New Blog Post" %> +<% + def can_create? + admin? && current_user.confirmed? + end +%> +<%= f.submit "Create Post", class: "btn blue left" %>
+ <%= f.text_field :title, placeholder: "Title", disabled: !can_create? %> + <%= render partial: "md_editor", locals: {name: "blogpost[content]", content: @post.content, options: {disabled: !can_create?}} %> +<%= f.submit "Create Post", class: "btn blue left", disabled: !can_create? %>
+ + <% if !current_user.confirmed? %> + You must confirm your email before you can create new blog posts. + <% end %> <% end %>