Module: MuckUsers::Models::MuckUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/muck-users/models/user.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #accepts_terms_of_service? ⇒ Boolean
- #activate! ⇒ Object
-
#active? ⇒ Boolean
Authlogic automatically executes the following methods.
- #add_exclude_fields(options = {}) ⇒ Object
-
#add_to_role(rolename) ⇒ Object
Add the user to a new role.
- #admin? ⇒ Boolean
- #any_role?(*test_rolenames) ⇒ Boolean
- #as_json(options = {}) ⇒ Object
- #can_edit?(user) ⇒ Boolean
- #deactivate! ⇒ Object
- #deliver_activation_confirmation! ⇒ Object
- #deliver_activation_instructions! ⇒ Object
- #deliver_password_reset_instructions! ⇒ Object
- #deliver_username_request! ⇒ Object
- #deliver_welcome_email ⇒ Object
- #display_name ⇒ Object
- #full_name ⇒ Object
-
#generate_password ⇒ Object
Build a random password.
- #has_role?(rolename) ⇒ Boolean
- #is_in_role?(object, roles) ⇒ Boolean
-
#lower_login ⇒ Object
lowercase all logins.
-
#reset_password!(user) ⇒ Object
Since password reset doesn’t need to change openid_identifier, we save without block as usual.
- #short_name ⇒ Object
- #to_xml(options = {}) ⇒ Object
Instance Method Details
#accepts_terms_of_service? ⇒ Boolean
225 226 227 228 229 |
# File 'lib/muck-users/models/user.rb', line 225 def accepts_terms_of_service? if !self.terms_of_service self.errors[:base] << I18n.translate('muck.users.terms_of_service_required') end end |
#activate! ⇒ Object
199 200 201 202 |
# File 'lib/muck-users/models/user.rb', line 199 def activate! self.activated_at = Time.now.utc self.save! end |
#active? ⇒ Boolean
Authlogic automatically executes the following methods
184 185 186 |
# File 'lib/muck-users/models/user.rb', line 184 def active? !activated_at.blank? end |
#add_exclude_fields(options = {}) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/muck-users/models/user.rb', line 162 def add_exclude_fields( = {}) ||= {} [:except] ||= [] [:except] << :crypted_password << :salt << :remember_token << :remember_token_expires_at << :activation_code [:except] << :activated_at << :password_reset_code << :enabled << :terms_of_service << :can_send_messages << :identity_url [:except] << :tmp_password << :protected_profile << :public_profile << :disabled_at << :current_login_ip << :access_code_id [:except] << :failed_login_count << :last_login_ip [:except] << :password_salt << :perishable_token << :persistence_token << :single_access_token end |
#add_to_role(rolename) ⇒ Object
Add the user to a new role
147 148 149 150 151 |
# File 'lib/muck-users/models/user.rb', line 147 def add_to_role(rolename) @role_names = nil role = Role.find_or_create_by_rolename(rolename) self.roles << role if !self.roles.include?(role) # Make sure that the user can only be put into a role once end |
#admin? ⇒ Boolean
153 154 155 |
# File 'lib/muck-users/models/user.rb', line 153 def admin? self.has_role?('administrator') end |
#any_role?(*test_rolenames) ⇒ Boolean
138 139 140 141 142 143 144 |
# File 'lib/muck-users/models/user.rb', line 138 def any_role?(*test_rolenames) test_rolenames = [test_rolenames] unless test_rolenames.is_a?(Array) test_rolenames.flatten! @role_names = self.roles.map(&:rolename) if @role_names.blank? return false if @role_names.blank? (@role_names & test_rolenames).length > 0 end |
#as_json(options = {}) ⇒ Object
178 179 180 181 |
# File 'lib/muck-users/models/user.rb', line 178 def as_json( = {}) = add_exclude_fields() super() end |
#can_edit?(user) ⇒ Boolean
157 158 159 160 |
# File 'lib/muck-users/models/user.rb', line 157 def can_edit?(user) return false if user.nil? self.id == user.id || user.admin? end |
#deactivate! ⇒ Object
204 205 206 207 |
# File 'lib/muck-users/models/user.rb', line 204 def deactivate! self.activated_at = nil self.save! end |
#deliver_activation_confirmation! ⇒ Object
94 95 96 97 |
# File 'lib/muck-users/models/user.rb', line 94 def deliver_activation_confirmation! reset_perishable_token! UserMailer.activation_confirmation(self).deliver end |
#deliver_activation_instructions! ⇒ Object
99 100 101 102 |
# File 'lib/muck-users/models/user.rb', line 99 def deliver_activation_instructions! reset_perishable_token! UserMailer.activation_instructions(self).deliver end |
#deliver_password_reset_instructions! ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/muck-users/models/user.rb', line 104 def deliver_password_reset_instructions! if self.active? reset_perishable_token! UserMailer.password_reset_instructions(self).deliver else UserMailer.password_not_active_instructions(self).deliver end end |
#deliver_username_request! ⇒ Object
113 114 115 |
# File 'lib/muck-users/models/user.rb', line 113 def deliver_username_request! UserMailer.username_request(self).deliver end |
#deliver_welcome_email ⇒ Object
90 91 92 |
# File 'lib/muck-users/models/user.rb', line 90 def deliver_welcome_email UserMailer.welcome_notification(self).deliver if MuckUsers.configuration.send_welcome end |
#display_name ⇒ Object
221 222 223 |
# File 'lib/muck-users/models/user.rb', line 221 def display_name CGI::escapeHTML(self.login) end |
#full_name ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/muck-users/models/user.rb', line 213 def full_name if self.first_name.blank? && self.last_name.blank? self.display_name rescue 'Deleted user' else ((CGI::escapeHTML(self.first_name) || '') + ' ' + (CGI::escapeHTML(self.last_name) || '')).strip end end |
#generate_password ⇒ Object
Build a random password
118 119 120 |
# File 'lib/muck-users/models/user.rb', line 118 def generate_password self.password = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{self.email}--#{self.id}") end |
#has_role?(rolename) ⇒ Boolean
134 135 136 |
# File 'lib/muck-users/models/user.rb', line 134 def has_role?(rolename) self.any_role?(rolename) end |
#is_in_role?(object, roles) ⇒ Boolean
130 131 132 |
# File 'lib/muck-users/models/user.rb', line 130 def is_in_role?(object, roles) raise 'not implemented' end |
#lower_login ⇒ Object
lowercase all logins
195 196 197 |
# File 'lib/muck-users/models/user.rb', line 195 def lower_login self.login = self.login.nil? ? nil : self.login.downcase end |
#reset_password!(user) ⇒ Object
Since password reset doesn’t need to change openid_identifier, we save without block as usual.
124 125 126 127 128 |
# File 'lib/muck-users/models/user.rb', line 124 def reset_password!(user) self.password = user[:password] self.password_confirmation = user[:password_confirmation] save end |
#short_name ⇒ Object
209 210 211 |
# File 'lib/muck-users/models/user.rb', line 209 def short_name CGI::escapeHTML(self.first_name) || self.display_name end |
#to_xml(options = {}) ⇒ Object
173 174 175 176 |
# File 'lib/muck-users/models/user.rb', line 173 def to_xml( = {}) = add_exclude_fields() super() end |