From baeeb875e66e472a4c9eb82ed399bcaeaf2f8990 Mon Sep 17 00:00:00 2001 From: yasushiito Date: Thu, 8 Mar 2012 18:30:48 +0900 Subject: [PATCH] add user and delete flip flags --- ...troller.rb => user_registrations_controller.rb} | 2 +- app/models/author.rb | 19 +---------- app/models/panel_picture.rb | 2 +- app/models/user.rb | 22 +++++++++++++ app/views/panel_pictures/index.html.erb | 2 -- app/views/panel_pictures/list.html.erb | 4 --- app/views/users/browse.html.erb | 38 ++++++++++++++++++++++ .../{authors => users}/confirmations/new.html.erb | 0 app/views/users/index.html.erb | 13 ++++++++ app/views/users/list.html.erb | 31 ++++++++++++++++++ .../mailer/confirmation_instructions.html.erb | 0 .../mailer/reset_password_instructions.html.erb | 0 .../mailer/unlock_instructions.html.erb | 0 .../{authors => users}/passwords/edit.html.erb | 0 .../{authors => users}/passwords/new.html.erb | 0 .../{authors => users}/registrations/edit.html.erb | 0 .../{authors => users}/registrations/new.html.erb | 0 app/views/{authors => users}/sessions/new.html.erb | 0 app/views/{authors => users}/shared/_links.erb | 0 app/views/users/show.html.erb | 8 +++++ app/views/{authors => users}/unlocks/new.html.erb | 0 config/routes.rb | 15 ++++++++- db/migrate/20111206091950_create_authors.rb | 17 ++++++++++ db/migrate/20111206113803_create_panel_pictures.rb | 2 -- ...rs.rb => 20120306231650_devise_create_users.rb} | 5 ++- spec/models/user_spec.rb | 5 +++ 26 files changed, 153 insertions(+), 32 deletions(-) rename app/controllers/{author_registrations_controller.rb => user_registrations_controller.rb} (51%) create mode 100644 app/models/user.rb create mode 100644 app/views/users/browse.html.erb rename app/views/{authors => users}/confirmations/new.html.erb (100%) create mode 100644 app/views/users/index.html.erb create mode 100644 app/views/users/list.html.erb rename app/views/{authors => users}/mailer/confirmation_instructions.html.erb (100%) rename app/views/{authors => users}/mailer/reset_password_instructions.html.erb (100%) rename app/views/{authors => users}/mailer/unlock_instructions.html.erb (100%) rename app/views/{authors => users}/passwords/edit.html.erb (100%) rename app/views/{authors => users}/passwords/new.html.erb (100%) rename app/views/{authors => users}/registrations/edit.html.erb (100%) rename app/views/{authors => users}/registrations/new.html.erb (100%) rename app/views/{authors => users}/sessions/new.html.erb (100%) rename app/views/{authors => users}/shared/_links.erb (100%) create mode 100644 app/views/users/show.html.erb rename app/views/{authors => users}/unlocks/new.html.erb (100%) create mode 100644 db/migrate/20111206091950_create_authors.rb rename db/migrate/{20111206091950_devise_create_authors.rb => 20120306231650_devise_create_users.rb} (85%) create mode 100644 spec/models/user_spec.rb diff --git a/app/controllers/author_registrations_controller.rb b/app/controllers/user_registrations_controller.rb similarity index 51% rename from app/controllers/author_registrations_controller.rb rename to app/controllers/user_registrations_controller.rb index 9744070f..18719011 100644 --- a/app/controllers/author_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -1,4 +1,4 @@ -class AuthorRegistrationsController < Devise::RegistrationsController +class UserRegistrationsController < Devise::RegistrationsController protected def after_sign_up_path_for(resource) diff --git a/app/models/author.rb b/app/models/author.rb index 2341a9f3..7148ef03 100644 --- a/app/models/author.rb +++ b/app/models/author.rb @@ -1,14 +1,7 @@ class Author < ActiveRecord::Base has_one :artist + belongs_to :user - # Include default devise modules. Others available are: - # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable - devise :database_authenticatable, :registerable, - :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable - - # Setup accessible (or protected) attributes for your model - attr_accessible :id, :name, :password, :password_confirmation, :remember_me #, :email - before_save do |r| r.name = 'no name' if r.name.blank? end @@ -17,16 +10,6 @@ class Author < ActiveRecord::Base 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 diff --git a/app/models/panel_picture.rb b/app/models/panel_picture.rb index 0bc67340..eaff1304 100644 --- a/app/models/panel_picture.rb +++ b/app/models/panel_picture.rb @@ -3,7 +3,7 @@ class PanelPicture < ActiveRecord::Base belongs_to :resource_picture def flip - res = (self.flipv == 0 ? '' : 'v') + (self.fliph == 0 ? '' : 'h') + res = (self.height < 0 ? '' : 'v') + (self.width == 0 ? '' : 'h') res += '/' unless res.empty? res end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 00000000..90958af6 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,22 @@ +class User < ActiveRecord::Base + has_one :author + + # Include default devise modules. Others available are: + # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :token_authenticatable, :validatable#, :confirmable + + # Setup accessible (or protected) attributes for your model + attr_accessible :id, :name, :password, :password_confirmation, :remember_me , :email + + def create_token + self.ensure_authentication_token + self.save + end + + def delete_token + self.authentication_token = nil + self.save + end + +end diff --git a/app/views/panel_pictures/index.html.erb b/app/views/panel_pictures/index.html.erb index 9f443805..49f866c3 100644 --- a/app/views/panel_pictures/index.html.erb +++ b/app/views/panel_pictures/index.html.erb @@ -12,7 +12,6 @@ y z t - flip updated_at @@ -28,7 +27,6 @@ <%= panel_picture.t %> <%= panel_picture.width %> <%= panel_picture.height %> - <%= panel_picture.flip %> <%= panel_picture.updated_at %> <% end %> diff --git a/app/views/panel_pictures/list.html.erb b/app/views/panel_pictures/list.html.erb index 1edf3984..f87feff7 100644 --- a/app/views/panel_pictures/list.html.erb +++ b/app/views/panel_pictures/list.html.erb @@ -12,8 +12,6 @@ t Width Height - flipv - fliph created_at updated_at @@ -30,8 +28,6 @@ <%= panel_picture.t %> <%= panel_picture.width %> <%= panel_picture.height %> - <%= panel_picture.flipv %> - <%= panel_picture.fliph %> <%= panel_picture.created_at %> <%= panel_picture.updated_at %> diff --git a/app/views/users/browse.html.erb b/app/views/users/browse.html.erb new file mode 100644 index 00000000..86d0e794 --- /dev/null +++ b/app/views/users/browse.html.erb @@ -0,0 +1,38 @@ +

