Class User
In: app/models/user.rb
Parent: ActiveRecord::Base

Methods

Attributes

password_confirmation  [RW] 

Public Class methods

[Source]

     # File app/models/user.rb, line 137
137:   def self.authenticate(email, password)
138:     user = self.find_by_email(email)
139:     if user && user.is_activated
140:       expected_password = User.encrypted_password(password, user.salt)
141:       if user.hashed_password != expected_password
142:         user = nil
143:       end
144:     else
145:       user = nil
146:     end
147:     user
148:   end

[Source]

     # File app/models/user.rb, line 123
123:   def self.exists?(email)
124:     user = self.find_by_email(email)
125:     return user ? true : false
126:   end

[Source]

     # File app/models/user.rb, line 128
128:   def self.is_activated?(email)
129:     user = self.find_by_email(email)
130:     if user
131:       return user.is_activated      
132:     else
133:       return false
134:     end
135:   end

Public Instance methods

[Source]

     # File app/models/user.rb, line 155
155:   def activate(activation)
156:     if self.activation == activation
157:       self.is_activated = true
158:       self.save!
159:     end
160:   end

[Source]

     # File app/models/user.rb, line 162
162:   def confirm?(confirmation)
163:     self.activation == confirmation
164:   end

[Source]

     # File app/models/user.rb, line 150
150:   def deactivate
151:     self.is_activated = false
152:     self.save!
153:   end

[Source]

    # File app/models/user.rb, line 47
47:   def get_preference(entity_attribute, attribute = nil)
48:     unless attribute
49:       split = entity_attribute.split(/_/)
50:       attribute        = split[1]
51:       entity_attribute = split[0]
52:     end
53:     user_preference = UserPreference.find_by_user_id_and_entity_and_attribute(self,entity_attribute,attribute)
54:     unless user_preference
55:       user_preference = UserPreference.create_for_user(self,entity_attribute,attribute)  
56:     end
57:     user_preference.value
58:   end

[Source]

    # File app/models/user.rb, line 85
85:   def language_dictionary(value = nil)
86:     unless value
87:       return get_preference('language_dictionary')
88:     else
89:       set_preference('language_dictionary', value.to_s)
90:     end
91:   end

[Source]

    # File app/models/user.rb, line 77
77:   def language_native(value = nil)
78:     unless value
79:       return get_preference('language_native')
80:     else
81:       set_preference('language_native', value.to_s)
82:     end
83:   end

[Source]

    # File app/models/user.rb, line 93
93:   def language_target(value = nil)
94:     unless value
95:       return get_preference('language_target')
96:     else
97:       set_preference('language_target', value.to_s)
98:     end
99:   end

[Source]

    # File app/models/user.rb, line 43
43:   def password
44:     @password || ( self.hashed_password ? 'hashed_password' : nil)
45:   end

[Source]

     # File app/models/user.rb, line 101
101:   def password=(a_password)
102:     @password = a_password
103:     return if a_password.blank?
104:     create_new_salt
105:     self.hashed_password = User.encrypted_password(self.password, self.salt)
106:   end

[Source]

     # File app/models/user.rb, line 173
173:   def reset_activation (is_activated = false)
174:     self.activation = generate_activation
175:     self.is_activated = is_activated
176:     self.save!
177:   end

[Source]

     # File app/models/user.rb, line 166
166:   def reset_password
167:     new_password = generate_password
168:     self.password = new_password
169:     self.save!
170:     return new_password
171:   end

[Source]

    # File app/models/user.rb, line 60
60:   def set_preference(entity_attribute, attribute = nil, value = nil)
61:     unless value
62:       value = attribute
63:       split = entity_attribute.split(/_/)
64:       attribute        = split[1]
65:       entity_attribute = split[0]
66:     end
67:     user_preference = UserPreference.find_by_user_id_and_entity_and_attribute(self,entity_attribute,attribute)
68:     unless user_preference
69:       user_preference = UserPreference.create_for_user(self,entity_attribute,attribute)  
70:     end
71:     if value
72:       user_preference.value = value
73:       user_preference.save!
74:     end
75:   end

[Source]

     # File app/models/user.rb, line 179
179:   def to_label
180:     label = ''
181:     if first_name and not first_name.blank? and last_name and not last_name.blank?
182:       label = "#{last_name}, #{first_name}"
183:     elsif (last_name.nil? or last_name.blank?) and first_name
184:       label = first_name
185:     elsif  last_name and (first_name.nil? or first_name.blank?)
186:       label = last_name
187:     else
188:       label = I18n.t('activerecord.attributes.user.unknown')
189:     end
190:     return label
191:   end

[Source]

     # File app/models/user.rb, line 108
108:   def update_password(current_password, new_password, confirm_password)
109:     exists = current_password && new_password && confirm_password
110:     new_identical = new_password == confirm_password
111:     current_password_hash = User.encrypted_password(current_password, self.salt)
112:     current_matches = self.hashed_password == current_password_hash
113: 
114:     has_length = exists && new_password.length >= 0
115:     if exists && new_identical && has_length && current_matches
116:       self.password=(new_password)
117:       self.save!
118:       return true
119:     end
120:     return false
121:   end

[Source]

    # File app/models/user.rb, line 39
39:   def validate
40:       errors.add_to_base("Missing password") if hashed_password.blank?
41:   end

Protected Instance methods

[Source]

     # File app/models/user.rb, line 207
207:   def authorized_for_create?
208:     false
209:   end

[Source]

     # File app/models/user.rb, line 215
215:   def authorized_for_destroy?
216:     return self == current_user ? true : Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ROOT)
217:   end

[Source]

     # File app/models/user.rb, line 203
203:   def authorized_for_read?
204:     true
205:   end

[Source]

     # File app/models/user.rb, line 211
211:    def authorized_for_update?
212:     return self == current_user ? true : Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ROOT)
213:   end

[Source]

     # File app/models/user.rb, line 199
199:   def email_authorized?
200:     Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ROOT)
201:   end

[Source]

     # File app/models/user.rb, line 195
195:   def user_role_authorized?
196:     Authorize.is_role_allowed_for_user?(current_user, UserRole::USER_ROLE_ROOT)
197:   end

[Validate]