OSDN Git Service

bb3551c0aa9f7f8e0b3dca9d44e96fc4b3171082
[pettanr/pettanr.git] / app / controllers / application_controller.rb
1 class ApplicationController < ActionController::Base
2   protect_from_forgery
3   layout :devise_layout if MagicNumber['test_layout']
4   before_filter :bf
5   
6   def devise_layout
7     if devise_controller?
8       case resource_name
9       when :admin
10         'test'
11       when :user
12         'test'
13       end
14     else
15       'application'
16     end
17   end
18   
19   def bf
20     @server_result = {
21       :location => {:controller => params[:controller], :action => params[:action]}
22     }
23     @server_result[:location][:id] = params[:id] if params[:id]
24     if Admin.count.to_i == 0 or License.count.to_i == 0
25       if params[:controller] == 'system' and params[:action] == 'start'
26       else
27         redirect_to :controller => '/system', :action => 'start'
28       end
29     else
30       if user_signed_in?
31         @user = current_user
32         @author = @user.author
33         @artist = if @author and @author.artist?
34           @author.artist
35         else
36           nil
37         end
38       end
39       @admin = if admin_signed_in?
40         current_admin
41       else
42         nil
43       end
44     end
45   end
46   
47   def authenticate_author
48     if @author
49       true
50     else
51       respond_to do |format|
52         format.html { redirect_to main_app.new_author_path, :status => :found }
53         format.js { render "authors/new" }
54         format.json { 
55           raise ActiveRecord::Forbidden
56         }
57       end
58       false
59     end
60   end
61   
62   def authenticate_artist
63     if @author.artist?
64       true
65     else
66       respond_to do |format|
67         format.html { redirect_to main_app.new_artist_path, :status => :found }
68         format.js { render "artists/new" }
69         format.json { 
70           raise ActiveRecord::Forbidden
71         }
72       end
73       false
74     end
75   end
76   
77   def set_image(file)
78     if file.respond_to?(:read)
79       file.read
80     else
81       Base64.decode64(file.to_s.gsub(' ', '+'))
82     end
83   end
84   
85 =begin
86   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
87
88   private
89   def render_404(exception = nil)
90     if exception
91         logger.info "Rendering 404: #{exception.message}"
92     end
93     respond_to do |format|
94           format.html { 
95     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
96 }
97           format.json { 
98     render :text => "404 found", :status => 404
99 }
100   end
101   end
102 =end  
103 end