OSDN Git Service

t#30473:fix authenticate
[pettanr/pettanr.git] / app / controllers / home_controller.rb
index edd47d0..49129f9 100644 (file)
@@ -1,9 +1,10 @@
 class HomeController < ApplicationController
-  layout 'test' if Pettanr::TestLayout
-  before_filter :authenticate_user!, :only => [
-    :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, 
-    :comic, :picture
+  layout 'test' if MagicNumber['test_layout']
+  before_filter :authenticate_user, :only => [
+    :index, :show, :profile, :configure, :create_token, :delete_token, 
+    :comic, :story, :panel, :resource_picture, :panel_picture, :panel_color, :ground_picture, :ground_color
   ]
+  before_filter :authenticate_artist, :only => [:resource_picture]
   
   def index
   end
@@ -15,84 +16,114 @@ class HomeController < ApplicationController
   end
   
   def create_token
-    respond_to do |format|
-      if @user.create_token
-        format.html { redirect_to({:action => :configure}, {:notice => 'user token was successfully created.'}) }
-      else
-        format.html { render action: "auth_token" }
+    if @user.create_token
+      respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.created', :model => User.human_attribute_name(:authentication_token))
+        format.html { redirect_to({:action => :configure}) }
       end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_created', :model => User.human_attribute_name(:authentication_token))
+      format.html { render action: "configure" }
     end
   end
   
   def delete_token
-    @user.delete_token
+    if @user.delete_token
+      respond_to do |format|
+        flash[:notice] = I18n.t('flash.notice.destroyed', :model => User.human_attribute_name(:authentication_token))
+        format.html { redirect_to :action => :configure}
+      end
+    else
+      flash[:notice] = I18n.t('flash.notice.not_destroyed', :model => User.human_attribute_name(:authentication_token))
+      format.html { render action: "configure" }
+    end
+  end
+  
+  def comic
+    @page = Author.page params[:page]
+    @page_size = Author.comic_page_size params[:page_size]
+    @comics = Comic.mylist(@author, @page, @page_size)
+
     respond_to do |format|
-      format.html { redirect_to :action => :configure}
+      format.html # index.html.erb
+      format.json { render json: @comics.to_json(Comic.list_json_opt) }
     end
   end
   
-  def step2
+  def story
+    @page = Author.page params[:page]
+    @page_size = Author.story_page_size params[:page_size]
+    @stories = Story.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render text: Story.list_as_json_text(@stories) }
+    end
   end
   
-  def save_step2
+  def panel
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @panels = Panel.mylist(@author, @page, @page_size)
+
     respond_to do |format|
-      if @author.step2(params[:author][:name])
-        a = if params[:step3].to_i == 1
-          :step3
-        else
-          :index
-        end
-        format.html { redirect_to({:action => a}, {:notice => 'your name was successfully updated.'}) }
-      else
-        format.html { render action: "step2" }
-      end
+      format.html # index.html.erb
+      format.json { render text: Panel.list_as_json_text(@panels) }
     end
   end
   
-  def step3
+  def panel_picture
+    @page = Author.page params[:page]
+    @page_size = Author.panel_picture_page_size params[:page_size]
+    @panel_pictures = PanelPicture.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @panel_pictures.to_json(PanelPicture.list_json_opt) }
+    end
   end
   
-  def save_step3
-    if @author.artist?
-      redirect_to :action => :index
-    else
-      @artist = Artist.new params[:artist]
-      respond_to do |format|
-        if @artist.save
-          format.html { redirect_to({:action => :index}, {:notice => 'artist was successfully registered.'}) }
-        else
-          format.html { render action: "step3" }
-        end
-      end
+  def panel_color
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @panel_colors = PanelColor.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @panel_colors.to_json(PanelColor.list_json_opt) }
     end
   end
   
-  def comic
-    @comics = Comic.find(:all, 
-      :include => :author, :conditions => ['author_id = ?', @author.id], 
-      :order => 'updated_at desc', :limit => 20
-    )
+  def ground_picture
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @ground_pictures = GroundPicture.mylist(@author, @page, @page_size)
 
     respond_to do |format|
       format.html # index.html.erb
-      format.json { render json: @comics }
+      format.json { render json: @ground_pictures.to_json(GroundPicture.list_json_opt) }
     end
   end
   
-  def picture
-    if @author.artist?
-      @original_pictures = OriginalPicture.find(:all, 
-        :include => [:artist, :license, :resource_picture], :conditions => ['artist_id = ?', @author.artist.id], 
-        :order => 'updated_at', :limit => 20
-      )
+  def ground_color
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @ground_colors = GroundColor.mylist(@author, @page, @page_size)
 
-      respond_to do |format|
-        format.html # index.html.erb
-        format.json { render :json => @original_pictures.to_json(
-          :include => [:resource_picture, :artist, :license]
-        ) }
-      end
-    else
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @ground_colors.to_json(GroundColor.list_json_opt) }
+    end
+  end
+  
+  def resource_picture
+    @page = Author.page params[:page]
+    @page_size = Author.panel_page_size params[:page_size]
+    @resource_pictures = ResourcePicture.mylist(@author, @page, @page_size)
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @resource_pictures.to_json(ResourcePicture.list_json_opt) }
     end
   end