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

Users are related to UserGroups and to PeerGroups.

Methods

Included Modules

HomePageModule UnixNameModule

Public Class methods

Returns the admin user.

[Source]

    # File app/models/user.rb, line 96
96:   def self.admin
97:     return GlobalConfig.admin_user
98:   end

Returns the anonymous user.

[Source]

    # File app/models/user.rb, line 90
90:   def self.anonymous
91:     return GlobalConfig.anonymous_user
92:   end

Sets the current prefsprofile to the default prefs-profile of the given user. Useful for resolving links.

[Source]

     # File app/models/user.rb, line 117
117:   def self.login(user = nil)
118:     user ||= User.admin
119:     PrefsProfile.current_prefs = user.default_prefs_profile
120:   end

Set‘s the given user‘s login-url to that of the admin-user so logging in can be tested and verified.

[Source]

     # File app/models/user.rb, line 125
125:   def self.swap_in_admin(user)
126:     admin = User.admin
127:     temp_adm_url = admin.openid_identifier
128:     # add 3 random characters
129:     admin.openid_identifier = user.openid_identifier + (1..3).collect {
130:         a = 'a'; (rand 25).times {a.next!}; a }.join
131:     user.openid_identifier = temp_adm_url
132:     admin.save
133:     user.save
134:   end

Reverses this

[Source]

     # File app/models/user.rb, line 138
138:   def self.swap_out_admin(user)
139:     admin = User.admin
140:     temp_adm_url = user.openid_identifier
141:     user.openid_identifier = admin.openid_identifier[0...-3]
142:     admin.openid_identifier = temp_adm_url
143:     user.save
144:     admin.save
145:   end

Returns UsedTags for the most prolific Users for the tag-cloud.

Arguments:

  • limit = the max amount of tags returned

[Source]

     # File app/models/user.rb, line 107
107:   def self.top_users(options = {})
108:     return User.find(:all, options.merge(
109:         :order => "created_logis_count DESC")).sort_by {|user| user.name}
110:   end

Public Instance methods

Returns true if this user is the Admin user.

[Source]

     # File app/models/user.rb, line 171
171:   def admin?
172:     return self == User.admin
173:   end

Returns true if this user is the Anonymous user.

[Source]

     # File app/models/user.rb, line 165
165:   def anonymous?
166:     return self == User.anonymous
167:   end

Allows us to create the prefs-profiles after the rest of the settings have been set during init_to_db of the GlobalConfig.

Public.

[Source]

     # File app/models/user.rb, line 241
241:   def continue_creating_prefs_profiles
242:     self.user_group_memberships.create(:user_group => UserGroup.public)
243:     self.peer_group_memberships.create(:peer_group => PeerGroup.public,
244:           :power => PeerGroupMembership.member_power)
245:     self.prefs_profiles.create(
246:         :name => self.home_page_tag.to_s,
247:         :user_group => self.personal_user_group,
248:         :default_peer_group => PeerGroup.public)
249:     self.default_prefs_profile = self.prefs_profiles.first
250:     self.prefs_profiles.create(:default_settings => true)
251:     # the personal prefs profile is default 
252:     self.save
253:   end

Delivers instructions for password reset

[Source]

     # File app/models/user.rb, line 185
185:   def deliver_password_reset_instructions!
186:     reset_perishable_token!
187:     Notifier.deliver_password_reset_instructions(self)
188:   end

Methods

[Source]

     # File app/models/user.rb, line 149
149:   def deliver_welcome!
150:     if GlobalConfig.done?
151:       Notifier.deliver_welcome(self)
152:     end
153:   end

Returns the link to the users homepage.

[Source]

     # File app/models/user.rb, line 177
177:   def home_page_link
178:     return self.home_page_link_for(Tag.user)
179:   end

For acts_as_authentic configuration

[Source]

     # File app/models/user.rb, line 194
194:   def openid_identifier_blank?
195:     openid_identifier.blank?
196:   end

Used for abstraction & use with cloud helper.

[Source]

     # File app/models/user.rb, line 159
159:   def use_count
160:     return self.created_logis_count
161:   end

Protected Instance methods

Makes sure the persistence token is not null.

[Source]

     # File app/models/user.rb, line 202
