Class: Spree::User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Core::UserBanners
Defined in:
app/models/spree/user.rb

Defined Under Namespace

Classes: DestroyWithOrdersError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.admin_created?Boolean

Returns:

  • (Boolean)


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

def self.admin_created?
  User.admin.count > 0
end

.anonymous!Object

Creates an anonymous user. An anonymous user is basically an auto-generated User account that is created for the customer behind the scenes and its completely transparently to the customer. All Orders must have a User so this is necessary when adding to the “cart” (which is really an order) and before the customer has a chance to provide an email or to register.



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

def self.anonymous!
  token = User.generate_token(:persistence_token)
  User.create(:email => "#{token}@example.net", :password => token, :password_confirmation => token, :persistence_token => token)
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/spree/user.rb', line 45

def anonymous?
  email.nil? || email =~ /@example.net$/
end

#has_role?(role_in_question) ⇒ Boolean

has_role? simply needs to return true or false whether a user has a role or not.

Returns:

  • (Boolean)


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

def has_role?(role_in_question)
  roles.any? { |role| role.name == role_in_question.to_s }
end

#last_incomplete_orderObject



54
55
56
# File 'app/models/spree/user.rb', line 54

def last_incomplete_order
  orders.incomplete.order("created_at desc").last
end

#send_reset_password_instructionsObject



49
50
51
52
# File 'app/models/spree/user.rb', line 49

def send_reset_password_instructions
  generate_reset_password_token!
  UserMailer.reset_password_instructions(self).deliver
end