Class: User

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.admin_created?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/models/user.rb', line 33

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.



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

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)


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

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

#deliver_password_reset_instructions!Object



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

def deliver_password_reset_instructions!
  reset_perishable_token!
  UserMailer.password_reset_instructions(self).deliver
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)


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

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