--- /dev/null
+# 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/
--- /dev/null
+// 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/
--- /dev/null
+class AuthorRegistrationsController < Devise::RegistrationsController
+ protected\r
+\r
+ def after_sign_up_path_for(resource)\r
+ '/home/step2'\r
+ end
+end
format.html { render layout: 'system' }
end
end
-
+
end
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
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 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
#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
--- /dev/null
+module AuthorRegistrationsHelper
+end
: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
- 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
editable == 1 ? 'O' : 'X'
end
+ def disp_visible
+ visible == 1 ? 'O' : 'X'
+ end
+
end
<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><%= 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>
--- /dev/null
+<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" %>
<%= 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>
-<h1><%= link_to '新着', comics_path %></h1>
-
+<%= link_to "comics", comics_path %>
+<h1>コミック</h1>
+<%= link_to '新着', comics_path %>
<table>
<tr>
<th>Title</th>
<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>
<% 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 %>
--- /dev/null
+<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 %>
--- /dev/null
+<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>
<h1><%= h(current_author.name) -%>(<%= h(current_author.email) -%>)</h1>
-<div>
-あなたの認証トークンは<%= current_author.authentication_token %>です
-</div>
<div>
<p>絵師活動</p>
--- /dev/null
+<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 %>
--- /dev/null
+<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 %>
--- /dev/null
+<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>
<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>
+ <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 %>
<%= 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>
<% 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 -%>
<%= 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 %>
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'
--- /dev/null
+require 'spec_helper'
+
+describe AuthorRegistrationsController do
+
+end
--- /dev/null
+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