OSDN Git Service

t#30444:add site profile
[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         'guest'
11       when :user
12         'guest'
13       when :demand_user
14         'guest'
15       end
16     else
17       'application'
18     end
19   end
20   
21   def bf
22     @server_result = {
23       :location => {:controller => params[:controller], :action => params[:action]}
24     }
25     @server_result[:location][:id] = params[:id] if params[:id]
26     if Admin.count.to_i == 0 or License.count.to_i == 0
27       if params[:controller] == 'system' and params[:action] == 'start'
28       else
29         redirect_to :controller => '/system', :action => 'start'
30       end
31     else
32       if user_signed_in?
33         @user = current_user
34         @author = @user.author
35         @artist = if @author and @author.artist?
36           @author.artist
37         else
38           nil
39         end
40       end
41       @admin = if admin_signed_in?
42         current_admin
43       else
44         nil
45       end
46       @demand_user = if demand_user_signed_in?
47         current_demand_user
48       else
49         nil
50       end
51     end
52   end
53   
54   def authenticate_author
55     if @author
56       true
57     else
58       respond_to do |format|
59         format.html { redirect_to main_app.new_author_path, :status => :found }
60         format.js { render "authors/new" }
61         format.json { 
62           raise ActiveRecord::Forbidden
63         }
64       end
65       false
66     end
67   end
68   
69   def authenticate_artist
70     if @author and @author.artist?
71       true
72     else
73       respond_to do |format|
74         format.html { redirect_to main_app.new_artist_path, :status => :found }
75         format.js { render "artists/new" }
76         format.json { 
77           raise ActiveRecord::Forbidden
78         }
79       end
80       false
81     end
82   end
83   
84   def set_image(file)
85     if file.respond_to?(:read)
86       file.read
87     else
88       Base64.decode64(file.to_s.gsub(' ', '+'))
89     end
90   end
91   
92 =begin
93   rescue_from ActiveRecord::RecordNotFound, :with => :render_404
94
95   private
96   def render_404(exception = nil)
97     if exception
98         logger.info "Rendering 404: #{exception.message}"
99     end
100     respond_to do |format|
101           format.html { 
102     render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
103 }
104           format.json { 
105     render :text => "404 found", :status => 404
106 }
107   end
108   end
109 =end  
110 end