Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Instance Attribute Summary collapse
-
#login ⇒ Object
Setup accessible (or protected) attributes for your model :login is a virtual attribute for authenticating by either username or email This is in addition to a real persisted field like ‘username’.
Class Method Summary collapse
-
.find_for_database_authentication(conditions) ⇒ Object
Find user by email or username.
Instance Method Summary collapse
- #add_role(title) ⇒ Object
- #authorized_plugins ⇒ Object
- #can_delete?(user_to_delete = self) ⇒ Boolean
- #has_role?(title) ⇒ Boolean
- #plugins=(plugin_names) ⇒ Object
Instance Attribute Details
#login ⇒ Object
Setup accessible (or protected) attributes for your model :login is a virtual attribute for authenticating by either username or email This is in addition to a real persisted field like ‘username’
15 16 17 |
# File 'app/models/user.rb', line 15 def login @login end |
Class Method Details
.find_for_database_authentication(conditions) ⇒ Object
Find user by email or username. github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign_in-using-their-username-or-email-address
23 24 25 26 |
# File 'app/models/user.rb', line 23 def find_for_database_authentication(conditions) value = conditions[authentication_keys.first] where(["username = :value OR email = :value", { :value => value }]).first end |
Instance Method Details
#add_role(title) ⇒ Object
50 51 52 53 |
# File 'app/models/user.rb', line 50 def add_role(title) raise ArgumentException, "Role should be the title of the role not a role object." if title.is_a?(Role) roles << Role[title] unless has_role?(title) end |
#authorized_plugins ⇒ Object
39 40 41 |
# File 'app/models/user.rb', line 39 def plugins.collect { |p| p.name } | Refinery::Plugins.always_allowed.names end |
#can_delete?(user_to_delete = self) ⇒ Boolean
43 44 45 46 47 48 |
# File 'app/models/user.rb', line 43 def can_delete?(user_to_delete = self) user_to_delete.persisted? and !user_to_delete.has_role?(:superuser) and Role[:refinery].users.count > 1 and id != user_to_delete.id end |
#has_role?(title) ⇒ Boolean
55 56 57 58 |
# File 'app/models/user.rb', line 55 def has_role?(title) raise ArgumentException, "Role should be the title of the role not a role object." if title.is_a?(Role) roles.any?{|r| r.title == title.to_s.camelize} end |
#plugins=(plugin_names) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'app/models/user.rb', line 29 def plugins=(plugin_names) if persisted? # don't add plugins when the user_id is nil. UserPlugin.delete_all(:user_id => id) plugin_names.each_with_index do |plugin_name, index| plugins.create(:name => plugin_name, :position => index) if plugin_name.is_a?(String) end end end |