<%= notice %>

+ +

+ name: + <%= h(@author.name) %> +

+ +

+ email: + <%= h(@author.email) %> +

+ +

+ sign_in_count: + <%= @author.sign_in_count %> +

+ +

+ current_sign_in_at: + <%= @author.current_sign_in_at %> +

+ +

+ last_sign_in_at: + <%= @author.last_sign_in_at %> +

+ +

+ current_sign_in_ip: + <%= @author.current_sign_in_ip %> +

+ +

+ last_sign_in_ip: + <%= @author.last_sign_in_ip %> +

+ +<%= link_to 'Back', :action => :list %> diff --git a/app/views/authors/confirmations/new.html.erb b/app/views/users/confirmations/new.html.erb similarity index 100% rename from app/views/authors/confirmations/new.html.erb rename to app/views/users/confirmations/new.html.erb diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb new file mode 100644 index 00000000..5691bbbf --- /dev/null +++ b/app/views/users/index.html.erb @@ -0,0 +1,13 @@ +

Listing system_pictures

+ + + + + + +<% @authors.each do |author| %> + + + +<% end %> +
Ext
<%= link_to h(author.name), :action => :show, :id => author.id %>
diff --git a/app/views/users/list.html.erb b/app/views/users/list.html.erb new file mode 100644 index 00000000..a5599796 --- /dev/null +++ b/app/views/users/list.html.erb @@ -0,0 +1,31 @@ +

Listing authors

