diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 9fd4f83cc..2ef7f0e86 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -1,5 +1,9 @@ class TasksController < ApplicationController def index + if @mytask.user_id != session[:user_id] + flash[:notice] = "You cannot view a task list that is not your own." + redirect_to homepage_path + end @tasks = Task.where(user_id: session[:user_id]) @user = User.find(session[:user_id]) end @@ -10,6 +14,10 @@ def new def show @mytask = Task.find(params[:id].to_i) + if @mytask.user_id != session[:user_id] + flash[:notice] = "You cannot view or edit tasks that are not your own." + redirect_to homepage_path + end end def delete @@ -33,6 +41,10 @@ def update end def create + if session[:user_id] = nil + flash[:notice] = "You must be logged in to create a task." + redirect_to homepage_path + end @params = params @mytask = Task.new @mytask.task_name = params[:task][:task_name] diff --git a/app/models/task.rb b/app/models/task.rb index 935f76e12..5c58542c4 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -1,2 +1,3 @@ class Task < ActiveRecord::Base + belongs_to :user end diff --git a/app/models/user.rb b/app/models/user.rb index f6c13853a..c3d95eb89 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,4 +1,5 @@ class User < ActiveRecord::Base + has_many :tasks validates :email, :uid, :provider, presence: true def self.build_from_github(auth_hash) diff --git a/config/routes.rb b/config/routes.rb index a9de6b90d..2fa4e024c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,7 +28,7 @@ get "/auth/:provider/callback" => "sessions#create" - get 'homepages/index' + get 'homepages/index', as: 'homepage' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes".