Class: Spree::User

Inherits:
Base
  • Object
show all
Includes:
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)


22
23
24
# File 'app/models/spree/user.rb', line 22

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

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



30
31
32
33
34
35
36
37
# File 'app/models/spree/user.rb', line 30

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



55
56
57
58
59
# File 'app/models/spree/user.rb', line 55

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)


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

def admin?
  has_spree_role?('admin')
end

#resend_confirmation_instructions(current_store) ⇒ Object



39
40
41
42
43
# File 'app/models/spree/user.rb', line 39

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

#send_confirmation_instructions(current_store) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'app/models/spree/user.rb', line 45

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



61
62
63
64
65
66
# File 'app/models/spree/user.rb', line 61

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



68
69
70
# File 'app/models/spree/user.rb', line 68

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