OSDN Git Service

iroiro v032_signup
authoryasushiito <yas@pen-chan.jp>
Sun, 15 Jan 2012 05:42:01 +0000 (14:42 +0900)
committeryasushiito <yas@pen-chan.jp>
Sun, 15 Jan 2012 05:42:01 +0000 (14:42 +0900)
26 files changed:
app/assets/javascripts/author_registrations.js.coffee [new file with mode: 0644]
app/assets/stylesheets/author_registrations.css.scss [new file with mode: 0644]
app/controllers/author_registrations_controller.rb [new file with mode: 0644]
app/controllers/authors_controller.rb
app/controllers/comics_controller.rb
app/controllers/home_controller.rb
app/controllers/system_controller.rb
app/helpers/author_registrations_helper.rb [new file with mode: 0644]
app/models/author.rb
app/models/comic.rb
app/views/artists/list.html.erb
app/views/author_registrations/new.html.erb [new file with mode: 0644]
app/views/authors/registrations/new.html.erb
app/views/comics/top.html.erb
app/views/home/comic.html.erb [new file with mode: 0644]
app/views/home/configure.html.erb [new file with mode: 0644]
app/views/home/index.html.erb
app/views/home/picture.html.erb [new file with mode: 0644]
app/views/home/step2.html.erb [new file with mode: 0644]
app/views/home/step3.html.erb [new file with mode: 0644]
app/views/layouts/application.html.erb
app/views/original_pictures/_uploader.html.erb
app/views/original_pictures/index.html.erb
config/routes.rb
spec/controllers/author_registrations_controller_spec.rb [new file with mode: 0644]
spec/helpers/author_registrations_helper_spec.rb [new file with mode: 0644]

diff --git a/app/assets/javascripts/author_registrations.js.coffee b/app/assets/javascripts/author_registrations.js.coffee
new file mode 100644 (file)
index 0000000..7615679
--- /dev/null
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/app/assets/stylesheets/author_registrations.css.scss b/app/assets/stylesheets/author_registrations.css.scss
new file mode 100644 (file)
index 0000000..a97efb9
--- /dev/null
@@ -0,0 +1,3 @@
+// Place all the styles related to the author_registrations controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
diff --git a/app/controllers/author_registrations_controller.rb b/app/controllers/author_registrations_controller.rb
new file mode 100644 (file)
index 0000000..9744070
--- /dev/null
@@ -0,0 +1,7 @@
+class AuthorRegistrationsController < Devise::RegistrationsController
+  protected\r
+\r
+  def after_sign_up_path_for(resource)\r
+    '/home/step2'\r
+  end
+end
index c960bc5..a69fffa 100644 (file)
@@ -33,5 +33,5 @@ class AuthorsController < ApplicationController
       format.html { render layout: 'system' }
     end
   end
       format.html { render layout: 'system' }
     end
   end
-
+  
 end
 end
index 8a5169c..3513be4 100644 (file)
@@ -11,7 +11,12 @@ class ComicsController < ApplicationController
   public
   
   def top
   public
   
   def top
-    @comics = Comic.all
+    @new_comics = Comic.find(:all, 
+      :include => :author, :conditions => ['visible = 1'], :order => 'updated_at desc', :limit => 5
+    )
+    @new_pictures = OriginalPicture.find(:all, 
+      :include => [:artist, :lisence, :resource_picture], :order => 'updated_at', :limit => 5
+    )
 
     respond_to do |format|
       format.html # index.html.erb
 
     respond_to do |format|
       format.html # index.html.erb
index cc3895a..fea06ed 100644 (file)
@@ -1,8 +1,8 @@
 class HomeController < ApplicationController
 class HomeController < ApplicationController
-  
-  def start
-    
-  end
+  before_filter :authenticate_author!, :only => [
+    :index, :show, :profile, :configure, :create_token, :delete_token, :step2, :save_step2, :step3, :save_step3, 
+    :comic, :picture
+  ]
   
   def index
   end
   
   def index
   end
@@ -10,4 +10,93 @@ class HomeController < ApplicationController
   def profile
   end
   
   def profile
   end
   
