1 class ApplicationController < ActionController::Base
3 layout :devise_layout if MagicNumber['test_layout']
23 :location => {:controller => params[:controller], :action => params[:action]}
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'
29 redirect_to :controller => '/system', :action => 'start'
34 @author = @user.author
35 @artist = if @author and @author.artist?
41 @admin = if admin_signed_in?
46 @demand_user = if demand_user_signed_in?
54 def authenticate_author
58 respond_to do |format|
59 format.html { redirect_to main_app.new_author_path, :status => :found }
60 format.js { render "authors/new" }
62 raise ActiveRecord::Forbidden
69 def authenticate_artist
70 if @author and @author.artist?
73 respond_to do |format|
74 format.html { redirect_to main_app.new_artist_path, :status => :found }
75 format.js { render "artists/new" }
77 raise ActiveRecord::Forbidden
85 if file.respond_to?(:read)
88 Base64.decode64(file.to_s.gsub(' ', '+'))
92 def ymd_to_time ymd_str
93 return nil if ymd_str.blank?
96 date = Time.parse(ymd_str[0..3] + '/' + ymd_str[4..5] + '/' + ymd_str[6..7])
103 def export_url demander_url, action, token, date
104 u = demander_url + (demander_url[-1] == '/' ? '' : '/')
105 u = URI.join(u, action + '.json?auth_token=' + token)
106 u = URI.join(u, '&date=' + date) unless date.blank?
110 def export_from_provider url
111 json = RestClient.get url
115 def export_by action, provider_status, ymd
117 url = export_url provider_status.provider.demander_url, action, provider_status.token, t
118 export_from_provider(url)
122 rescue_from ActiveRecord::RecordNotFound, :with => :render_404
125 def render_404(exception = nil)
127 logger.info "Rendering 404: #{exception.message}"
129 respond_to do |format|
131 render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
134 render :text => "404 found", :status => 404