Class: User

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

Direct Known Subclasses

Administrator, Designer, Visitor

Constant Summary collapse

@@authorized_types =
[ 'Administrator', 'Designer', 'User' ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loginObject

When inheriting this can raise an exception on the new models



8
9
10
# File 'app/models/user.rb', line 8

def 
  @login
end

#new_class_nameObject

When inheriting this can raise an exception on the new models



8
9
10
# File 'app/models/user.rb', line 8

def new_class_name
  @new_class_name
end

Class Method Details

.find_for_authentication(conditions) ⇒ Object



66
67
68
69
# File 'app/models/user.rb', line 66

def find_for_authentication(conditions)
   = conditions.delete(:login)
  find(:first, :conditions => ["username = ? OR email = ?", , ])
end

.unprotected_attributesObject



58
59
60
# File 'app/models/user.rb', line 58

def unprotected_attributes
  @unprotected_attributes ||= [:name, :email, :username, :login, :password, :password_confirmation, :locale]
end

.unprotected_attributes=(array) ⇒ Object



62
63
64
# File 'app/models/user.rb', line 62

def unprotected_attributes=(array)
  @unprotected_attributes = array.map{|att| att.to_sym }
end

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


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

def admin?
  has_role?(:admin)
end

#authorized?Boolean

Returns:

  • (Boolean)


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

def authorized?
  @@authorized_types.include?(class_name)
end

#designer?Boolean

Returns:

  • (Boolean)


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

def designer?
  has_role?(:designer)
end

#has_role?(role) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_role?(role)
  class_name.downcase.to_sym == role.to_s.downcase.to_sym
end