OSDN Git Service

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