+  def configure
+  end
+  
+  def create_token
+    @author = current_author
+    respond_to do |format|
+      if @author.create_token
+        format.html { redirect_to({:action => :configure}, {:notice => 'author token was successfully created.'}) }
+      else
+        format.html { render action: "auth_token" }
+      end
+    end
+  end
+  
+  def delete_token
+    current_author.delete_token
+    respond_to do |format|
+      format.html { redirect_to :action => :configure}
+    end
+  end
+  
+  def step2
+    @author = current_author
+  end
+  
+  def save_step2
+    @author = current_author
+    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
+    end
+  end
+  
+  def step3
+    @artist = Artist.new :author_id => current_author.id, :name => current_author.name, :default_lisence_id => 1
+  end
+  
+  def save_step3
+    if current_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
+    end
+  end
+  
+  def comic
+    @comics = Comic.find(:all, 
+      :include => :author, :conditions => ['author_id = ?', current_author.id], 
+      :order => 'updated_at desc', :limit => 20
+    )
+
+    respond_to do |format|
+      format.html # index.html.erb
+      format.json { render json: @comics }
+    end
+  end
+  
+  def picture
+    if current_author.artist?
+      @original_pictures = OriginalPicture.find(:all, 
+        :include => [:artist, :lisence, :resource_picture], :conditions => ['artist_id = ?', current_author.artist.id], 
+        :order => 'updated_at', :limit => 20
+      )
+
+      respond_to do |format|
+        format.html # index.html.erb
+        format.json { render :json => @original_pictures.to_json(
+          :include => [:resource_picture, :artist, :lisence]
+        ) }
+      end
+    else
+    end
+  end
+  
 end
 end
index 69c0a93..a466600 100644 (file)
@@ -4,7 +4,19 @@ class SystemController < ApplicationController
   #layout :system
   
   def start
   #layout :system
   
   def start
-  
+    OriginalPicture.all.each do |a|
+      a.lisence_id = 1 if a.lisence_id.blank?
+      a.save
+    end
+    ResourcePicture.all.each do |a|
+      a.lisence_id = 1 if a.lisence_id.blank?
+      a.artist_id = 1 if a.artist_id.blank?
+      a.save
+    end
+    Artist.all.each do |a|
+      a.default_lisence_id = 1 if a.default_lisence_id.blank?
+      a.save
+    end
   end
   
   def index
   end
   
   def index
diff --git a/app/helpers/author_registrations_helper.rb b/app/helpers/author_registrations_helper.rb
new file mode 100644 (file)
index 0000000..4614791
--- /dev/null
@@ -0,0 +1,2 @@
+module AuthorRegistrationsHelper
+end
index cc154ca..2341a9f 100644 (file)
@@ -7,15 +7,29 @@ class Author < ActiveRecord::Base
          :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
 
   # Setup accessible (or protected) attributes for your model
          :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable
 
   # Setup accessible (or protected) attributes for your model
-  attr_accessible :email, :password, :password_confirmation, :remember_me
+  attr_accessible :id, :name, :password, :password_confirmation, :remember_me #, :email
 
 
-  before_save :ensure_authentication_token\r
   before_save do |r|
     r.name = 'no name' if r.name.blank?
   end
   
   before_save do |r|
     r.name = 'no name' if r.name.blank?
   end
   
- def artist?
-   Artist.find_by_author(self) != nil
- end
+  def artist?
+    Artist.find_by_author(self) != nil
+  end
+  
+  def create_token
+    self.ensure_authentication_token
+    self.save
+  end
+  
+  def delete_token
+    self.authentication_token = nil
+    self.save
+  end
+  
+  def step2 n
+    self.name = n
+    self.save
+  end
+  
 end
 end
index ab882cf..2411318 100644 (file)
@@ -11,4 +11,8 @@ class Comic < ActiveRecord::Base
     editable == 1 ? 'O' : 'X'
   end
   
     editable == 1 ? 'O' : 'X'
   end
   
+  def disp_visible
+    visible == 1 ? 'O' : 'X'
+  end
+  
 end
 end
index cf81c73..1ffd5d3 100644 (file)
@@ -20,9 +20,9 @@
     <td><%= h artist.email %></td>
     <td><%= h artist.name %></td>
     <td><%= h artist.homepage_url %></td>
     <td><%= h artist.email %></td>
     <td><%= h artist.name %></td>
     <td><%= h artist.homepage_url %></td>
+    <td><%= h artist.api_url %></td>
     <td><%= link_to artist.default_lisence_id, :controller => 'lisences', :action => :browse, :id => artist.default_lisence_id %></td>
     <td><%= artist.crowled_at %></td>
     <td><%= link_to artist.default_lisence_id, :controller => 'lisences', :action => :browse, :id => artist.default_lisence_id %></td>
     <td><%= artist.crowled_at %></td>
