Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
- .admin_created? ⇒ Boolean
-
.anonymous! ⇒ Object
Creates an anonymous user.
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #deliver_password_reset_instructions! ⇒ Object
-
#has_role?(role_in_question) ⇒ Boolean
has_role? simply needs to return true or false whether a user has a role or not.
Class Method Details
.admin_created? ⇒ 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
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.
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 |