Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add spam checking for user profiles

  • Loading branch information...
commit f1f6bbff30acda47ac62538788b8a9d503a05bee 1 parent 0b1311f
Bruno Bornsztein bborn authored
21 app/controllers/users_controller.rb
@@ -32,7 +32,7 @@ def require_invitation
32 32 :edit_pro_details, :update_pro_details,
33 33 :welcome_photo, :welcome_about, :welcome_invite, :deactivate,
34 34 :crop_profile_photo, :upload_profile_photo]
35   - before_filter :admin_required, :only => [:assume, :destroy, :featured, :toggle_featured, :toggle_moderator]
  35 + before_filter :admin_required, :only => [:assume, :destroy, :featured, :toggle_featured, :toggle_moderator, :delete_selected]
36 36 before_filter :admin_or_current_user_required, :only => [:statistics]
37 37
38 38 def activate
@@ -164,6 +164,9 @@ def update
164 164
165 165 def destroy
166 166 unless @user.admin? || @user.featured_writer?
  167 + if params[:spam] && AppConfig.akismet_key
  168 + @user.spam!
  169 + end
167 170 @user.destroy
168 171 flash[:notice] = :the_user_was_deleted.l
169 172 else
@@ -418,6 +421,22 @@ def statistics
418 421 }
419 422 end
420 423 end
  424 +
  425 + def delete_selected
  426 + if request.post?
  427 + if params[:delete]
  428 + params[:delete].each { |id|
  429 + user = User.find(id)
  430 + unless user.admin? || user.featured_writer?
  431 + user.spam! if params[:spam] && AppConfig.akismet_key
  432 + user.destroy
  433 + end
  434 + }
  435 + end
  436 + flash[:notice] = :the_user_was_deleted.l
  437 + redirect_to admin_users_path
  438 + end
  439 + end
421 440
422 441 protected
423 442 def setup_metro_areas_for_cloud
10 app/models/user.rb
... ... @@ -1,6 +1,9 @@
1 1 require 'digest/sha1'
2 2
3 3 class User < ActiveRecord::Base
  4 + include Rakismet::Model
  5 + rakismet_attrs :author => :login, :comment_type => 'registration', :content => :description, :user_ip => :last_login_ip, :author_email => :email
  6 +
4 7 has_many :albums
5 8
6 9 MALE = 'M'
@@ -43,6 +46,7 @@ class User < ActiveRecord::Base
43 46 validates_uniqueness_of :login_slug
44 47 validates_exclusion_of :login, :in => AppConfig.reserved_logins
45 48 validates_date :birthday, :before => 13.years.ago.to_date
  49 + validate :check_spam
46 50
47 51 #associations
48 52 has_enumerated :role
@@ -440,6 +444,12 @@ def unread_message_count
440 444 message_threads_as_recipient.count(:conditions => ["messages.recipient_id = ? AND messages.recipient_deleted = ? AND read_at IS NULL", self.id, false], :include => :message)
441 445 end
442 446
  447 + def check_spam
  448 + if AppConfig.akismet_key && self.spam?
  449 + self.errors.add_to_base(:user_spam_error.l)
  450 + end
  451 + end
  452 +
443 453 ## End Instance Methods
444 454
445 455
13 app/views/admin/comments.html.haml
@@ -49,8 +49,8 @@
49 49 %td
50 50 =link_to_remote(image_tag('icons/delete.png', :plugin => 'community_engine'), {:url => comment_path(comment.commentable_type, comment.commentable_id, comment), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "comment_#{comment.id}"), :confirm => "Are you sure you want to permanently delete this comment"} )
51 51 %td
52   - =link_to_remote(image_tag('icons/bad-flag.png', :plugin => 'community_engine'), {:url => comment_path(comment.commentable_type, comment.commentable_id, comment), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "comment_#{comment.id}"), :confirm => "Are you sure you want to permanently delete this comment and mark it as spam!?"} )
53   -
  52 + -if AppConfig.akismet_key
  53 + =link_to_remote(image_tag('icons/bad-flag.png', :plugin => 'community_engine'), {:url => comment_path(comment.commentable_type, comment.commentable_id, comment, :spam => true), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "comment_#{comment.id}"), :confirm => "Are you sure you want to permanently delete this comment and mark it as spam!?"} )
54 54 %td= check_box_tag "delete[]", comment.id
55 55 %td
56 56 .left
@@ -73,8 +73,13 @@
73 73 %td{ :colspan => "4" }
74 74 -if @comments.any?
75 75 %a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
76   - %p= submit_tag :delete_selected.l
77   - %p= submit_tag :delete_selected_mark_as_spam.l
  76 +
  77 + %p
  78 + -if AppConfig.akismet_key
  79 + = check_box_tag :spam
  80 + =:delete_selected_mark_as_spam.l
  81 + %br
  82 + = submit_tag :delete_selected.l
78 83
79 84
80 85 -if @comments.page_count > 1
65 app/views/admin/users.html.haml
... ... @@ -1,6 +1,7 @@
1 1 .yui-b.sidebar
2 2 = render :partial => 'shared/admin_nav'
3 3
  4 +
