OSDN Git Service

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