202:   def assert_persistence_token
203:     if self.persistence_token.nil? or self.persistence_token.empty?
204:       self.persistence_token = User.unique_token
205:     end
206:   end

Creates a home-page.

[Source]

     # File app/models/user.rb, line 258
258:   def create_home_page
259:     self.create_home_page_for(Tag.user, :creator => self,
260:         :user_group => self.personal_user_group,
261:         :title => t('m.user.home_title', :name => self.name),
262:         :body => '<p>' + t('m.user.home_body', :name => self.name) + '</p>',
263:         :kind => Const::Logi::KINDS[:user])
264:     return true
265:   end

Creates the personal UserGroup.

[Source]

     # File app/models/user.rb, line 216
216:   def create_personal_user_group
217:     user_group = UserGroup.new(:personal_user => self,
218:         :name => self.home_page_tag.to_s,
219:         :default_restriction => Const::Logi::EDIT)
220:     user_group.save!
221:     return true
222:   end

Creates the PrefsProfiles for the user.

[Source]

     # File app/models/user.rb, line 226
226:   def create_prefs_profiles
227:     if GlobalConfig.done_with_groups?
228:       self.continue_creating_prefs_profiles
229:     else
230:       self.default_prefs_profile_id = 1
231:     end
232:     return true
233:   end

Subscribes the user to the daily and weekly mailings

[Source]

     # File app/models/user.rb, line 269
269:   def create_subscriptions
270:     ll_s_w = LogLogSubscription.new(:user => self,
271:         :channel => "logis", :period => "weekly")
272:     ll_s_w.save
273:     ll_s_d = LogLogSubscription.new(:user => self,
274:         :channel => "for_" + self.unix_name, :period => "daily")
275:     ll_s_d.save
276:   end

Destroys the home of the user.

[Source]

     # File app/models/user.rb, line 297
297:   def destroy_home_pages
298:     self.destroy_home_pages_for(Tag.user)
299:     return true
300:   end

Logs creation to log.logilogi.org

[Source]

     # File app/models/user.rb, line 280
280:   def log_create_to_log_log
281:     if GlobalConfig.use_log_log
282:       m = LogLogMessage.new(
283:           :kind => "User",
284:           :channel_names => ['all','users',
285:               'by_' + self.unix_name].join(','),
286:           :title => 'Welcome: ' + self.name,
287:           :author => self,
288:           :text => self.name + ' created an account.',
289:           :url => GlobalConfig.site_url + "users/" +
290:               self.home_page_tag_string)
291:       m.save
292:     end
293:   end

Validates that it is to a different logi.

[Source]

     # File app/models/user.rb, line 333
333:   def name_not_reserved
334:     if self.name =~ Const::Tag::RESERVED_WORDS_RE
335:       errors.add(:name, t('m.user.error_reserved_word'))
336:     end
337:   end

Makes sure the openid is normalized.

[Source]

     # File app/models/user.rb, line 341
341:   def normalize_openid_identifier
342:     if !self.openid_identifier.blank?
343:       begin
344:         self.openid_identifier = OpenIdAuthentication.normalize_identifier(self.openid_identifier) 
345:       rescue OpenIdAuthentication::InvalidOpenId => e
346:         errors.add(:openid_identifier, e.message)
347:       end
348:     end
349:   end

Resets the user-, creator- and editor- roles this user had in links, logis and logi_versions to the anonymous user.

[Source]

     # File app/models/user.rb, line 305
305:   def reset_dependents
306:     # set users to anonymous in links
307:     self.links.each do |link|
308:       link.user = User.anonymous
309:       link.save
310:     end
311:     # and in Logis
312:     self.created_logis.each do |logi|
313:       logi.creator = User.anonymous
314:       logi.save
315:     end
316:     # and LogiVersions
317:     self.edited_logi_versions.each do |logi_version|
318:       logi_version.editor = User.anonymous
319:       logi_version.save
320:     end
321:     self.paths.each do |path|
322:       path.user = User.anonymous
323:       path.save
324:     end
325:     return true
326:   end

[Source]

     # File app/models/user.rb, line 208
208:   def set_blog_title
209:     if self.blog_title.nil?
210:       self.blog_title = t('m.user.blog_title')
211:     end
212:   end

[Validate]