mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add confirmable email to user model
This commit is contained in:
committed by
Rob Harrington
parent
99729457cc
commit
dbbc2ddb1c
@@ -19,10 +19,17 @@ Spree.user_class.class_eval do
|
||||
accepts_nested_attributes_for :ship_address
|
||||
|
||||
attr_accessible :enterprise_ids, :enterprise_roles_attributes, :enterprise_limit, :locale, :bill_address_attributes, :ship_address_attributes
|
||||
after_create :send_signup_confirmation
|
||||
|
||||
validate :limit_owned_enterprises
|
||||
|
||||
# We use the same options as Spree and add :confirmable
|
||||
devise :database_authenticatable, :token_authenticatable, :registerable, :recoverable,
|
||||
:rememberable, :trackable, :validatable, :confirmable, :encryptable,
|
||||
:reconfirmable => true, confirmation_keys: [ :id, :email ], :encryptor => 'authlogic_sha512'
|
||||
handle_asynchronously :send_confirmation_instructions
|
||||
# TODO: Later versions of devise have a dedicated after_confirmation callback, so use that
|
||||
after_update :welcome_after_confirm, if: lambda { confirmation_token_changed? && confirmation_token.nil? }
|
||||
|
||||
def known_users
|
||||
if admin?
|
||||
Spree::User.scoped
|
||||
@@ -46,6 +53,14 @@ Spree.user_class.class_eval do
|
||||
customers.find_by_enterprise_id(enterprise)
|
||||
end
|
||||
|
||||
def welcome_after_confirm
|
||||
# Send welcome email if we are confirming an user's email
|
||||
# Note: this callback only runs on email confirmation
|
||||
if confirmed? && unconfirmed_email.nil? && !unconfirmed_email_changed?
|
||||
send_signup_confirmation
|
||||
end
|
||||
end
|
||||
|
||||
def send_signup_confirmation
|
||||
Delayed::Job.enqueue ConfirmSignupJob.new(id)
|
||||
end
|
||||
|
||||
13
db/migrate/20170710145821_add_confirmable_to_user.rb
Normal file
13
db/migrate/20170710145821_add_confirmable_to_user.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
class AddConfirmableToUser < ActiveRecord::Migration
|
||||
def up
|
||||
add_column :spree_users, :confirmation_token, :string
|
||||
add_column :spree_users, :confirmed_at, :datetime
|
||||
add_column :spree_users, :confirmation_sent_at, :datetime
|
||||
add_column :spree_users, :unconfirmed_email, :string
|
||||
add_index :spree_users, :confirmation_token, :unique => true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_columns :spree_users, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email
|
||||
end
|
||||
end
|
||||
@@ -1004,8 +1004,13 @@ ActiveRecord::Schema.define(:version => 20170921065259) do
|
||||
t.string "api_key", :limit => 40
|
||||
t.integer "enterprise_limit", :default => 1, :null => false
|
||||
t.string "locale", :limit => 5
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at"
|
||||
t.datetime "confirmation_sent_at"
|
||||
t.string "unconfirmed_email"
|
||||
end
|
||||
|
||||
add_index "spree_users", ["confirmation_token"], :name => "index_spree_users_on_confirmation_token", :unique => true
|
||||
add_index "spree_users", ["email"], :name => "email_idx_unique", :unique => true
|
||||
add_index "spree_users", ["persistence_token"], :name => "index_users_on_persistence_token"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user