Description:
sends mass emails
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r309:5760cdcf6707 - - 3 files changed: 63 inserted, 1 deleted

@@ -0,0 +1,19
1 + %h1 Send mass e-mails
2 +
3 + - form_tag :action => 'bulk_mail' do
4 + %b List recipients' login below; one per line.
5 + %br/
6 + = text_area_tag 'login_list', nil, :rows => 7, :cols => 80
7 + %br/
8 + %b Subject:
9 + = text_field_tag 'subject', '', :size => 60
10 + %br/
11 + %b Email body:
12 + %br/
13 + = text_area_tag 'email_body', nil, :rows => 11, :cols => 80
14 + %br/
15 +
16 + = submit_tag "Send mails", :confirm => 'Are you sure?'
17 +
18 + %hr/
19 + = link_to '[go back to index]', :action => 'index'
@@ -9,13 +9,16
9 render :action => 'list'
9 render :action => 'list'
10 end
10 end
11
11
12 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
12 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
13 verify :method => :post, :only => [ :destroy,
13 verify :method => :post, :only => [ :destroy,
14 :create, :create_from_list,
14 :create, :create_from_list,
15 - :update ],
15 + :update,
16 + :manage_contest,
17 + :bulk_mail
18 + ],
16 :redirect_to => { :action => :list }
19 :redirect_to => { :action => :list }
17
20
18 def list
21 def list
19 @user_count = User.count
22 @user_count = User.count
20 if params[:page] == 'all'
23 if params[:page] == 'all'
21 @users = User.all
24 @users = User.all
@@ -298,12 +301,51
298 admin_role = Role.find_by_name('admin')
301 admin_role = Role.find_by_name('admin')
299 user.roles.delete(admin_role)
302 user.roles.delete(admin_role)
300 flash[:notice] = 'User permission revoked'
303 flash[:notice] = 'User permission revoked'
301 redirect_to :action => 'admin'
304 redirect_to :action => 'admin'
302 end
305 end
303
306
307 + # mass mailing
308 +
309 + def mass_mailing
310 + end
311 +
312 + def bulk_mail
313 + lines = params[:login_list]
314 + if !lines or lines.blank?
315 + flash[:notice] = 'You entered an empty list.'
316 + redirect_to :action => 'mass_mailing' and return
317 + end
318 +
319 + subject = params[:subject]
320 + if !subject or subject.blank?
321 + flash[:notice] = 'You entered an empty mail subject.'
322 + redirect_to :action => 'mass_mailing' and return
323 + end
324 +
325 + body = params[:email_body]
326 + if !body or body.blank?
327 + flash[:notice] = 'You entered an empty mail body.'
328 + redirect_to :action => 'mass_mailing' and return
329 + end
330 +
331 + note = []
332 + users = []
333 + lines.split("\n").each do |line|
334 + user = User.find_by_login(line.chomp)
335 + if user
336 + send_mail(user.email, subject, body)
337 + note << user.login
338 + end
339 + end
340 +
341 + flash[:notice] = 'User(s) ' + note.join(', ') +
342 + ' were successfully modified. '
343 + redirect_to :action => 'mass_mailing'
344 + end
345 +
304 protected
346 protected
305
347
306 def random_password(length=5)
348 def random_password(length=5)
307 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
349 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
308 newpass = ""
350 newpass = ""
309 length.times { newpass << chars[rand(chars.size-1)] }
351 length.times { newpass << chars[rand(chars.size-1)] }
@@ -30,12 +30,13
30 <b>What else: </b>
30 <b>What else: </b>
31 <%= link_to '[New user]', :action => 'new' %>
31 <%= link_to '[New user]', :action => 'new' %>
32 <%= link_to '[New list of users]', :action => 'new_list' %>
32 <%= link_to '[New list of users]', :action => 'new_list' %>
33 <%= link_to '[View administrators]', :action => 'admin' %>
33 <%= link_to '[View administrators]', :action => 'admin' %>
34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
35 <%= link_to '[View active users]', :action => 'active' %>
35 <%= link_to '[View active users]', :action => 'active' %>
36 + <%= link_to '[Mass mailing]', :action => 'mass_mailing' %>
36 <% if Configuration.multicontests? %>
37 <% if Configuration.multicontests? %>
37 <br/><b>Multi-contest:</b>
38 <br/><b>Multi-contest:</b>
38 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
39 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
39 View users in:
40 View users in:
40 <% @contests.each do |contest| %>
41 <% @contests.each do |contest| %>
41 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
42 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
You need to be logged in to leave comments. Login now