-    <td><%= h artist.api_url %></td>
     <td><%= link_to artist.author_id, :controller => 'authors', :action => :browse, :id => artist.author_id %></td>
     <td><%= artist.created_at %></td>
     <td><%= artist.updated_at %></td>
     <td><%= link_to artist.author_id, :controller => 'authors', :action => :browse, :id => artist.author_id %></td>
     <td><%= artist.created_at %></td>
     <td><%= artist.updated_at %></td>
diff --git a/app/views/author_registrations/new.html.erb b/app/views/author_registrations/new.html.erb
new file mode 100644 (file)
index 0000000..d15e275
--- /dev/null
@@ -0,0 +1,18 @@
+<h2>Sign up</h2>
+
+<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
+  <%= devise_error_messages! %>
+
+  <div><%= f.label :email %><br />
+  <%= f.email_field :email %></div>
+
+  <div><%= f.label :password %><br />
+  <%= f.password_field :password %></div>
+
+  <div><%= f.label :password_confirmation %><br />
+  <%= f.password_field :password_confirmation %></div>
+
+  <div><%= f.submit "Sign up" %></div>
+<% end %>
+
+<%= render :partial => "devise/shared/links" %>
index 3ae6813..d15e275 100644 (file)
@@ -3,9 +3,6 @@
 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
   <%= devise_error_messages! %>
 
 <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
   <%= devise_error_messages! %>
 
-  <div><%= f.label :name %><br />
-  <%= f.text_field :name %></div>
-
   <div><%= f.label :email %><br />
   <%= f.email_field :email %></div>
 
   <div><%= f.label :email %><br />
   <%= f.email_field :email %></div>
 
index 696809e..df6393a 100644 (file)
@@ -1,5 +1,6 @@
-<h1><%= link_to '新着', comics_path %></h1>
-
+<%= link_to "comics", comics_path %>
+<h1>コミック</h1>
+<%= link_to '新着', comics_path %>
 <table>
   <tr>
     <th>Title</th>
 <table>
   <tr>
     <th>Title</th>
@@ -9,7 +10,7 @@
     <th></th>
   </tr>
 
     <th></th>
   </tr>
 
-<% @comics.each do |comic| %>
+<% @new_comics.each do |comic| %>
   <tr>
     <td><%= link_to h(comic.title), :action => :play, :id => comic.id %></td>
     <td><%= comic.editable %></td>
   <tr>
     <td><%= link_to h(comic.title), :action => :play, :id => comic.id %></td>
     <td><%= comic.editable %></td>
   </tr>
 <% end %>
 </table>
   </tr>
 <% end %>
 </table>
-<h1>人気</h1>
-
+<%= link_to '人気', comics_path %>
+<h3>コマ</h3>
+<%= link_to '新着', panels_path %>
+<%= link_to '人気', panels_path %>
+<h1>素材</h1>
+<% @new_pictures.each do |picture| %>
+  <div>
+    <img src="<%= picture.resource_picture.url('thumbnail') -%>">
+    画:<%= h picture.artist.name %>
+  </div>
+<% end %>
+<%= link_to "もっと見る", original_pictures_path %>
+<h3>ライセンス</h3>
+<%= link_to "lisences", lisences_path %>
diff --git a/app/views/home/comic.html.erb b/app/views/home/comic.html.erb
new file mode 100644 (file)
index 0000000..6c9b62d
--- /dev/null
@@ -0,0 +1,14 @@
+<h1>Listing comics</h1>
+
+<% @comics.each do |comic| %>
+  <div>
+    <div>
+      <%= link_to h(comic.title), :action => :play, :id => comic.id %>
+      一般投稿:<%= comic.disp_editable %>
+      公開:<%= comic.disp_visible %>
+    </div>
+    <div>
+      更新:<%= comic.updated_at %>
+    </div>
+  </div>
+<% end %>
diff --git a/app/views/home/configure.html.erb b/app/views/home/configure.html.erb
new file mode 100644 (file)
index 0000000..38b80af
--- /dev/null
@@ -0,0 +1,15 @@
+<h2>認証トークン</h2>
+<div>
+あなたの認証トークンは<%= current_author.authentication_token %>です
+</div>
+<div>
+  <% if current_author.authentication_token %>
+    <%= link_to 'delete token', :action => :delete_token %>
+  <% else %>
+    <%= link_to 'generate token', :action => :create_token %>
+  <% end %>
+</div>
+<h2>退会</h2>
+<div>
+  <%= link_to('退会する', {:controller => 'author_registrations', :action => :destroy, :id => current_author.id}, {:method => :delete}) %>
+</div>
index e45cd11..ea26dcb 100644 (file)
@@ -1,7 +1,4 @@
 <h1><%= h(current_author.name) -%>(<%= h(current_author.email) -%>)</h1>
 <h1><%= h(current_author.name) -%>(<%= h(current_author.email) -%>)</h1>
