diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 0baebee..6d754de 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -1,71 +1,50 @@ class BlogpostsController < ApplicationController + before_filter :set_post, except: [:index, :new, :create] + before_filter :auth, except: [:index, :show] + def index @posts = Blogpost.all.reverse end def show - @post = Blogpost.find(params[:id]) @comment = Comment.new(blogpost: @post) end def new - if mod? - @post = Blogpost.new - else - flash[:alert] = "You are not allowed to create a new post!" - redirect_to blogposts_path - end + @post = Blogpost.new end def edit - @post = Blogpost.find(params[:id]) - if mod? - else - flash[:alert] = "You are not allowed to edit this post!" - redirect_to @post - end end def create - if mod? - @post = Blogpost.new(post_params) - @post.user_author = current_user - if @post.save - redirect_to @post, notice: 'Post has been created.' - else - flash[:alert] = "Error creating blogpost" - render action: "new" - end + @post = Blogpost.new(post_params) + @post.user_author = current_user + if @post.save + redirect_to @post, notice: 'Post has been created.' else - flash[:alert] = "You are not allowed to create new posts" - redirect_to blog_path + flash[:alert] = "Error creating blogpost" + render action: "new" end end def update - @post = Blogpost.find(params[:id]) - if mod? || @comment.author.is?(current_user) - @post.user_editor = current_user - if @post.update_attributes(post_params([:user_editor])) - redirect_to @post, notice: 'Post has been updated.' - else - flash[:alert] = "There was a problem while updating the post" - render action: "edit" - end + @post.user_editor = current_user + @post.attributes = post_params([:user_editor]) + if @post.save + redirect_to @post, notice: 'Post has been updated.' + else + flash[:alert] = "There was a problem while updating the post" + render action: "edit" end end def destroy - @post = Blogpost.find(params[:id]) - if mod? - if @post.destroy - flash[:notice] = "Post deleted!" - else - flash[:alert] = "There was a problem while deleting this Post" - end + if @post.destroy + flash[:notice] = "Post deleted!" else - flash[:alert] = "You are not allowed to delete this Post" + flash[:alert] = "There was a problem while deleting this Post" end redirect_to blogposts_path end @@ -78,4 +57,18 @@ class BlogpostsController < ApplicationController a += add params.require(:blogpost).permit(a) end + + def set_post + if params[:id] + @post = Blogpost.find(params[:id]) + end + end + + def auth + unless mod? + flash[:alert] = "You are not allowed to edit posts!" + redirect_to @post ? @post : blogposts_path + end + end + end \ No newline at end of file diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 77e77cf..a8b9d33 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -29,7 +29,9 @@ class CommentsController < ApplicationController def update @comment = Comment.find(params[:id]) if mod? || @comment.author.is?(current_user) - if @comment.update_attributes(comment_params) + @comment.user_editor = current_user + @comment.attributes = comment_params + if @comment.save flash[:notice] = "Comment updated!" redirect_to blogpost_path(@comment.blogpost) + "#comment-#{@comment.id}" else diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index 167ac75..d5c9412 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -12,7 +12,8 @@ class ForumthreadsController < ApplicationController def update if mod? || @thread.author.is?(current_user) @thread.user_editor = current_user - if @thread.update_attributes thread_params([:user_editor]) + @thread.attributes = thread_params([:user_editor]) + if @thread.save redirect_to @thread, notice: 'Post has been updated.' else flash[:alert] = "There was a problem while updating the post" diff --git a/app/controllers/info_controller.rb b/app/controllers/info_controller.rb new file mode 100644 index 0000000..a1c9892 --- /dev/null +++ b/app/controllers/info_controller.rb @@ -0,0 +1,68 @@ +class InfoController < ApplicationController + + before_filter :set_info, except: [:index, :new, :create] + before_filter :auth, except: [:index, :show] + + def index + @info = Info.all.sort_by{|i| i.title} + end + + def show + end + + def new + @info = Info.new + end + + def edit + end + + def create + @info = Info.new(info_params) + if @info.save + redirect_to @info, notice: 'Info has been created.' + else + flash[:alert] = "Error creating info" + render action: "new" + end + end + + def update + @info.attributes = info_params() + if @info.save + redirect_to @info, notice: 'Info has been updated.' + else + flash[:alert] = "There was a problem while updating the info" + render action: "edit" + end + end + + def destroy + if @info.destroy + flash[:notice] = "Info deleted!" + else + flash[:alert] = "There was a problem while deleting this info" + end + redirect_to info_index_path + end + + + private + + def info_params(add = []) + a = [:title, :content] + a += add + params.require(:info).permit(a) + end + + def set_info + @info = Info.find(params[:id]) + end + + def auth + unless mod? + flash[:alert] = "You are not allowed to edit info!" + redirect_to @info ? @info : info_index_path + end + end +end \ No newline at end of file diff --git a/app/controllers/threadreplies_controller.rb b/app/controllers/threadreplies_controller.rb index ff90650..f00e5d1 100644 --- a/app/controllers/threadreplies_controller.rb +++ b/app/controllers/threadreplies_controller.rb @@ -1,3 +1,65 @@ class ThreadrepliesController < ApplicationController + def edit + @reply = Threadreply.find(params[:id]) + if mod? || @reply.author.is?(current_user) + else + flash[:alert] = "You are not allowed to edit this reply" + redirect_to @reply.thread + end + end + + def create + thread = Forumthread.find(params[:forumthread_id]) + if thread.can_write?(current_user) + @reply = Threadreply.new(reply_params) + @reply.user_author = current_user + @reply.forumthread = thread + if @reply.save + redirect_to forumthread_path(@reply.thread) + "#reply-#{@reply.id}", notice: 'Reply created!' + else + flash[:alert] = "Could not create reply." + redirect_to Blogpost.find(params[:forumthread_id]) + end + else + flash[:alert] = "You are not allowed to create replies." + redirect_to Blogpost.find(params[:forumthread_id]) + end + end + + def update + @reply = Threadreply.find(params[:id]) + if mod? || @reply.author.is?(current_user) + if @reply.update_attributes(reply_params) + flash[:notice] = "Reply updated!" + redirect_to forumthread_path(@reply.thread) + "#reply-#{@reply.id}" + else + flash[:alert] = "There was a problem while updating your reply" + render action: "edit" + end + else + flash[:alert] = "You are not allowed to edit this reply" + redirect_to @reply.thread + end + end + + def destroy + @reply = Threadreply.find(params[:id]) + if mod? || @reply.author.is?(current_user) + if @reply.destroy + flash[:notice] = "Reply deleted!" + else + flash[:alert] = "There was a problem while deleting this reply" + end + else + flash[:alert] = "You are not allowed to delete this reply" + end + redirect_to @reply.thread + end + + private + + def reply_params + params.require(:threadreply).permit(:content) + end end \ No newline at end of file diff --git a/app/models/comment.rb b/app/models/comment.rb index afc9114..d4829d1 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,5 +1,7 @@ class Comment < ActiveRecord::Base + belongs_to :user_author, class_name: "User", foreign_key: "user_author_id" + belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id" validates_presence_of :content, :author, :blogpost validates_length_of :content, in: 4..1000 diff --git a/app/models/info.rb b/app/models/info.rb new file mode 100644 index 0000000..b8fdfb4 --- /dev/null +++ b/app/models/info.rb @@ -0,0 +1,6 @@ +class Info < ActiveRecord::Base + self.table_name = "info" + + validates_presence_of :title, :content + +end \ No newline at end of file diff --git a/app/views/blogposts/edit.html.erb b/app/views/blogposts/edit.html.erb index 1f7f428..eefc9ee 100644 --- a/app/views/blogposts/edit.html.erb +++ b/app/views/blogposts/edit.html.erb @@ -5,4 +5,4 @@ <%= f.text_area :content, :label => false, input_html: {class: "full-width vertical"} %>
<%= f.submit "Update Post", class: "btn blue left" %>
<% end %> -<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post & comments forever?", class: "btn red right" %>
\ No newline at end of file +<%= 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/comments/edit.html.erb b/app/views/comments/edit.html.erb index 857e3ec..092f0a3 100644 --- a/app/views/comments/edit.html.erb +++ b/app/views/comments/edit.html.erb @@ -4,4 +4,4 @@ <%= f.input :content, label: false, as: "text", placeholder: "Comment" %><%= f.submit "Update Comment", class: "btn blue left" %>
<% end %> -<%= button_to "Delete comment", [@comment.blogpost, @comment] , method: "delete", confirm: "Delete comment forever?", class: "btn red right" %>
\ No newline at end of file +<%= button_to "Delete comment", [@comment.blogpost, @comment] , method: "delete", data: {confirm: "Delete comment forever?"}, class: "btn red right" %>
\ No newline at end of file diff --git a/app/views/forumgroups/edit.html.erb b/app/views/forumgroups/edit.html.erb index 5f94ff2..9b4f731 100644 --- a/app/views/forumgroups/edit.html.erb +++ b/app/views/forumgroups/edit.html.erb @@ -34,4 +34,4 @@<%= f.submit "Update group", class: "btn blue" %>
<% end %> -<%= button_to "Delete group", @post, :method => "delete", :confirm => "Delete group?\nForums + Threads will not be accessible!", class: "btn red right" %>
\ No newline at end of file +<%= button_to "Delete group", @post, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right" %>
\ No newline at end of file diff --git a/app/views/forumthreads/edit.html.erb b/app/views/forumthreads/edit.html.erb index 8b5d74b..9cd84b1 100644 --- a/app/views/forumthreads/edit.html.erb +++ b/app/views/forumthreads/edit.html.erb @@ -1,8 +1,22 @@Note: You can use <%= link_to "Markdown", "https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet", target: "_blank" %>!
-<%= simple_form_for [@thread.forum, @thread] do |f|%> - <%= f.input :title, label: false %> - <%= f.text_area :content, label: false, input_html: {class: "full-width vertical"} %> - <%= f.submit "Update thread", class: "btn blue left" %> +<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → New thread +<%= form_for @thread do |f|%> +| <%= f.label :sticky %> | +<%= f.check_box :sticky %> | +
| <%= f.label :locked %> | +<%= f.check_box :locked %> | +
<%= f.submit "Update thread", class: "btn blue" %>
<% end %> -<%= button_to "Delete thread", [@thread.forum, @thread], :method => "delete", :confirm => "Delete thread & comments forever?", class: "btn red right" %> \ No newline at end of file +<%= button_to "Delete thread", @thread, :method => "delete", data: {confirm: "Delete thread & comments forever?"}, class: "btn red right" %> \ No newline at end of file diff --git a/app/views/forumthreads/show.html.erb b/app/views/forumthreads/show.html.erb index 4b9c9ba..1cda450 100644 --- a/app/views/forumthreads/show.html.erb +++ b/app/views/forumthreads/show.html.erb @@ -14,11 +14,12 @@<%= f.submit "Update Info", class: "btn blue left" %>
+<% end %> +<%= button_to "Delete Info", @info, method: "delete", data: {confirm: "Delete Info forever?"}, class: "btn red right" %>
\ No newline at end of file diff --git a/app/views/info/index.html.erb b/app/views/info/index.html.erb new file mode 100644 index 0000000..12c33a9 --- /dev/null +++ b/app/views/info/index.html.erb @@ -0,0 +1,9 @@ +<%= f.submit "Create Info", class: "btn blue left" %>
+<% end %> \ No newline at end of file diff --git a/app/views/info/show.html.erb b/app/views/info/show.html.erb new file mode 100644 index 0000000..36e6f7d --- /dev/null +++ b/app/views/info/show.html.erb @@ -0,0 +1,3 @@ +<%= link_to "Info", info_index_path %> → <%= @info.title %> +Thank you for registering on Redstoner.com!
-To use your account, you need to <%= link_to "confirm", confirm_user_path(@user, code: @user.email_token, only_path: false) %> your email address.
+Thank you for registering on Redstoner.com!
+To use your account, you need to <%= link_to "confirm", confirm_user_path(@user, code: @user.email_token, only_path: false) %>your email address.
-<% if @mcpw %> -- - NEVER USE THE SAME PASSWORD TWICE! - -
-
-
- You used your minecraft password on our website. We could have stolen it easily!
-
- (But we didn't)
-
+ + NEVER USE THE SAME PASSWORD TWICE! + +
++ + You used your minecraft password on our website. Do not do that. It's just stupid. + +
+Please click this link to confirm your registration: -
Please click this link to confirm your registration: +
+If you have any questions or problems, just ask one of our <%= link_to "Staff", users_path(role: "staff", only_path: false) %> in-game.
+Your Redstoner team
+ +If you have any questions or problems, just ask one of our <%= link_to "Staff", users_path(role: "staff", only_path: false) %> in-game.
-Your Redstoner team
- - -If you did not sign up on redstoner.com you can safely ignore this email \ No newline at end of file +If you did not sign up on redstoner.com you can safely ignore this email! +
+You can contact us via: <%= link_to "Website", "root_path" %> | <%= link_to "Twitter", "https://twitter.com/RedstonerServer" %> | <%= link_to "Google+", "https://google.com/+Redstoner" | <%= link_to "Email", "mailto:redstonerserver+website@gmail.com" %>
+<%= f.submit "Reply", class: "btn blue" %>
+<% end %> \ No newline at end of file diff --git a/app/views/threadreplies/_reply.html.erb b/app/views/threadreplies/_reply.html.erb new file mode 100644 index 0000000..dd061b2 --- /dev/null +++ b/app/views/threadreplies/_reply.html.erb @@ -0,0 +1,12 @@ +<%= f.submit "Reply", class: "btn blue" %>
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1fe7e54..9b16a5c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ Site::Application.routes.draw do end end - resources :roles + resources :info resources :users do member do @@ -23,18 +23,20 @@ Site::Application.routes.draw do end end - resources :forums, path: 'forums' - resources :forumthreads, path: '/forums/threads' resources :forumgroups, path: 'forums/groups' + resources :forums, path: 'forums' + resources :forumthreads, path: '/forums/threads' do + resources :threadreplies, path: '/forums/threads/replies' + end - get '/status' => 'status#show' + # get '/status' => 'status#show' - get "logout" => 'sessions#destroy' get 'login' => 'sessions#new' - get 'signup' => 'users#new' post 'login' => 'sessions#create' + get "logout" => 'sessions#destroy' + get 'signup' => 'users#new' - post 'paypal' => 'paypal#create' + # post 'paypal' => 'paypal#create' root to: 'statics#index' end \ No newline at end of file diff --git a/db/migrate/11_create_info.rb b/db/migrate/11_create_info.rb new file mode 100644 index 0000000..c7dc516 --- /dev/null +++ b/db/migrate/11_create_info.rb @@ -0,0 +1,8 @@ +class CreateInfo < ActiveRecord::Migration + def change + create_table :info do |t| + t.string :title + t.text :content + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b877bbc..f666e1a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,36 +9,36 @@ # from scratch. The latter is a flawed and unsustainable approach (the more migrations # you'll amass, the slower it'll run and the greater likelihood for issues). # -# It's strongly recommended to check this file into your version control system. +# It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(:version => 10) do +ActiveRecord::Schema.define(version: 11) do - create_table "blogposts", :force => true do |t| + create_table "blogposts", force: true do |t| t.string "title" t.text "content" t.integer "user_author_id" t.integer "user_editor_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "comments", :force => true do |t| + create_table "comments", force: true do |t| t.text "content" t.integer "user_author_id" t.integer "user_editor_id" t.integer "blogpost_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "forumgroups", :force => true do |t| + create_table "forumgroups", force: true do |t| t.string "name" t.integer "position" t.integer "role_read_id" t.integer "role_write_id" end - create_table "forums", :force => true do |t| + create_table "forums", force: true do |t| t.string "name" t.integer "position" t.integer "role_read_id" @@ -46,67 +46,72 @@ ActiveRecord::Schema.define(:version => 10) do t.integer "forumgroup_id" end - create_table "forumthreads", :force => true do |t| + create_table "forumthreads", force: true do |t| t.string "title" t.text "content" - t.boolean "sticky", :default => false - t.boolean "locked", :default => false + t.boolean "sticky", default: false + t.boolean "locked", default: false t.integer "user_author_id" t.integer "user_editor_id" t.integer "forum_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "register_tokens", :primary_key => "uuid", :force => true do |t| - t.string "token", :limit => 6, :null => false - t.string "email", :null => false + create_table "info", force: true do |t| + t.string "title" + t.text "content" end - create_table "roles", :force => true do |t| + create_table "register_tokens", primary_key: "uuid", force: true do |t| + t.string "token", limit: 6, null: false + t.string "email", null: false + end + + create_table "roles", force: true do |t| t.string "name" t.integer "value" end - create_table "sessions", :force => true do |t| - t.string "session_id", :null => false + create_table "sessions", force: true do |t| + t.string "session_id", null: false t.text "data" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" - add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree + add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree - create_table "threadreplies", :force => true do |t| + create_table "threadreplies", force: true do |t| t.text "content" t.integer "user_author_id" t.integer "user_editor_id" t.integer "forumthread_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "users", :force => true do |t| - t.string "uuid", :null => false - t.string "name", :null => false - t.string "password_digest", :null => false - t.string "ign", :null => false - t.string "email", :null => false + create_table "users", force: true do |t| + t.string "uuid", null: false + t.string "name", null: false + t.string "password_digest", null: false + t.string "ign", null: false + t.string "email", null: false t.text "about" t.string "last_ip" t.string "skype" - t.boolean "skype_public", :default => false + t.boolean "skype_public", default: false t.string "youtube" t.string "youtube_channelname" t.string "twitter" - t.boolean "donor", :default => false + t.boolean "donor", default: false t.string "email_token" - t.boolean "confirmed", :default => false + t.boolean "confirmed", default: false t.datetime "last_seen" - t.integer "role_id", :null => false - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.integer "role_id", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end end