4 5 #yui-main
5 6 .yui-b
6 7 -box do
@@ -18,25 +19,53 @@
18 19 -if @users.page_count > 1
19 20 .pagination= paginating_links @users, :link_to_current_page => true
20 21
21   - %table{"cellspacing"=>"0", "border"=>"0", "cellpadding"=>"0", "width"=>"100%"}
22   - %tr
23   - %th=:login.l
24   - %th=:e_mail.l
25   - %th=:status.l
26   - %th=:actions.l
  22 + - form_tag delete_selected_users_path, :id => 'users' do
  23 + %table{"cellspacing"=>"0", "border"=>"0", "cellpadding"=>"0", "width"=>"100%"}
  24 + %thead
  25 + %tr
  26 + %th{:width => '60px', :colspan => '3'}
  27 + %th=:login.l
  28 + %th=:e_mail.l
  29 + %th=:status.l
  30 + %th=:actions.l
27 31
28   - - @users.each do |user|
29   - %tr{:id => "user_#{user.id}"}
30   - %td
31   - = link_to h(user.login), user_path(user)
32   - %td
33   - = h user.email
34   - %td
35   - = user.active? ? :active.l : :inactive.l
36   - %td
37   - = link_to( :assume_id.l , assume_user_path(user) )
38   - = (" | " + link_to(:activate.l, :controller => "/admin", :action => "activate_user", :id => user.id)) unless user.active?
39   - = link_to_remote(image_tag('icons/delete.png', :plugin => 'community_engine'), {:url => user_path(user), :method => :delete, :success => visual_effect(:fade, "user_#{user.id}"), :confirm => "Are you sure you want to permanently delete this user"} )
  32 + %tbody
  33 + - @users.each do |user|
  34 + %tr{:id => "user_#{user.id}"}
  35 + %td
  36 + = link_to_remote(image_tag('icons/delete.png', :plugin => 'community_engine'), {:url => user_path(user), :method => :delete, :success => visual_effect(:fade, "user_#{user.id}"), :confirm => "Are you sure you want to permanently delete this user"} )
  37 + %td
  38 + -if AppConfig.akismet_key
  39 + = link_to_remote(image_tag('icons/bad-flag.png', :plugin => 'community_engine'), {:url => user_path(user, :spam => true), :method => :delete, 500 => 'alert(\'Sorry, there was a server error\'); return false', :success => visual_effect(:fade, "user_#{user.id}"), :confirm => "Are you sure you want to permanently delete this user and mark it as spam!?"} )
  40 +
  41 + %td= check_box_tag "delete[]", user.id
  42 +
  43 + %td
  44 + = link_to h(user.login), user_path(user)
  45 + %td
  46 + = h user.email
  47 + %td
  48 + = user.active? ? :active.l : :inactive.l
  49 + %td
  50 + = link_to( :assume_id.l , assume_user_path(user) )
  51 + = (" | " + link_to(:activate.l, :controller => "/admin", :action => "activate_user", :id => user.id)) unless user.active?
  52 + %tfoot
  53 + %tr
  54 + %td{ :colspan => "4" }
  55 + -if @users.any?
  56 + %a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
  57 + %p
  58 + -if AppConfig.akismet_key
  59 + = check_box_tag :spam
  60 + =:delete_selected_mark_as_spam.l
  61 + %br
  62 + = submit_tag :delete_selected.l
40 63
  64 +
  65 +
41 66 -if @users.page_count > 1
42 67 .pagination= paginating_links @users, :link_to_current_page => true
  68 +
  69 +%script{:type => 'text/javascript'}
  70 + var form = $('users');
  71 + checkboxes = form.getInputs('checkbox');
1  config/desert_routes.rb
@@ -97,6 +97,7 @@
97 97 resources :favorites, :path_prefix => '/:favoritable_type/:favoritable_id'
98 98 resources :comments, :path_prefix => '/:commentable_type/:commentable_id'
99 99 delete_selected_comments 'comments/delete_selected', :controller => "comments", :action => 'delete_selected'
  100 +delete_selected_users 'users/delete_selected', :controller => "users", :action => 'delete_selected'
100 101
101 102 resources :homepage_features
102 103 resources :metro_areas
4 lang/ui/en.yml
@@ -356,7 +356,7 @@ en:
356 356 #en: delete_selected: Delete selected
357 357 delete_selected: Delete selected
358 358 #en: delete_selected_mark_as_spam: Delete selected and mark spam
359   - delete_selected_mark_as_spam: Delete selected and mark spam
  359 + delete_selected_mark_as_spam: Mark as spam
360 360 #en: delete_this_event: Delete this event
361 361 delete_this_event: Delete this event
362 362 #en: delete_this_forum: Delete this forum
@@ -1447,6 +1447,8 @@ en:
1447 1447 users_photos: "{{user}}'s Photos"
1448 1448 #en: users_profile: {{user}}'s profile
1449 1449 users_profile: "{{user}}'s profile"
  1450 + #en: user_spam_error: "User was flagged as spam. Please make sure you aren't including any spammy words or links and try again."
  1451 + user_spam_error: "User was flagged as spam. Make sure you don't include spammy words or links and try again"
1450 1452 #en: users_tagged: Users tagged
1451 1453 users_tagged: "Users tagged"
1452 1454 #en: user_vendor_offer: "<p>Describe the product or service you offer:<ul><li> Tell people what you do</li><li> Explain why you love your work</li><li> How can people contact you? What's your Web site?</li></ul></p>"

0 comments on commit f1f6bbf

Please sign in to comment.
Something went wrong with that request. Please try again.