-<div>
-あなたの認証トークンは<%= current_author.authentication_token %>です
-</div>
 
 <div>
 <p>絵師活動</p>
 
 <div>
 <p>絵師活動</p>
diff --git a/app/views/home/picture.html.erb b/app/views/home/picture.html.erb
new file mode 100644 (file)
index 0000000..e948534
--- /dev/null
@@ -0,0 +1,10 @@
+<h1>Listing my pictures</h1>
+
+<% @original_pictures.each do |original_picture| %>
+  <div>
+    <%= original_picture.filename %>
+    <img src="<%= original_picture.resource_picture.url('thumbnail') -%>">
+    <%= original_picture.width %>x<%= original_picture.height %>
+    <%= original_picture.filesize %>bytes
+  </div>
+<% end %>
diff --git a/app/views/home/step2.html.erb b/app/views/home/step2.html.erb
new file mode 100644 (file)
index 0000000..70281cb
--- /dev/null
@@ -0,0 +1,32 @@
+<h1>ようこそ、ぺったんRへ</h1>
+<div>
+<%= h(current_author.email) -%>さんはぺったんRで作家としてデビューしました。
+今すぐにでも作品を作れますが、より良い活動をするために作家名を登録してください。
+</div>
+<%= form_for(:author, :url => {:controller => '/home', :action => :save_step2}) do |f| %>
+  <% if @author.errors.any? %>
+    <div id="error_explanation">
+      <h2><%= pluralize(@author.errors.count, "error") %> prohibited this original_lisence from being saved:</h2>
+
+      <ul>
+      <% @author.errors.full_messages.each do |msg| %>
+        <li><%= msg %></li>
+      <% end %>
+      </ul>
+    </div>
+  <% end %>
+
+  <div class="field">
+    <%= f.label :name %><br />
+    <%= f.text_field :name %>
+  </div>
+  <p>あなたの素材を投稿してみませんか?</p>
+  絵師としての情報を登録すれば、あなたのキャラクターを漫画に登場させるなど、幅広い創作活動ができます。
+  <div class="field">
+    <%= check_box_tag 'step3', 1, false %> 引き続き、絵師登録を行う
+  </div>
+
+  <div class="actions">
+    <%= f.submit '次のステップへ' %>
+  </div>
+<% end %>
diff --git a/app/views/home/step3.html.erb b/app/views/home/step3.html.erb
new file mode 100644 (file)
index 0000000..13a37a1
--- /dev/null
@@ -0,0 +1,31 @@
+<h1>ようこそ、ぺったんRへ</h1>
+<%= h(current_author.name) -%>さん
+<div>
+  <%= form_for(:artist, :url => {:controller => '/home', :action => :save_step3}) do |f| %>
+    <% if @artist.errors.any? %>
+      <div id="error_explanation">
+        <h2><%= pluralize(@artist.errors.count, "error") %> prohibited this artist from being saved:</h2>
+
+        <ul>
+        <% @artist.errors.full_messages.each do |msg| %>
+          <li><%= msg %></li>
+        <% end %>
+        </ul>
+      </div>
+    <% end %>
+
+    <div class="field">
+      <p>作家名とは別に絵師としてのペンネームを設定できます。</p>
+      <%= f.label :name %><br />
+      <%= f.text_field :name %><br />
+
+      <p>素材をアップロードするときのデフォルトライセンスを選択します。</p>
+      <%= f.label :default_lisence_id %><br />
+      <%= f.select :default_lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :html => {:selected => @artist.default_lisence_id} %>
+      <%= f.hidden_field :author_id, :value => @artist.author_id %>
+    </div>
+    <div class="actions">
+      <%= f.submit '完了' %>
+    </div>
+  <% end %>
+</div>
index 22a644c..be0c608 100644 (file)
 <div>
 <% if author_signed_in? %>
   <%= link_to "my home", :controller => '/home' %>
 <div>
 <% if author_signed_in? %>
   <%= link_to "my home", :controller => '/home' %>
