Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add spam checking for user profiles

  • Loading branch information...
commit f1f6bbff30acda47ac62538788b8a9d503a05bee 1 parent 0b1311f
@bborn authored
View
21 app/controllers/users_controller.rb
@@ -32,7 +32,7 @@ def require_invitation
:edit_pro_details, :update_pro_details,
:welcome_photo, :welcome_about, :welcome_invite, :deactivate,
:crop_profile_photo, :upload_profile_photo]
- before_filter :admin_required, :only => [:assume, :destroy, :featured, :toggle_featured, :toggle_moderator]
+ before_filter :admin_required, :only => [:assume, :destroy, :featured, :toggle_featured, :toggle_moderator, :delete_selected]
before_filter :admin_or_current_user_required, :only => [:statistics]
def activate
@@ -164,6 +164,9 @@ def update
def destroy
unless @user.admin? || @user.featured_writer?
+ if params[:spam] && AppConfig.akismet_key
+ @user.spam!
+ end
@user.destroy
flash[:notice] = :the_user_was_deleted.l
else
@@ -418,6 +421,22 @@ def statistics
}
end
end
+
+ def delete_selected
+ if request.post?
+ if params[:delete]
+ params[:delete].each { |id|
+ user = User.find(id)
+ unless user.admin? || user.featured_writer?
+ user.spam! if params[:spam] && AppConfig.akismet_key
+ user.destroy
+ end
+ }
+ end
+ flash[:notice] = :the_user_was_deleted.l
+ redirect_to admin_users_path
+ end
+ end
protected
def setup_metro_areas_for_cloud
View
10 app/models/user.rb
@@ -1,6 +1,9 @@
require 'digest/sha1'
class User < ActiveRecord::Base
+ include Rakismet::Model
+ rakismet_attrs :author => :login, :comment_type => 'registration', :content => :description, :user_ip => :last_login_ip, :author_email => :email
+
has_many :albums
MALE = 'M'
@@ -43,6 +46,7 @@ class User < ActiveRecord::Base
validates_uniqueness_of :login_slug
validates_exclusion_of :login, :in => AppConfig.reserved_logins
validates_date :birthday, :before => 13.years.ago.to_date
+ validate :check_spam
#associations
has_enumerated :role
@@ -440,6 +444,12 @@ def unread_message_count
message_threads_as_recipient.count(:conditions => ["messages.recipient_id = ? AND messages.recipient_deleted = ? AND read_at IS NULL", self.id, false], :include => :message)
end
+ def check_spam
+ if AppConfig.akismet_key && self.spam?
+ self.errors.add_to_base(:user_spam_error.l)
+ end
+ end
+
## End Instance Methods
View
13 app/views/admin/comments.html.haml
@@ -49,8 +49,8 @@
%td
=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"} )
%td
- =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!?"} )
-
+ -if AppConfig.akismet_key
+ =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!?"} )
%td= check_box_tag "delete[]", comment.id
%td
.left
@@ -73,8 +73,13 @@
%td{ :colspan => "4" }
-if @comments.any?
%a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
- %p= submit_tag :delete_selected.l
- %p= submit_tag :delete_selected_mark_as_spam.l
+
+ %p
+ -if AppConfig.akismet_key
+ = check_box_tag :spam
+ =:delete_selected_mark_as_spam.l
+ %br
+ = submit_tag :delete_selected.l
-if @comments.page_count > 1
View
65 app/views/admin/users.html.haml
@@ -1,6 +1,7 @@
.yui-b.sidebar
= render :partial => 'shared/admin_nav'
+
#yui-main
.yui-b
-box do
@@ -18,25 +19,53 @@
-if @users.page_count > 1
.pagination= paginating_links @users, :link_to_current_page => true
- %table{"cellspacing"=>"0", "border"=>"0", "cellpadding"=>"0", "width"=>"100%"}
- %tr
- %th=:login.l
- %th=:e_mail.l
- %th=:status.l
- %th=:actions.l
+ - form_tag delete_selected_users_path, :id => 'users' do
+ %table{"cellspacing"=>"0", "border"=>"0", "cellpadding"=>"0", "width"=>"100%"}
+ %thead
+ %tr
+ %th{:width => '60px', :colspan => '3'}
+ %th=:login.l
+ %th=:e_mail.l
+ %th=:status.l
+ %th=:actions.l
- - @users.each do |user|
- %tr{:id => "user_#{user.id}"}
- %td
- = link_to h(user.login), user_path(user)
- %td
- = h user.email
- %td
- = user.active? ? :active.l : :inactive.l
- %td
- = link_to( :assume_id.l , assume_user_path(user) )
- = (" | " + link_to(:activate.l, :controller => "/admin", :action => "activate_user", :id => user.id)) unless user.active?
- = 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"} )
+ %tbody
+ - @users.each do |user|
+ %tr{:id => "user_#{user.id}"}
+ %td
+ = 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"} )
+ %td
+ -if AppConfig.akismet_key
+ = 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!?"} )
+
+ %td= check_box_tag "delete[]", user.id
+
+ %td
+ = link_to h(user.login), user_path(user)
+ %td
+ = h user.email
+ %td
+ = user.active? ? :active.l : :inactive.l
+ %td
+ = link_to( :assume_id.l , assume_user_path(user) )
+ = (" | " + link_to(:activate.l, :controller => "/admin", :action => "activate_user", :id => user.id)) unless user.active?
+ %tfoot
+ %tr
+ %td{ :colspan => "4" }
+ -if @users.any?
+ %a{:href=>"#", :onclick=>"checkboxes.each(function(e){ e.checked = (e.checked == 0 ? 1 : 0) }); return false;"} Toggle all
+ %p
+ -if AppConfig.akismet_key
+ = check_box_tag :spam
+ =:delete_selected_mark_as_spam.l
+ %br
+ = submit_tag :delete_selected.l
+
+
-if @users.page_count > 1
.pagination= paginating_links @users, :link_to_current_page => true
+
+%script{:type => 'text/javascript'}
+ var form = $('users');
+ checkboxes = form.getInputs('checkbox');
View
1  config/desert_routes.rb
@@ -97,6 +97,7 @@
resources :favorites, :path_prefix => '/:favoritable_type/:favoritable_id'
resources :comments, :path_prefix => '/:commentable_type/:commentable_id'
delete_selected_comments 'comments/delete_selected', :controller => "comments", :action => 'delete_selected'
+delete_selected_users 'users/delete_selected', :controller => "users", :action => 'delete_selected'
resources :homepage_features
resources :metro_areas
View
4 lang/ui/en.yml
@@ -356,7 +356,7 @@ en:
#en: delete_selected: Delete selected
delete_selected: Delete selected
#en: delete_selected_mark_as_spam: Delete selected and mark spam
- delete_selected_mark_as_spam: Delete selected and mark spam
+ delete_selected_mark_as_spam: Mark as spam
#en: delete_this_event: Delete this event
delete_this_event: Delete this event
#en: delete_this_forum: Delete this forum
@@ -1447,6 +1447,8 @@ en:
users_photos: "{{user}}'s Photos"
#en: users_profile: {{user}}'s profile
users_profile: "{{user}}'s profile"
+ #en: user_spam_error: "User was flagged as spam. Please make sure you aren't including any spammy words or links and try again."
+ user_spam_error: "User was flagged as spam. Make sure you don't include spammy words or links and try again"
#en: users_tagged: Users tagged
users_tagged: "Users tagged"
#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>"
Please sign in to comment.
Something went wrong with that request. Please try again.