OSDN Git Service

t#30444:add site profile
[pettanr/pettanr.git] / app / controllers / application_controller.rb
index fc35d3f..22ed9b2 100644 (file)
@@ -1,7 +1,23 @@
 class ApplicationController < ActionController::Base
   protect_from_forgery
+  layout :devise_layout if MagicNumber['test_layout']
   before_filter :bf
   
+  def devise_layout
+    if devise_controller?
+      case resource_name
+      when :admin
+        'guest'
+      when :user
+        'guest'
+      when :demand_user
+        'guest'
+      end
+    else
+      'application'
+    end
+  end
+  
   def bf
     @server_result = {
       :location => {:controller => params[:controller], :action => params[:action]}
@@ -27,11 +43,31 @@ class ApplicationController < ActionController::Base
       else
         nil
       end
+      @demand_user = if demand_user_signed_in?
+        current_demand_user
+      else
+        nil
+      end
+    end
+  end
+  
+  def authenticate_author
+    if @author
+      true
+    else
+      respond_to do |format|
+        format.html { redirect_to main_app.new_author_path, :status => :found }
+        format.js { render "authors/new" }
+        format.json { 
+          raise ActiveRecord::Forbidden
+        }
+      end
+      false
     end
   end
   
   def authenticate_artist
-    if @author.artist?
+    if @author and @author.artist?
       true
     else
       respond_to do |format|
@@ -49,7 +85,7 @@ class ApplicationController < ActionController::Base
     if file.respond_to?(:read)
       file.read
     else
-      Base64.decode64(file.to_s.gsub(' ', '+')) #rubyのバグ?+でデコードされるべきキャラがスペースになる
+      Base64.decode64(file.to_s.gsub(' ', '+'))
     end
   end