Remove email from Devise users and use nickname as primary key
This commit is contained in:
parent
bb234d7463
commit
da12b71938
10 changed files with 80 additions and 108 deletions
|
@ -19,7 +19,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def configure_permitted_parameters
|
def configure_permitted_parameters
|
||||||
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
|
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
|
||||||
:email, :nickname, :name, :last_name, :password, :password_confirmation
|
:nickname, :name, :last_name, :password, :password_confirmation
|
||||||
) }
|
) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,32 +9,25 @@
|
||||||
# nickname :string(255)
|
# nickname :string(255)
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# email :string(255) default(""), not null
|
|
||||||
# encrypted_password :string(255) default(""), not null
|
# encrypted_password :string(255) default(""), not null
|
||||||
# reset_password_token :string(255)
|
|
||||||
# reset_password_sent_at :datetime
|
|
||||||
# remember_created_at :datetime
|
# remember_created_at :datetime
|
||||||
# sign_in_count :integer default(0), not null
|
# sign_in_count :integer default(0), not null
|
||||||
# current_sign_in_at :datetime
|
# current_sign_in_at :datetime
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# confirmation_token :string(255)
|
|
||||||
# confirmed_at :datetime
|
|
||||||
# confirmation_sent_at :datetime
|
|
||||||
# unconfirmed_email :string(255)
|
|
||||||
#
|
#
|
||||||
|
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
devise :database_authenticatable, :registerable,
|
devise :database_authenticatable, :registerable,
|
||||||
:recoverable, :rememberable, :trackable, :validatable,
|
:rememberable, :trackable
|
||||||
:confirmable
|
|
||||||
|
|
||||||
has_many :orders, -> { includes :products }
|
has_many :orders, -> { includes :products }
|
||||||
|
|
||||||
|
validates :nickname, presence: true, uniqueness: true
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :last_name, presence: true
|
validates :last_name, presence: true
|
||||||
validates :nickname, presence: true, uniqueness: true
|
validates :password, length: { in: 8..128 }, confirmation: true
|
||||||
|
|
||||||
def full_name
|
def full_name
|
||||||
"#{name} #{last_name}"
|
"#{name} #{last_name}"
|
||||||
|
|
|
@ -3,29 +3,18 @@
|
||||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
|
||||||
<%= devise_error_messages! %>
|
<%= devise_error_messages! %>
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<%= f.label :email %><br />
|
|
||||||
<%= f.email_field :email, autofocus: true %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
|
||||||
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="field">
|
<%= form_text_field f, :nickname %>
|
||||||
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
|
<%= form_text_field f, :name %>
|
||||||
<%= f.password_field :password, autocomplete: "off" %>
|
<%= form_text_field f, :last_name %>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
|
||||||
<%= f.label :password_confirmation %><br />
|
|
||||||
<%= f.password_field :password_confirmation, autocomplete: "off" %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
<%= form_password_field f, :password %>
|
||||||
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
|
<%= form_password_field f, :password_confirmation %>
|
||||||
<%= f.password_field :current_password, autocomplete: "off" %>
|
<%= form_password_field f, :current_password %>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<%= f.submit "Update" %>
|
<%= f.submit "Update" %>
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
|
||||||
<%= devise_error_messages! %>
|
<%= devise_error_messages! %>
|
||||||
|
|
||||||
<%= form_email_field f, :email %>
|
|
||||||
<%= form_text_field f, :nickname %>
|
<%= form_text_field f, :nickname %>
|
||||||
<%= form_text_field f, :name %>
|
<%= form_text_field f, :name %>
|
||||||
<%= form_text_field f, :last_name %>
|
<%= form_text_field f, :last_name %>
|
||||||
|
|
|
@ -2,10 +2,7 @@
|
||||||
<%= render partial: 'flash' %>
|
<%= render partial: 'flash' %>
|
||||||
|
|
||||||
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
|
||||||
<div class="field">
|
<%= form_text_field f, :nickname %>
|
||||||
<%= f.label :email %><br />
|
|
||||||
<%= f.email_field :email, autofocus: true %>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<%= f.label :password %><br />
|
<%= f.label :password %><br />
|
||||||
|
|
|
@ -29,7 +29,7 @@ Devise.setup do |config|
|
||||||
# session. If you need permissions, you should implement that in a before filter.
|
# session. If you need permissions, you should implement that in a before filter.
|
||||||
# You can also supply a hash where the value is a boolean determining whether
|
# You can also supply a hash where the value is a boolean determining whether
|
||||||
# or not authentication should be aborted when the value is not present.
|
# or not authentication should be aborted when the value is not present.
|
||||||
# config.authentication_keys = [ :email ]
|
config.authentication_keys = [ :nickname ]
|
||||||
|
|
||||||
# Configure parameters from the request object used for authentication. Each entry
|
# Configure parameters from the request object used for authentication. Each entry
|
||||||
# given should be a request method and it will automatically be passed to the
|
# given should be a request method and it will automatically be passed to the
|
||||||
|
@ -41,12 +41,12 @@ Devise.setup do |config|
|
||||||
# Configure which authentication keys should be case-insensitive.
|
# Configure which authentication keys should be case-insensitive.
|
||||||
# These keys will be downcased upon creating or modifying a user and when used
|
# These keys will be downcased upon creating or modifying a user and when used
|
||||||
# to authenticate or find a user. Default is :email.
|
# to authenticate or find a user. Default is :email.
|
||||||
config.case_insensitive_keys = [ :email ]
|
config.case_insensitive_keys = [ ]
|
||||||
|
|
||||||
# Configure which authentication keys should have whitespace stripped.
|
# Configure which authentication keys should have whitespace stripped.
|
||||||
# These keys will have whitespace before and after removed upon creating or
|
# These keys will have whitespace before and after removed upon creating or
|
||||||
# modifying a user and when used to authenticate or find a user. Default is :email.
|
# modifying a user and when used to authenticate or find a user. Default is :email.
|
||||||
config.strip_whitespace_keys = [ :email ]
|
config.strip_whitespace_keys = [ ]
|
||||||
|
|
||||||
# Tell if authentication through request.params is enabled. True by default.
|
# Tell if authentication through request.params is enabled. True by default.
|
||||||
# It can be set to an array that will enable params authentication only for the
|
# It can be set to an array that will enable params authentication only for the
|
||||||
|
@ -119,7 +119,7 @@ Devise.setup do |config|
|
||||||
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
# initial account confirmation) to be applied. Requires additional unconfirmed_email
|
||||||
# db field (see migrations). Until confirmed, new email is stored in
|
# db field (see migrations). Until confirmed, new email is stored in
|
||||||
# unconfirmed_email column, and copied to email column on successful confirmation.
|
# unconfirmed_email column, and copied to email column on successful confirmation.
|
||||||
config.reconfirmable = true
|
# config.reconfirmable = true
|
||||||
|
|
||||||
# Defines which key will be used when confirming an account
|
# Defines which key will be used when confirming an account
|
||||||
# config.confirmation_keys = [ :email ]
|
# config.confirmation_keys = [ :email ]
|
||||||
|
|
19
db/migrate/20141209172818_remove_email_from_devise_users.rb
Normal file
19
db/migrate/20141209172818_remove_email_from_devise_users.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
class RemoveEmailFromDeviseUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_index :users, :confirmation_token
|
||||||
|
remove_index :users, :email
|
||||||
|
remove_index :users, :reset_password_token
|
||||||
|
|
||||||
|
change_table(:users) do |t|
|
||||||
|
t.remove :email
|
||||||
|
|
||||||
|
t.remove :reset_password_token
|
||||||
|
t.remove :reset_password_sent_at
|
||||||
|
|
||||||
|
t.remove :confirmation_token
|
||||||
|
t.remove :confirmed_at
|
||||||
|
t.remove :confirmation_sent_at
|
||||||
|
t.remove :unconfirmed_email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20141209144521) do
|
ActiveRecord::Schema.define(version: 20141209172818) do
|
||||||
|
|
||||||
create_table "order_products", force: true do |t|
|
create_table "order_products", force: true do |t|
|
||||||
t.integer "order_id"
|
t.integer "order_id"
|
||||||
|
@ -47,24 +47,13 @@ ActiveRecord::Schema.define(version: 20141209144521) do
|
||||||
t.string "nickname"
|
t.string "nickname"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "email", default: "", null: false
|
|
||||||
t.string "encrypted_password", default: "", null: false
|
t.string "encrypted_password", default: "", null: false
|
||||||
t.string "reset_password_token"
|
|
||||||
t.datetime "reset_password_sent_at"
|
|
||||||
t.datetime "remember_created_at"
|
t.datetime "remember_created_at"
|
||||||
t.integer "sign_in_count", default: 0, null: false
|
t.integer "sign_in_count", default: 0, null: false
|
||||||
t.datetime "current_sign_in_at"
|
t.datetime "current_sign_in_at"
|
||||||
t.datetime "last_sign_in_at"
|
t.datetime "last_sign_in_at"
|
||||||
t.string "current_sign_in_ip"
|
t.string "current_sign_in_ip"
|
||||||
t.string "last_sign_in_ip"
|
t.string "last_sign_in_ip"
|
||||||
t.string "confirmation_token"
|
|
||||||
t.datetime "confirmed_at"
|
|
||||||
t.datetime "confirmation_sent_at"
|
|
||||||
t.string "unconfirmed_email"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
|
|
||||||
add_index "users", ["email"], name: "index_users_on_email", unique: true
|
|
||||||
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
7
test/fixtures/users.yml
vendored
7
test/fixtures/users.yml
vendored
|
@ -9,20 +9,13 @@
|
||||||
# nickname :string(255)
|
# nickname :string(255)
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# email :string(255) default(""), not null
|
|
||||||
# encrypted_password :string(255) default(""), not null
|
# encrypted_password :string(255) default(""), not null
|
||||||
# reset_password_token :string(255)
|
|
||||||
# reset_password_sent_at :datetime
|
|
||||||
# remember_created_at :datetime
|
# remember_created_at :datetime
|
||||||
# sign_in_count :integer default(0), not null
|
# sign_in_count :integer default(0), not null
|
||||||
# current_sign_in_at :datetime
|
# current_sign_in_at :datetime
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# confirmation_token :string(255)
|
|
||||||
# confirmed_at :datetime
|
|
||||||
# confirmation_sent_at :datetime
|
|
||||||
# unconfirmed_email :string(255)
|
|
||||||
#
|
#
|
||||||
|
|
||||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
|
@ -9,20 +9,13 @@
|
||||||
# nickname :string(255)
|
# nickname :string(255)
|
||||||
# created_at :datetime
|
# created_at :datetime
|
||||||
# updated_at :datetime
|
# updated_at :datetime
|
||||||
# email :string(255) default(""), not null
|
|
||||||
# encrypted_password :string(255) default(""), not null
|
# encrypted_password :string(255) default(""), not null
|
||||||
# reset_password_token :string(255)
|
|
||||||
# reset_password_sent_at :datetime
|
|
||||||
# remember_created_at :datetime
|
# remember_created_at :datetime
|
||||||
# sign_in_count :integer default(0), not null
|
# sign_in_count :integer default(0), not null
|
||||||
# current_sign_in_at :datetime
|
# current_sign_in_at :datetime
|
||||||
# last_sign_in_at :datetime
|
# last_sign_in_at :datetime
|
||||||
# current_sign_in_ip :string(255)
|
# current_sign_in_ip :string(255)
|
||||||
# last_sign_in_ip :string(255)
|
# last_sign_in_ip :string(255)
|
||||||
# confirmation_token :string(255)
|
|
||||||
# confirmed_at :datetime
|
|
||||||
# confirmation_sent_at :datetime
|
|
||||||
# unconfirmed_email :string(255)
|
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
Loading…
Reference in a new issue