Class: UsersController
Instance Method Summary
collapse
#advertise, #cache_action?, #css_help, #footer_content, #homepage_features, #plaxo, #rss_site_index, #site_index
#get_matching_ui_locale, #get_sorted_langs_from_accept_header, #get_valid_lang_from_accept_header, #set_locale
#login_by_token, #update_last_seen_at
Instance Method Details
#activate ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'app/controllers/users_controller.rb', line 27
def activate
redirect_to signup_path and return if params[:id].blank?
@user = User.find_by_activation_code(params[:id])
if @user and @user.activate
self.current_user = @user
@user.track_activity(:joined_the_site)
flash[:notice] = :thanks_for_activating_your_account.l
redirect_to welcome_photo_user_path(@user) and return
end
flash[:error] = :account_activation_error.l_with_args(:email => configatron.support_email)
redirect_to signup_path
end
|
#assume ⇒ Object
311
312
313
314
315
316
317
318
319
|
# File 'app/controllers/users_controller.rb', line 311
def assume
user = User.find(params[:id])
if assumed_user_session = self.assume_user(user)
redirect_to user_path(assumed_user_session.record)
else
redirect_to users_path
end
end
|
#change_profile_photo ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'app/controllers/users_controller.rb', line 150
def change_profile_photo
@user = User.find(params[:id])
@photo = Photo.find(params[:photo_id])
@user.avatar = @photo
if @user.save!
flash[:notice] = :your_changes_were_saved.l
redirect_to user_photo_path(@user, @photo)
end
rescue ActiveRecord::RecordInvalid
@metro_areas, @states = setup_locations_for(@user)
render :action => 'edit'
end
|
#create ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'app/controllers/users_controller.rb', line 91
def create
@user = User.new(params[:user])
@user.role = Role[:member]
if (!configatron.require_captcha_on_signup || verify_recaptcha(@user)) && @user.save
create_friendship_with_inviter(@user, params)
flash[:notice] = :email_signup_thanks.l_with_args(:email => @user.email)
redirect_to signup_completed_user_path(@user)
else
render :action => 'new'
end
end
|
#create_friendship_with_inviter(user, options = {}) ⇒ Object
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'app/controllers/users_controller.rb', line 233
def create_friendship_with_inviter(user, options = {})
unless options[:inviter_code].blank? or options[:inviter_id].blank?
friend = User.find(options[:inviter_id])
if friend && friend.valid_invite_code?(options[:inviter_code])
accepted = FriendshipStatus[:accepted]
@friendship = Friendship.new(:user_id => friend.id,
:friend_id => user.id,
:friendship_status => accepted,
:initiator => true)
reverse_friendship = Friendship.new(:user_id => user.id,
:friend_id => friend.id,
:friendship_status => accepted )
@friendship.save!
reverse_friendship.save!
end
end
end
|
#crop_profile_photo ⇒ Object
164
165
166
167
168
169
170
171
172
173
|
# File 'app/controllers/users_controller.rb', line 164
def crop_profile_photo
unless @photo = @user.avatar
flash[:notice] = :no_profile_photo.l
redirect_to upload_profile_photo_user_path(@user) and return
end
return unless request.put?
@photo.update_attributes(:crop_x => params[:crop_x], :crop_y => params[:crop_y], :crop_w => params[:crop_w], :crop_h => params[:crop_h])
redirect_to user_path(@user)
end
|
#dashboard ⇒ Object
60
61
62
63
64
|
# File 'app/controllers/users_controller.rb', line 60
def dashboard
@user = current_user
@network_activity = @user.network_activity
@recommended_posts = @user.recommended_posts
end
|
#deactivate ⇒ Object
41
42
43
44
45
46
|
# File 'app/controllers/users_controller.rb', line 41
def deactivate
@user.deactivate
current_user_session.destroy if current_user_session
flash[:notice] = :deactivate_completed.l
redirect_to login_path
end
|
#delete_selected ⇒ Object
389
390
391
392
393
394
395
396
397
398
399
400
401
|
# File 'app/controllers/users_controller.rb', line 389
def delete_selected
if params[:delete]
params[:delete].each { |id|
user = User.find(id)
unless user.admin? || user.featured_writer?
user.spam! if params[:spam] && !configatron.akismet_key.nil?
user.destroy
end
}
end
flash[:notice] = :the_user_was_deleted.l
redirect_to admin_users_path
end
|
#destroy ⇒ Object
138
139
140
141
142
143
144
145
146
147
148
|
# File 'app/controllers/users_controller.rb', line 138
def destroy
unless @user.admin? || @user.featured_writer?
@user.destroy
flash[:notice] = :the_user_was_deleted.l
else
flash[:error] = :you_cant_delete_that_user.l
end
respond_to do |format|
format.html { redirect_to users_url }
end
end
|
#edit ⇒ Object
104
105
106
107
|
# File 'app/controllers/users_controller.rb', line 104
def edit
@metro_areas, @states = setup_locations_for(@user)
@avatar = (@user.avatar || @user.build_avatar)
end
|
#edit_account ⇒ Object
187
188
189
190
191
|
# File 'app/controllers/users_controller.rb', line 187
def edit_account
@user = current_user
@authorizations = current_user.authorizations
@is_current_user = true
end
|
#edit_pro_details ⇒ Object
210
211
212
|
# File 'app/controllers/users_controller.rb', line 210
def edit_pro_details
@user = User.find(params[:id])
end
|
#forgot_username ⇒ Object
282
283
284
285
286
287
288
289
290
291
292
|
# File 'app/controllers/users_controller.rb', line 282
def forgot_username
return unless request.post?
if @user = User.active.find_by_email(params[:email])
UserNotifier.forgot_username(@user).deliver
redirect_to login_url
flash[:info] = :your_username_was_emailed_to_you.l
else
flash[:error] = :sorry_we_dont_recognize_that_email_address.l
end
end
|
#index ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'app/controllers/users_controller.rb', line 48
def index
@users, @search, @metro_areas, @states = User.search_conditions_with_metros_and_states(params)
@users = @users.active.recent.includes(:tags).page(params[:page]).per(20)
@metro_areas, @states = User.find_country_and_state_from_search_params(params)
@tags = User.tag_counts :limit => 10
setup_metro_areas_for_cloud
end
|
#invite ⇒ Object
273
274
275
|
# File 'app/controllers/users_controller.rb', line 273
def invite
@user = User.find(params[:id])
end
|
#metro_area_update ⇒ Object
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
# File 'app/controllers/users_controller.rb', line 325
def metro_area_update
country = Country.find(params[:country_id]) unless params[:country_id].blank?
state = State.find(params[:state_id]) unless params[:state_id].blank?
states = country ? country.states : []
if states.any?
metro_areas = state ? state.metro_areas.order("name ASC").all : []
else
metro_areas = country ? country.metro_areas.order("name ASC").all : []
end
respond_to do |format|
format.js {
render :partial => 'shared/location_chooser', :locals => {
:states => states,
:metro_areas => metro_areas,
:selected_country => params[:country_id].to_i,
:selected_state => params[:state_id].to_i,
:selected_metro_area => nil,
:js => true }
}
end
end
|
#new ⇒ Object
85
86
87
88
89
|
# File 'app/controllers/users_controller.rb', line 85
def new
@user = User.new( {:birthday => Date.parse((Time.now - 25.years).to_s) }.merge(params[:user] || {}) )
@inviter_id = params[:id]
@inviter_code = params[:code]
end
|
#resend_activation ⇒ Object
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'app/controllers/users_controller.rb', line 294
def resend_activation
if params[:email]
@user = User.find_by_email(params[:email])
else
@user = User.find(params[:id])
end
if @user && !@user.active?
flash[:notice] = :activation_email_resent_message.l
UserNotifier.signup_notification(@user).deliver
redirect_to login_path and return
else
flash[:notice] = :activation_email_not_sent_message.l
end
end
|
#return_admin ⇒ Object
321
322
323
|
# File 'app/controllers/users_controller.rb', line 321
def return_admin
return_to_admin
end
|
#show ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/controllers/users_controller.rb', line 66
def show
@friend_count = @user.accepted_friendships.count
@accepted_friendships = @user.accepted_friendships.find(:all, :limit => 5).collect{|f| f.friend }
@pending_friendships_count = @user.pending_friendships.count()
= @user..find(:all, :limit => 10, :order => 'created_at DESC')
= .(@user)
= .(@user).limit(5)
@recent_posts = @user.posts.recent.find(:all, :limit => 2)
@clippings = @user.clippings.find(:all, :limit => 5)
@photos = @user.photos.find(:all, :limit => 5)
= .new(params[:comment])
@my_activity = Activity.recent.by_users([@user.id]).find(:all, :limit => 10)
update_view_count(@user) unless current_user && current_user.eql?(@user)
end
|
#signup_completed ⇒ Object
254
255
256
257
|
# File 'app/controllers/users_controller.rb', line 254
def signup_completed
@user = User.find(params[:id])
redirect_to home_path and return unless @user
end
|
#statistics ⇒ Object
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'app/controllers/users_controller.rb', line 363
def statistics
if params[:date]
date = Date.new(params[:date][:year].to_i, params[:date][:month].to_i)
@month = Time.parse(date.to_s)
else
@month = Date.today
end
start_date = @month.beginning_of_month
end_date = @month.end_of_month.end_of_day
@posts = @user.posts.find(:all,
:conditions => ['? <= published_at AND published_at <= ?', start_date, end_date])
@estimated_payment = @posts.sum do |p|
7
end
respond_to do |format|
format.html
format.xml {
render :xml => @posts.to_xml(:include => :category)
}
end
end
|
#toggle_featured ⇒ Object
350
351
352
353
354
|
# File 'app/controllers/users_controller.rb', line 350
def toggle_featured
@user = User.find(params[:id])
@user.toggle!(:featured_writer)
redirect_to user_path(@user)
end
|
#toggle_moderator ⇒ Object
356
357
358
359
360
361
|
# File 'app/controllers/users_controller.rb', line 356
def toggle_moderator
@user = User.find(params[:id])
@user.role = @user.moderator? ? Role[:member] : Role[:moderator]
@user.save!
redirect_to user_path(@user)
end
|
#update ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
# File 'app/controllers/users_controller.rb', line 109
def update
@metro_areas, @states = setup_locations_for(@user)
unless params[:metro_area_id].blank?
@user.metro_area = MetroArea.find(params[:metro_area_id])
@user.state = (@user.metro_area && @user.metro_area.state) ? @user.metro_area.state : nil
@user.country = @user.metro_area.country if (@user.metro_area && @user.metro_area.country)
else
@user.metro_area = @user.state = @user.country = nil
end
@user.tag_list = params[:tag_list] || ''
params[:user][:avatar_attributes].merge!(:user_id => @user.id) if params[:user] && params[:user][:avatar_attributes]
if @user.update_attributes(params[:user])
@user.track_activity(:updated_profile)
flash[:notice] = :your_changes_were_saved.l
unless params[:welcome]
redirect_to user_path(@user)
else
redirect_to :action => "welcome_#{params[:welcome]}", :id => @user
end
else
render :action => 'edit'
end
end
|
#update_account ⇒ Object
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
# File 'app/controllers/users_controller.rb', line 193
def update_account
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = :your_changes_were_saved.l
respond_to do |format|
format.html {redirect_to user_path(@user)}
format.js
end
else
respond_to do |format|
format.html {render :action => 'edit_account'}
format.js
end
end
end
|
#update_pro_details ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'app/controllers/users_controller.rb', line 214
def update_pro_details
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
respond_to do |format|
format.html {
flash[:notice] = :your_changes_were_saved.l
redirect_to edit_pro_details_user_path(@user)
}
format.js {
render :text => 'success'
}
end
end
rescue ActiveRecord::RecordInvalid
render :action => 'edit_pro_details'
end
|
#upload_profile_photo ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
|
# File 'app/controllers/users_controller.rb', line 175
def upload_profile_photo
@avatar = Photo.new(params[:avatar])
return unless request.put?
@avatar.user = @user
if @avatar.save
@user.avatar = @avatar
@user.save
redirect_to crop_profile_photo_user_path(@user)
end
end
|
#welcome_about ⇒ Object
264
265
266
267
|
# File 'app/controllers/users_controller.rb', line 264
def welcome_about
@user = User.find(params[:id])
@metro_areas, @states = setup_locations_for(@user)
end
|
#welcome_complete ⇒ Object
277
278
279
280
|
# File 'app/controllers/users_controller.rb', line 277
def welcome_complete
flash[:notice] = :walkthrough_complete.l_with_args(:site => configatron.)
redirect_to user_path
end
|
#welcome_invite ⇒ Object
269
270
271
|
# File 'app/controllers/users_controller.rb', line 269
def welcome_invite
@user = User.find(params[:id])
end
|
#welcome_photo ⇒ Object
259
260
261
262
|
# File 'app/controllers/users_controller.rb', line 259
def welcome_photo
@user = User.find(params[:id])
@avatar = (@user.avatar || @user.build_avatar)
end
|