Class: Spree::User

Inherits:
Base
  • Object
show all
Includes:
Metadata, UserAddress, UserMethods, UserPaymentSource
Defined in:
app/models/spree/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.admin_created?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/spree/user.rb', line 25

def self.admin_created?
  User.admin.exists?
end

.send_confirmation_instructions(attributes = {}, current_store) ⇒ Object



33
34
35
36
37
38
39
40
# File 'app/models/spree/user.rb', line 33

def self.send_confirmation_instructions(attributes = {}, current_store)
  confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable
  unless confirmable.try(:persisted?)
    confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)
  end
  confirmable.resend_confirmation_instructions(current_store) if confirmable.persisted?
  confirmable
end

.send_reset_password_instructions(attributes = {}, current_store) ⇒ Object



58
59
60
61
62
# File 'app/models/spree/user.rb', line 58

def self.send_reset_password_instructions(attributes={}, current_store)
  recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
  recoverable.send_reset_password_instructions(current_store) if recoverable.persisted?
  recoverable
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/spree/user.rb', line 29

def admin?
  has_spree_role?('admin')
end

#resend_confirmation_instructions(current_store) ⇒ Object



42
43
44
45
46
# File 'app/models/spree/user.rb', line 42

def resend_confirmation_instructions(current_store)
  pending_any_confirmation do
    send_confirmation_instructions(current_store)
  end
end

#send_confirmation_instructions(current_store) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'app/models/spree/user.rb', line 48

def send_confirmation_instructions(current_store)
  unless @raw_confirmation_token
    generate_confirmation_token!
  end

  opts = pending_reconfirmation? ? { to: unconfirmed_email } : {}
  opts[:current_store_id] = current_store&.id || Spree::Store.default.id
  send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
end

#send_reset_password_instructions(current_store) ⇒ Object



64
65
66
67
68
69
# File 'app/models/spree/user.rb', line 64

def send_reset_password_instructions(current_store)
  token = set_reset_password_token
  send_reset_password_instructions_notification(token, current_store.id)

  token
end

#send_reset_password_instructions_notification(token, current_store_id) ⇒ Object



71
72
73
# File 'app/models/spree/user.rb', line 71

def send_reset_password_instructions_notification(token, current_store_id)
  send_devise_notification(:reset_password_instructions, token, { current_store_id: current_store_id })
end