+  <%= link_to "my comics", :controller => '/home', :action => :comic %>
+  <%= link_to "my pictures", :controller => '/home', :action => :picture %>
+  <%= link_to "config", :controller => '/home', :action => :configure %>
   <%= link_to "ログアウト", destroy_author_session_path, :method => :delete %>
 <% else %>
   <%= link_to "ログイン", new_author_session_path %>
 <% end %>
 </div>
 <div>
   <%= link_to "ログアウト", destroy_author_session_path, :method => :delete %>
 <% else %>
   <%= link_to "ログイン", new_author_session_path %>
 <% end %>
 </div>
 <div>
+ <p class="notice"><%= notice %></p>
+ <p class="alert"><%= alert %></p>
+</div>
+<%= yield %>
+
+<div>
 <% if admin_signed_in? %>
   <%= link_to "system", :controller => '/system' %>
   <%= link_to "ログアウト", destroy_admin_session_path, :method => :delete %>
 <% if admin_signed_in? %>
   <%= link_to "system", :controller => '/system' %>
   <%= link_to "ログアウト", destroy_admin_session_path, :method => :delete %>
   <%= link_to "管理者", new_admin_session_path %>
 <% end %>
 </div>
   <%= link_to "管理者", new_admin_session_path %>
 <% end %>
 </div>
-<div>
- <p class="notice"><%= notice %></p>
- <p class="alert"><%= alert %></p>
-</div>
-<%= link_to "comics", comics_path %>
-<%= link_to "panels", panels_path %>
-<%= link_to "pictures", original_pictures_path %>
-<%= link_to "lisences", lisences_path %>
-<%= yield %>
-
 </body>
 </html>
 </body>
 </html>
index 21555b3..8514d84 100644 (file)
@@ -2,6 +2,8 @@
   <% if current_author.artist? -%>
     <%= form_tag( {:action => "create"} , { :multipart => true }) do %>
       <label for="file">File to Upload</label> <%= file_field_tag "original_picture[file]" %>
   <% if current_author.artist? -%>
     <%= form_tag( {:action => "create"} , { :multipart => true }) do %>
       <label for="file">File to Upload</label> <%= file_field_tag "original_picture[file]" %>
+      lisence
+      <%= collection_select :original_picture, :lisence_id, Lisence.all.map {|l| [l.name, l.id] }, :last, :first, :html => {:selected => current_author.artist.default_lisence_id} %>
       <%= submit_tag 'upload' -%>
     <% end -%>
   <% else -%>
       <%= submit_tag 'upload' -%>
     <% end -%>
   <% else -%>
index 43c5fb2..096b4b3 100644 (file)
@@ -8,5 +8,6 @@
     <%= original_picture.width %>x<%= original_picture.height %>
     <%= original_picture.filesize %>bytes
     画:<%= h original_picture.artist.name %>
     <%= original_picture.width %>x<%= original_picture.height %>
     <%= original_picture.filesize %>bytes
     画:<%= h original_picture.artist.name %>
+    lisence:<%= h Lisence.find(original_picture.lisence_id || 1).name %>
   </div>
 <% end %>
   </div>
 <% end %>
index 2032dec..2a20daa 100644 (file)
@@ -1,7 +1,7 @@
 Pettanr::Application.routes.draw do
 
   devise_for :admins
 Pettanr::Application.routes.draw do
 
   devise_for :admins
-  devise_for :authors
+  devise_for :authors, :controllers => { :registrations => "author_registrations" }
 
   match 'original_pictures/:id(.:format)/refresh' => 'original_pictures#refresh'
 
 
   match 'original_pictures/:id(.:format)/refresh' => 'original_pictures#refresh'
 
diff --git a/spec/controllers/author_registrations_controller_spec.rb b/spec/controllers/author_registrations_controller_spec.rb
new file mode 100644 (file)
index 0000000..9950920
--- /dev/null
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe AuthorRegistrationsController do
+
+end
diff --git a/spec/helpers/author_registrations_helper_spec.rb b/spec/helpers/author_registrations_helper_spec.rb
new file mode 100644 (file)
index 0000000..ceaabcb
--- /dev/null
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+# Specs in this file have access to a helper object that includes
+# the AuthorRegistrationsHelper. For example:
+#
+# describe AuthorRegistrationsHelper do
+#   describe "string concat" do
+#     it "concats two strings with spaces" do
+#       helper.concat_strings("this","that").should == "this that"
+#     end
+#   end
+# end
+describe AuthorRegistrationsHelper do
+  pending "add some examples to (or delete) #{__FILE__}"
+end