+ + + + + + + + + + + + + + + +<% @authors.each do |author| %> + + + + + + + + + + + + +<% end %> +
idnameemailsign_in_countcurrent_sign_in_atlast_sign_in_atcurrent_sign_in_iplast_sign_in_ipcreated_atupdated_at
<%= link_to author.id, :action => :show, :id => author.id %><%= h(author.name) %><%= h(author.email) %><%= author.sign_in_count %><%= author.current_sign_in_at %><%= author.last_sign_in_at %><%= author.current_sign_in_ip %><%= author.last_sign_in_ip %><%= author.created_at %><%= author.updated_at %>
diff --git a/app/views/authors/mailer/confirmation_instructions.html.erb b/app/views/users/mailer/confirmation_instructions.html.erb similarity index 100% rename from app/views/authors/mailer/confirmation_instructions.html.erb rename to app/views/users/mailer/confirmation_instructions.html.erb diff --git a/app/views/authors/mailer/reset_password_instructions.html.erb b/app/views/users/mailer/reset_password_instructions.html.erb similarity index 100% rename from app/views/authors/mailer/reset_password_instructions.html.erb rename to app/views/users/mailer/reset_password_instructions.html.erb diff --git a/app/views/authors/mailer/unlock_instructions.html.erb b/app/views/users/mailer/unlock_instructions.html.erb similarity index 100% rename from app/views/authors/mailer/unlock_instructions.html.erb rename to app/views/users/mailer/unlock_instructions.html.erb diff --git a/app/views/authors/passwords/edit.html.erb b/app/views/users/passwords/edit.html.erb similarity index 100% rename from app/views/authors/passwords/edit.html.erb rename to app/views/users/passwords/edit.html.erb diff --git a/app/views/authors/passwords/new.html.erb b/app/views/users/passwords/new.html.erb similarity index 100% rename from app/views/authors/passwords/new.html.erb rename to app/views/users/passwords/new.html.erb diff --git a/app/views/authors/registrations/edit.html.erb b/app/views/users/registrations/edit.html.erb similarity index 100% rename from app/views/authors/registrations/edit.html.erb rename to app/views/users/registrations/edit.html.erb diff --git a/app/views/authors/registrations/new.html.erb b/app/views/users/registrations/new.html.erb similarity index 100% rename from app/views/authors/registrations/new.html.erb rename to app/views/users/registrations/new.html.erb diff --git a/app/views/authors/sessions/new.html.erb b/app/views/users/sessions/new.html.erb similarity index 100% rename from app/views/authors/sessions/new.html.erb rename to app/views/users/sessions/new.html.erb diff --git a/app/views/authors/shared/_links.erb b/app/views/users/shared/_links.erb similarity index 100% rename from app/views/authors/shared/_links.erb rename to app/views/users/shared/_links.erb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb new file mode 100644 index 00000000..464be429 --- /dev/null +++ b/app/views/users/show.html.erb @@ -0,0 +1,8 @@ +

<%= notice %>

+ +

+ name: + <%= h(@author.name) %> +

+ +<%= link_to 'Back', :controller => 'authors' %> diff --git a/app/views/authors/unlocks/new.html.erb b/app/views/users/unlocks/new.html.erb similarity index 100% rename from app/views/authors/unlocks/new.html.erb rename to app/views/users/unlocks/new.html.erb diff --git a/config/routes.rb b/config/routes.rb index 8a92433a..a06d818a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,23 @@ Pettanr::Application.routes.draw do + devise_for :users, :controllers => { :registrations => "user_registrations" } devise_for :admins - devise_for :authors, :controllers => { :registrations => "author_registrations" } match 'original_pictures/:id(.:format)/refresh' => 'original_pictures#refresh' + resources :authors do + collection do + get :index + get :show + post :create + get :list + get :browse + end + member do + put :update + delete :destroy + end + end resources :artists do collection do get :index diff --git a/db/migrate/20111206091950_create_authors.rb b/db/migrate/20111206091950_create_authors.rb new file mode 100644 index 00000000..c2dc72ff --- /dev/null +++ b/db/migrate/20111206091950_create_authors.rb @@ -0,0 +1,17 @@ +class CreateAuthors < ActiveRecord::Migration + def change + create_table(:authors) do |t| + t.string :name + t.integer :user_id, :null => false, :default => 0 + + t.timestamps + end + + add_index :authors, :email, :unique => true + add_index :authors, :reset_password_token, :unique => true + add_index :authors, :confirmation_token, :unique => true + # add_index :authors, :unlock_token, :unique => true + add_index :authors, :authentication_token, :unique => true + end + +end diff --git a/db/migrate/20111206113803_create_panel_pictures.rb b/db/migrate/20111206113803_create_panel_pictures.rb index 2011abbd..e05cbbfc 100644 --- a/db/migrate/20111206113803_create_panel_pictures.rb +++ b/db/migrate/20111206113803_create_panel_pictures.rb @@ -10,8 +10,6 @@ class CreatePanelPictures < ActiveRecord::Migration t.integer :t, :null => false, :default => 1 t.integer :width, :null => false t.integer :height, :null => false - t.integer :flipv, :null => false, :default => 0 - t.integer :fliph, :null => false, :default => 0 t.timestamps end diff --git a/db/migrate/20111206091950_devise_create_authors.rb b/db/migrate/20120306231650_devise_create_users.rb similarity index 85% rename from db/migrate/20111206091950_devise_create_authors.rb rename to db/migrate/20120306231650_devise_create_users.rb index 74b0f476..6372e999 100644 --- a/db/migrate/20111206091950_devise_create_authors.rb +++ b/db/migrate/20120306231650_devise_create_users.rb @@ -1,7 +1,6 @@ -class DeviseCreateAuthors < ActiveRecord::Migration +class DeviseCreateUsers < ActiveRecord::Migration def change - create_table(:authors) do |t| - t.string :name + create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 00000000..44032b48 --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe User do + pending "add some examples to (or delete) #{__FILE__}" +end -- 2.11.0