# HG changeset patch # User Jittat Fakcharoenphol # Date 2010-05-10 22:08:46 # Node ID 5760cdcf670775a2c0b2e935f82fafeb364e23e8 # Parent c400f7405eeec6cb74b9d3d6583962e1886709d6 sends mass emails diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -12,7 +12,10 @@ # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :create_from_list, - :update ], + :update, + :manage_contest, + :bulk_mail + ], :redirect_to => { :action => :list } def list @@ -301,6 +304,45 @@ redirect_to :action => 'admin' end + # mass mailing + + def mass_mailing + end + + def bulk_mail + lines = params[:login_list] + if !lines or lines.blank? + flash[:notice] = 'You entered an empty list.' + redirect_to :action => 'mass_mailing' and return + end + + subject = params[:subject] + if !subject or subject.blank? + flash[:notice] = 'You entered an empty mail subject.' + redirect_to :action => 'mass_mailing' and return + end + + body = params[:email_body] + if !body or body.blank? + flash[:notice] = 'You entered an empty mail body.' + redirect_to :action => 'mass_mailing' and return + end + + note = [] + users = [] + lines.split("\n").each do |line| + user = User.find_by_login(line.chomp) + if user + send_mail(user.email, subject, body) + note << user.login + end + end + + flash[:notice] = 'User(s) ' + note.join(', ') + + ' were successfully modified. ' + redirect_to :action => 'mass_mailing' + end + protected def random_password(length=5) diff --git a/app/views/user_admin/list.rhtml b/app/views/user_admin/list.rhtml --- a/app/views/user_admin/list.rhtml +++ b/app/views/user_admin/list.rhtml @@ -33,6 +33,7 @@ <%= link_to '[View administrators]', :action => 'admin' %> <%= link_to '[Random passwords]', :action => 'random_all_passwords' %> <%= link_to '[View active users]', :action => 'active' %> + <%= link_to '[Mass mailing]', :action => 'mass_mailing' %> <% if Configuration.multicontests? %>
Multi-contest: <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %> diff --git a/app/views/user_admin/mass_mailing.html.haml b/app/views/user_admin/mass_mailing.html.haml new file mode 100644 --- /dev/null +++ b/app/views/user_admin/mass_mailing.html.haml @@ -0,0 +1,19 @@ +%h1 Send mass e-mails + +- form_tag :action => 'bulk_mail' do + %b List recipients' login below; one per line. + %br/ + = text_area_tag 'login_list', nil, :rows => 7, :cols => 80 + %br/ + %b Subject: + = text_field_tag 'subject', '', :size => 60 + %br/ + %b Email body: + %br/ + = text_area_tag 'email_body', nil, :rows => 11, :cols => 80 + %br/ + + = submit_tag "Send mails", :confirm => 'Are you sure?' + +%hr/ += link_to '[go back to index]', :action => 'index'