Description:
moved send mail code back to helper
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r336:4e59f67ded1a - - 3 files changed: 22 inserted, 50 deleted
@@ -1,5 +1,7 | |||||
|
1 | class UserAdminController < ApplicationController |
|
1 | class UserAdminController < ApplicationController |
|
2 |
|
2 | ||
|
|
3 | + include MailHelperMethods | ||
|
|
4 | + | ||
|
3 | before_filter :admin_authorization |
|
5 | before_filter :admin_authorization |
|
4 |
|
6 | ||
|
5 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
7 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
@@ -326,19 +328,12 | |||||
|
326 | redirect_to :action => 'mass_mailing' and return |
|
328 | redirect_to :action => 'mass_mailing' and return |
|
327 | end |
|
329 | end |
|
328 |
|
330 | ||
|
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 | - Mail.deliver do |
|
336 | + send_mail(user.email, mail_subject, mail_body) |
|
337 | - from admin_email |
|
||
|
338 | - to user.email |
|
||
|
339 | - subject mail_subject |
|
||
|
340 | - body mail_body |
|
||
|
341 | - end |
|
||
|
342 | note << user.login |
|
337 | note << user.login |
|
343 | end |
|
338 | end |
|
344 | end |
|
339 | end |
@@ -440,15 +435,8 | |||||
|
440 | :contest_name => contest.name, |
|
435 | :contest_name => contest.name, |
|
441 | }) |
|
436 | }) |
|
442 |
|
437 | ||
|
443 | - admin_email = GraderConfiguration['system.admin_email'] |
|
||
|
444 | - |
|
||
|
445 | logger.info mail_body |
|
438 | logger.info mail_body |
|
446 | - Mail.deliver do |
|
439 | + send_mail(user.email, mail_subject, mail_body) |
|
447 | - from admin_email |
|
||
|
448 | - to user.email |
|
||
|
449 | - subject mail_subject |
|
||
|
450 | - body mail_body |
|
||
|
451 | - end |
|
||
|
452 | end |
|
440 | end |
|
453 |
|
441 | ||
|
454 | def find_contest_and_user_from_contest_id(id) |
|
442 | def find_contest_and_user_from_contest_id(id) |
@@ -2,6 +2,8 | |||||
|
2 |
|
2 | ||
|
3 | class UsersController < ApplicationController |
|
3 | class UsersController < ApplicationController |
|
4 |
|
4 | ||
|
|
5 | + include MailHelperMethods | ||
|
|
6 | + | ||
|
5 | before_filter :authenticate, :except => [:new, |
|
7 | before_filter :authenticate, :except => [:new, |
|
6 | :register, |
|
8 | :register, |
|
7 | :confirm, |
|
9 | :confirm, |
@@ -116,7 +118,6 | |||||
|
116 |
|
118 | ||
|
117 | def send_confirmation_email(user) |
|
119 | def send_confirmation_email(user) |
|
118 | contest_name = GraderConfiguration['contest.name'] |
|
120 | contest_name = GraderConfiguration['contest.name'] |
|
119 | - admin_email = GraderConfiguration['system.admin_email'] |
|
||
|
120 | activation_url = url_for(:action => 'confirm', |
|
121 | activation_url = url_for(:action => 'confirm', |
|
121 | :login => user.login, |
|
122 | :login => user.login, |
|
122 | :activation => user.activation_key) |
|
123 | :activation => user.activation_key) |
@@ -133,17 +134,11 | |||||
|
133 |
|
134 | ||
|
134 | logger.info mail_body |
|
135 | logger.info mail_body |
|
135 |
|
136 | ||
|
136 | - Mail.deliver do |
|
137 | + send_mail(user.email, mail_subject, mail_body) |
|
137 | - from admin_email |
|
||
|
138 | - to user.email |
|
||
|
139 | - subject mail_subject |
|
||
|
140 | - body mail_body |
|
||
|
141 | - end |
|
||
|
142 | end |
|
138 | end |
|
143 |
|
139 | ||
|
144 | def send_new_password_email(user) |
|
140 | def send_new_password_email(user) |
|
145 | contest_name = GraderConfiguration['contest.name'] |
|
141 | contest_name = GraderConfiguration['contest.name'] |
|
146 | - admin_email = GraderConfiguration['system.admin_email'] |
|
||
|
147 | mail_subject = "[#{contest_name}] Password recovery" |
|
142 | mail_subject = "[#{contest_name}] Password recovery" |
|
148 | mail_body = t('registration.password_retrieval.email_body', { |
|
143 | mail_body = t('registration.password_retrieval.email_body', { |
|
149 | :full_name => user.full_name, |
|
144 | :full_name => user.full_name, |
@@ -155,12 +150,7 | |||||
|
155 |
|
150 | ||
|
156 | logger.info mail_body |
|
151 | logger.info mail_body |
|
157 |
|
152 | ||
|
158 | - Mail.deliver do |
|
153 | + send_mail(user.email, mail_subject, mail_body) |
|
159 | - from admin_email |
|
||
|
160 | - to user.email |
|
||
|
161 | - subject mail_subject |
|
||
|
162 | - body mail_body |
|
||
|
163 | - end |
|
||
|
164 | end |
|
154 | end |
|
165 |
|
155 | ||
|
166 | end |
|
156 | end |
@@ -1,35 +1,29 | |||||
|
1 | module MailHelperMethods |
|
1 | module MailHelperMethods |
|
2 |
|
2 | ||
|
3 | - def send_mail(to, subject, body) |
|
3 | + def send_mail(mail_to, mail_subject, mail_body) |
|
4 | - mail = TMail::Mail.new |
|
4 | + mail_from = GraderConfiguration['system.online_registration.from'] |
|
5 | - mail.to = to |
|
5 | + smtp_server = GraderConfiguration['system.online_registration.smtp'] |
|
6 | - mail.from = Configuration['system.online_registration.from'] |
|
||
|
7 | - mail.subject = subject |
|
||
|
8 | - mail.body = body |
|
||
|
9 | - |
|
||
|
10 | - smtp_server = Configuration['system.online_registration.smtp'] |
|
||
|
11 |
|
6 | ||
|
12 | if ['fake', 'debug'].include? smtp_server |
|
7 | if ['fake', 'debug'].include? smtp_server |
|
13 | puts "------------------------- |
|
8 | puts "------------------------- |
|
14 |
- To: #{mail |
|
9 | + To: #{mail_to} |
|
15 |
- From: #{mail |
|
10 | + From: #{mail_from} |
|
16 |
- Subject: #{mail |
|
11 | + Subject: #{mail_subject} |
|
17 |
- #{mail |
|
12 | + #{mail_body} |
|
18 | -------------------------- |
|
13 | -------------------------- |
|
19 | " |
|
14 | " |
|
20 | return true |
|
15 | return true |
|
21 | end |
|
16 | end |
|
22 |
|
17 | ||
|
23 | - begin |
|
18 | + mail = Mail.new do |
|
24 | - Net::SMTP.start(smtp_server) do |smtp| |
|
19 | + from mail_from |
|
25 | - smtp.send_message(mail.to_s, mail.from, mail.to) |
|
20 | + to mail_to |
|
26 | - end |
|
21 | + subject mail_subject |
|
27 | - result = true |
|
22 | + body mail_body |
|
28 | - rescue |
|
||
|
29 | - result = false |
|
||
|
30 | end |
|
23 | end |
|
31 |
|
24 | ||
|
32 | - result |
|
25 | + mail.delivery_settings = { :address => smtp_server } |
|
|
26 | + mail.deliver | ||
|
33 | end |
|
27 | end |
|
34 |
|
28 | ||
|
35 | end |
|
29 | end |
You need to be logged in to leave comments.
Login now