Prettify the login page
[cs356-p2-videostore.git] / app / controllers / purchase_controller.rb
index a3b61bb..2ac4dae 100644 (file)
@@ -1,5 +1,8 @@
 class PurchaseController < ApplicationController
 
+  # Make sure that a user logs in before doing any action here
+  before_filter :authorize
+
   def index
     redirect_to :action => :begin
   end
@@ -73,6 +76,20 @@ class PurchaseController < ApplicationController
       return
     end
 
+    @maxoverduevideos = RentablePolicy.find_by_name("MaxOverdueVideos")
+    if @rentable.class == Video and @customer.overdue_videos >= @maxoverduevideos.value
+      flash[:error] = "#{@maxoverduevideos.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
+    @maxoverduegames = RentablePolicy.find_by_name("MaxOverdueGames")
+    if @rentable.class == Game and @customer.overdue_games >= @maxoverduegames.value
+      flash[:error] = "#{@maxoverduegames.description} LIMIT REACHED"
+      redirect_to :action => :rent_begin
+      return
+    end
+
     # Check out the item
     checkout = Coitem.new
     checkout.customer = @customer