Description:
sends mails by mail gem
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r331:4917c2675f37 - - 4 files changed: 44 inserted, 25 deleted

@@ -16,35 +16,35
16 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
16 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
17 # gem 'therubyracer', :platforms => :ruby
17 # gem 'therubyracer', :platforms => :ruby
18
18
19 gem 'uglifier', '>= 1.0.3'
19 gem 'uglifier', '>= 1.0.3'
20 end
20 end
21
21
22 gem 'prototype-rails'
22 gem 'prototype-rails'
23
23
24 # To use ActiveModel has_secure_password
24 # To use ActiveModel has_secure_password
25 # gem 'bcrypt-ruby', '~> 3.0.0'
25 # gem 'bcrypt-ruby', '~> 3.0.0'
26
26
27 # To use Jbuilder templates for JSON
27 # To use Jbuilder templates for JSON
28 # gem 'jbuilder'
28 # gem 'jbuilder'
29
29
30 # Use unicorn as the app server
30 # Use unicorn as the app server
31 # gem 'unicorn'
31 # gem 'unicorn'
32
32
33 # Deploy with Capistrano
33 # Deploy with Capistrano
34 # gem 'capistrano'
34 # gem 'capistrano'
35
35
36 # To use debugger
36 # To use debugger
37 # gem 'debugger'
37 # gem 'debugger'
38
38
39 gem "haml"
39 gem "haml"
40 - gem "tmail"
40 + gem "mail"
41 gem "rdiscount"
41 gem "rdiscount"
42 gem "test-unit"
42 gem "test-unit"
43 gem 'will_paginate', '~> 3.0.0'
43 gem 'will_paginate', '~> 3.0.0'
44 gem 'dynamic_form'
44 gem 'dynamic_form'
45 gem 'in_place_editing'
45 gem 'in_place_editing'
46 gem 'verification', :git => 'git://github.com/sikachu/verification.git'
46 gem 'verification', :git => 'git://github.com/sikachu/verification.git'
47
47
48 group :test, :development do
48 group :test, :development do
49 gem "rspec-rails", "~> 2.0"
49 gem "rspec-rails", "~> 2.0"
50 end
50 end
@@ -96,53 +96,52
96 rspec-core (~> 2.11.0)
96 rspec-core (~> 2.11.0)
97 rspec-expectations (~> 2.11.0)
97 rspec-expectations (~> 2.11.0)
98 rspec-mocks (~> 2.11.0)
98 rspec-mocks (~> 2.11.0)
99 rspec-core (2.11.1)
99 rspec-core (2.11.1)
100 rspec-expectations (2.11.3)
100 rspec-expectations (2.11.3)
101 diff-lcs (~> 1.1.3)
101 diff-lcs (~> 1.1.3)
102 rspec-mocks (2.11.3)
102 rspec-mocks (2.11.3)
103 rspec-rails (2.11.0)
103 rspec-rails (2.11.0)
104 actionpack (>= 3.0)
104 actionpack (>= 3.0)
105 activesupport (>= 3.0)
105 activesupport (>= 3.0)
106 railties (>= 3.0)
106 railties (>= 3.0)
107 rspec (~> 2.11.0)
107 rspec (~> 2.11.0)
108 sass (3.2.1)
108 sass (3.2.1)
109 sass-rails (3.2.5)
109 sass-rails (3.2.5)
110 railties (~> 3.2.0)
110 railties (~> 3.2.0)
111 sass (>= 3.1.10)
111 sass (>= 3.1.10)
112 tilt (~> 1.3)
112 tilt (~> 1.3)
113 sprockets (2.1.3)
113 sprockets (2.1.3)
114 hike (~> 1.2)
114 hike (~> 1.2)
115 rack (~> 1.0)
115 rack (~> 1.0)
116 tilt (~> 1.1, != 1.3.0)
116 tilt (~> 1.1, != 1.3.0)
117 test-unit (2.5.2)
117 test-unit (2.5.2)
118 thor (0.16.0)
118 thor (0.16.0)
119 tilt (1.3.3)
119 tilt (1.3.3)
120 - tmail (1.2.7.1)
121 treetop (1.4.10)
120 treetop (1.4.10)
122 polyglot
121 polyglot
123 polyglot (>= 0.3.1)
122 polyglot (>= 0.3.1)
124 tzinfo (0.3.33)
123 tzinfo (0.3.33)
125 uglifier (1.3.0)
124 uglifier (1.3.0)
126 execjs (>= 0.3.0)
125 execjs (>= 0.3.0)
127 multi_json (~> 1.0, >= 1.0.2)
126 multi_json (~> 1.0, >= 1.0.2)
128 will_paginate (3.0.3)
127 will_paginate (3.0.3)
129
128
130 PLATFORMS
129 PLATFORMS
131 ruby
130 ruby
132
131
133 DEPENDENCIES
132 DEPENDENCIES
134 coffee-rails (~> 3.2.1)
133 coffee-rails (~> 3.2.1)
135 dynamic_form
134 dynamic_form
136 haml
135 haml
137 in_place_editing
136 in_place_editing
137 + mail
138 mysql2
138 mysql2
139 prototype-rails
139 prototype-rails
140 rails (= 3.2.8)
140 rails (= 3.2.8)
141 rdiscount
141 rdiscount
142 rspec-rails (~> 2.0)
142 rspec-rails (~> 2.0)
143 sass-rails (~> 3.2.3)
143 sass-rails (~> 3.2.3)
144 test-unit
144 test-unit
145 - tmail
146 uglifier (>= 1.0.3)
145 uglifier (>= 1.0.3)
147 verification!
146 verification!
148 will_paginate (~> 3.0.0)
147 will_paginate (~> 3.0.0)
@@ -1,28 +1,26
1 class UserAdminController < ApplicationController
1 class UserAdminController < ApplicationController
2
2
3 - #include MailHelperMethods
4 -
5 before_filter :admin_authorization
3 before_filter :admin_authorization
6
4
7 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
5 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
8 verify :method => :post, :only => [ :destroy,
6 verify :method => :post, :only => [ :destroy,
9 :create, :create_from_list,
7 :create, :create_from_list,
10 :update,
8 :update,
11 :manage_contest,
9 :manage_contest,
12 :bulk_mail
10 :bulk_mail
13 ],
11 ],
14 :redirect_to => { :action => :list }
12 :redirect_to => { :action => :list }
15
13
16 def index
14 def index
17 list
15 list
18 render :action => 'list'
16 render :action => 'list'
19 end
17 end
20
18
21 def list
19 def list
22 @user_count = User.count
20 @user_count = User.count
23 if params[:page] == 'all'
21 if params[:page] == 'all'
24 @users = User.all
22 @users = User.all
25 @paginated = false
23 @paginated = false
26 else
24 else
27 @users = User.paginate :page => params[:page]
25 @users = User.paginate :page => params[:page]
28 @paginated = true
26 @paginated = true
@@ -295,66 +293,73
295 redirect_to :action => 'admin' and return
293 redirect_to :action => 'admin' and return
296 elsif user.login == 'root'
294 elsif user.login == 'root'
297 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
295 flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
298 redirect_to :action => 'admin' and return
296 redirect_to :action => 'admin' and return
299 end
297 end
300
298
301 admin_role = Role.find_by_name('admin')
299 admin_role = Role.find_by_name('admin')
302 user.roles.delete(admin_role)
300 user.roles.delete(admin_role)
303 flash[:notice] = 'User permission revoked'
301 flash[:notice] = 'User permission revoked'
304 redirect_to :action => 'admin'
302 redirect_to :action => 'admin'
305 end
303 end
306
304
307 # mass mailing
305 # mass mailing
308
306
309 def mass_mailing
307 def mass_mailing
310 end
308 end
311
309
312 def bulk_mail
310 def bulk_mail
313 lines = params[:login_list]
311 lines = params[:login_list]
314 if !lines or lines.blank?
312 if !lines or lines.blank?
315 flash[:notice] = 'You entered an empty list.'
313 flash[:notice] = 'You entered an empty list.'
316 redirect_to :action => 'mass_mailing' and return
314 redirect_to :action => 'mass_mailing' and return
317 end
315 end
318
316
319 - subject = params[:subject]
317 + mail_subject = params[:subject]
320 - if !subject or subject.blank?
318 + if !mail_subject or mail_subject.blank?
321 flash[:notice] = 'You entered an empty mail subject.'
319 flash[:notice] = 'You entered an empty mail subject.'
322 redirect_to :action => 'mass_mailing' and return
320 redirect_to :action => 'mass_mailing' and return
323 end
321 end
324
322
325 - body = params[:email_body]
323 + mail_body = params[:email_body]
326 - if !body or body.blank?
324 + if !mail_body or mail_body.blank?
327 flash[:notice] = 'You entered an empty mail body.'
325 flash[:notice] = 'You entered an empty mail body.'
328 redirect_to :action => 'mass_mailing' and return
326 redirect_to :action => 'mass_mailing' and return
329 end
327 end
330
328
329 + admin_email = GraderConfiguration['system.admin_email']
330 +
331 note = []
331 note = []
332 users = []
332 users = []
333 lines.split("\n").each do |line|
333 lines.split("\n").each do |line|
334 user = User.find_by_login(line.chomp)
334 user = User.find_by_login(line.chomp)
335 if user
335 if user
336 - send_mail(user.email, subject, body)
336 + Mail.deliver do
337 + from admin_email
338 + to user.email
339 + subject mail_subject
340 + body mail_body
341 + end
337 note << user.login
342 note << user.login
338 end
343 end
339 end
344 end
340
345
341 flash[:notice] = 'User(s) ' + note.join(', ') +
346 flash[:notice] = 'User(s) ' + note.join(', ') +
342 ' were successfully modified. '
347 ' were successfully modified. '
343 redirect_to :action => 'mass_mailing'
348 redirect_to :action => 'mass_mailing'
344 end
349 end
345
350
346 protected
351 protected
347
352
348 def random_password(length=5)
353 def random_password(length=5)
349 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
354 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
350 newpass = ""
355 newpass = ""
351 length.times { newpass << chars[rand(chars.size-1)] }
356 length.times { newpass << chars[rand(chars.size-1)] }
352 return newpass
357 return newpass
353 end
358 end
354
359
355 def import_from_file(f)
360 def import_from_file(f)
356 data_hash = YAML.load(f)
361 data_hash = YAML.load(f)
357 @import_log = ""
362 @import_log = ""
358
363
359 country_data = data_hash[:countries]
364 country_data = data_hash[:countries]
360 site_data = data_hash[:sites]
365 site_data = data_hash[:sites]
@@ -405,51 +410,58
405 u.site = sites[user[:site_id]]
410 u.site = sites[user[:site_id]]
406 u.activated = true
411 u.activated = true
407 u.email = "empty-#{u.login}@none.com"
412 u.email = "empty-#{u.login}@none.com"
408 if not u.save
413 if not u.save
409 @import_log << "Errors\n"
414 @import_log << "Errors\n"
410 u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" }
415 u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" }
411 end
416 end
412 end
417 end
413
418
414 end
419 end
415
420
416 def logout_users(users)
421 def logout_users(users)
417 users.each do |user|
422 users.each do |user|
418 contest_stat = user.contest_stat(true)
423 contest_stat = user.contest_stat(true)
419 if contest_stat and !contest_stat.forced_logout
424 if contest_stat and !contest_stat.forced_logout
420 contest_stat.forced_logout = true
425 contest_stat.forced_logout = true
421 contest_stat.save
426 contest_stat.save
422 end
427 end
423 end
428 end
424 end
429 end
425
430
426 def send_contest_update_notification_email(user, contest)
431 def send_contest_update_notification_email(user, contest)
427 contest_title_name = GraderConfiguration['contest.name']
432 contest_title_name = GraderConfiguration['contest.name']
428 contest_name = contest.name
433 contest_name = contest.name
429 - subject = t('contest.notification.email_subject', {
434 + mail_subject = t('contest.notification.email_subject', {
430 :contest_title_name => contest_title_name,
435 :contest_title_name => contest_title_name,
431 :contest_name => contest_name })
436 :contest_name => contest_name })
432 - body = t('contest.notification.email_body', {
437 + mail_body = t('contest.notification.email_body', {
433 :full_name => user.full_name,
438 :full_name => user.full_name,
434 :contest_title_name => contest_title_name,
439 :contest_title_name => contest_title_name,
435 :contest_name => contest.name,
440 :contest_name => contest.name,
436 })
441 })
437
442
438 - logger.info body
443 + admin_email = GraderConfiguration['system.admin_email']
439 - send_mail(user.email, subject, body)
444 +
445 + logger.info mail_body
446 + Mail.deliver do
447 + from admin_email
448 + to user.email
449 + subject mail_subject
450 + body mail_body
451 + end
440 end
452 end
441
453
442 def find_contest_and_user_from_contest_id(id)
454 def find_contest_and_user_from_contest_id(id)
443 if id!='none'
455 if id!='none'
444 @contest = Contest.find(id)
456 @contest = Contest.find(id)
445 else
457 else
446 @contest = nil
458 @contest = nil
447 end
459 end
448 if @contest
460 if @contest
449 @users = @contest.users
461 @users = @contest.users
450 else
462 else
451 @users = User.find_users_with_no_contest
463 @users = User.find_users_with_no_contest
452 end
464 end
453 return [@contest, @users]
465 return [@contest, @users]
454 end
466 end
455 end
467 end
@@ -1,31 +1,28
1 - require 'tmail'
2 require 'net/smtp'
1 require 'net/smtp'
3
2
4 class UsersController < ApplicationController
3 class UsersController < ApplicationController
5
4
6 - #include MailHelperMethods
7 -
8 before_filter :authenticate, :except => [:new,
5 before_filter :authenticate, :except => [:new,
9 :register,
6 :register,
10 :confirm,
7 :confirm,
11 :forget,
8 :forget,
12 :retrieve_password]
9 :retrieve_password]
13
10
14 before_filter :verify_online_registration, :only => [:new,
11 before_filter :verify_online_registration, :only => [:new,
15 :register,
12 :register,
16 :forget,
13 :forget,
17 :retrieve_password]
14 :retrieve_password]
18
15
19 verify :method => :post, :only => [:chg_passwd],
16 verify :method => :post, :only => [:chg_passwd],
20 :redirect_to => { :action => :index }
17 :redirect_to => { :action => :index }
21
18
22 #in_place_edit_for :user, :alias_for_editing
19 #in_place_edit_for :user, :alias_for_editing
23 #in_place_edit_for :user, :email_for_editing
20 #in_place_edit_for :user, :email_for_editing
24
21
25 def index
22 def index
26 if !GraderConfiguration['system.user_setting_enabled']
23 if !GraderConfiguration['system.user_setting_enabled']
27 redirect_to :controller => 'main', :action => 'list'
24 redirect_to :controller => 'main', :action => 'list'
28 else
25 else
29 @user = User.find(session[:user_id])
26 @user = User.find(session[:user_id])
30 end
27 end
31 end
28 end
@@ -103,56 +100,67
103 send_new_password_email(user)
100 send_new_password_email(user)
104 flash[:notice] = 'New password has been mailed to you.'
101 flash[:notice] = 'New password has been mailed to you.'
105 end
102 end
106 else
103 else
107 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
104 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
108 end
105 end
109 redirect_to :action => 'forget'
106 redirect_to :action => 'forget'
110 end
107 end
111
108
112 protected
109 protected
113
110
114 def verify_online_registration
111 def verify_online_registration
115 if !GraderConfiguration['system.online_registration']
112 if !GraderConfiguration['system.online_registration']
116 redirect_to :controller => 'main', :action => 'login'
113 redirect_to :controller => 'main', :action => 'login'
117 end
114 end
118 end
115 end
119
116
120 def send_confirmation_email(user)
117 def send_confirmation_email(user)
121 contest_name = GraderConfiguration['contest.name']
118 contest_name = GraderConfiguration['contest.name']
122 admin_email = GraderConfiguration['system.admin_email']
119 admin_email = GraderConfiguration['system.admin_email']
123 activation_url = url_for(:action => 'confirm',
120 activation_url = url_for(:action => 'confirm',
124 :login => user.login,
121 :login => user.login,
125 :activation => user.activation_key)
122 :activation => user.activation_key)
126 home_url = url_for(:controller => 'main', :action => 'index')
123 home_url = url_for(:controller => 'main', :action => 'index')
127 - subject = "[#{contest_name}] Confirmation"
124 + mail_subject = "[#{contest_name}] Confirmation"
128 - body = t('registration.email_body', {
125 + mail_body = t('registration.email_body', {
129 :full_name => user.full_name,
126 :full_name => user.full_name,
130 :contest_name => contest_name,
127 :contest_name => contest_name,
131 :login => user.login,
128 :login => user.login,
132 :password => user.password,
129 :password => user.password,
133 :activation_url => activation_url,
130 :activation_url => activation_url,
134 :admin_email => admin_email
131 :admin_email => admin_email
135 })
132 })
136
133
137 - logger.info body
134 + logger.info mail_body
138
135
139 - send_mail(user.email, subject, body)
136 + Mail.deliver do
137 + from admin_email
138 + to user.email
139 + subject mail_subject
140 + body mail_body
141 + end
140 end
142 end
141
143
142 def send_new_password_email(user)
144 def send_new_password_email(user)
143 contest_name = GraderConfiguration['contest.name']
145 contest_name = GraderConfiguration['contest.name']
144 admin_email = GraderConfiguration['system.admin_email']
146 admin_email = GraderConfiguration['system.admin_email']
145 - subject = "[#{contest_name}] Password recovery"
147 + mail_subject = "[#{contest_name}] Password recovery"
146 - body = t('registration.password_retrieval.email_body', {
148 + mail_body = t('registration.password_retrieval.email_body', {
147 :full_name => user.full_name,
149 :full_name => user.full_name,
148 :contest_name => contest_name,
150 :contest_name => contest_name,
149 :login => user.login,
151 :login => user.login,
150 :password => user.password,
152 :password => user.password,
151 :admin_email => admin_email
153 :admin_email => admin_email
152 })
154 })
153
155
154 - logger.info body
156 + logger.info mail_body
155 - send_mail(user.email, subject, body)
157 +
158 + Mail.deliver do
159 + from admin_email
160 + to user.email
161 + subject mail_subject
162 + body mail_body
163 + end
156 end
164 end
157
165
158 end
166 end
You need to be logged in to leave comments. Login now