OSDN Git Service

t#28985:add credit
[pettanr/pettanr.git] / app / controllers / home_controller.rb
1 class HomeController < ApplicationController
2   layout 'test' if Pettanr::TestLayout
3   before_filter :authenticate_user!, :only => [
4     :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, 
5     :comic, :picture
6   ]
7   
8   def index
9   end
10   
11   def profile
12   end
13   
14   def configure
15   end
16   
17   def create_token
18     respond_to do |format|
19       if @user.create_token
20         format.html { redirect_to({:action => :configure}, {:notice => 'user token was successfully created.'}) }
21       else
22         format.html { render action: "auth_token" }
23       end
24     end
25   end
26   
27   def delete_token
28     @user.delete_token
29     respond_to do |format|
30       format.html { redirect_to :action => :configure}
31     end
32   end
33   
34   def step2
35   end
36   
37   def save_step2
38     respond_to do |format|
39       if @author.step2(params[:author][:name])
40         a = if params[:step3].to_i == 1
41           :step3
42         else
43           :index
44         end
45         format.html { redirect_to({:action => a}, {:notice => 'your name was successfully updated.'}) }
46       else
47         format.html { render action: "step2" }
48       end
49     end
50   end
51   
52   def step3
53   end
54   
55   def save_step3
56     if @author.artist?
57       redirect_to :action => :index
58     else
59       @artist = Artist.new params[:artist]
60       respond_to do |format|
61         if @artist.save
62           format.html { redirect_to({:action => :index}, {:notice => 'artist was successfully registered.'}) }
63         else
64           format.html { render action: "step3" }
65         end
66       end
67     end
68   end
69   
70   def comic
71     @comics = Comic.find(:all, 
72       :include => :author, :conditions => ['author_id = ?', @author.id], 
73       :order => 'updated_at desc', :limit => 20
74     )
75
76     respond_to do |format|
77       format.html # index.html.erb
78       format.json { render json: @comics }
79     end
80   end
81   
82   def picture
83     if @author.artist?
84       @original_pictures = OriginalPicture.find(:all, 
85         :include => [:artist, :license, :resource_picture], :conditions => ['artist_id = ?', @author.artist.id], 
86         :order => 'updated_at', :limit => 20
87       )
88
89       respond_to do |format|
90         format.html # index.html.erb
91         format.json { render :json => @original_pictures.to_json(
92           :include => [:resource_picture, :artist, :license]
93         ) }
94       end
95     else
96     end
97   end
98   
99 end