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,50 +1,52 | |||||
|
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) |
|
6 | verify :method => :post, :only => [ :destroy, |
|
8 | verify :method => :post, :only => [ :destroy, |
|
7 | :create, :create_from_list, |
|
9 | :create, :create_from_list, |
|
8 | :update, |
|
10 | :update, |
|
9 | :manage_contest, |
|
11 | :manage_contest, |
|
10 | :bulk_mail |
|
12 | :bulk_mail |
|
11 | ], |
|
13 | ], |
|
12 | :redirect_to => { :action => :list } |
|
14 | :redirect_to => { :action => :list } |
|
13 |
|
15 | ||
|
14 | def index |
|
16 | def index |
|
15 | list |
|
17 | list |
|
16 | render :action => 'list' |
|
18 | render :action => 'list' |
|
17 | end |
|
19 | end |
|
18 |
|
20 | ||
|
19 | def list |
|
21 | def list |
|
20 | @user_count = User.count |
|
22 | @user_count = User.count |
|
21 | if params[:page] == 'all' |
|
23 | if params[:page] == 'all' |
|
22 | @users = User.all |
|
24 | @users = User.all |
|
23 | @paginated = false |
|
25 | @paginated = false |
|
24 | else |
|
26 | else |
|
25 | @users = User.paginate :page => params[:page] |
|
27 | @users = User.paginate :page => params[:page] |
|
26 | @paginated = true |
|
28 | @paginated = true |
|
27 | end |
|
29 | end |
|
28 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
30 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
29 | @contests = Contest.enabled |
|
31 | @contests = Contest.enabled |
|
30 | end |
|
32 | end |
|
31 |
|
33 | ||
|
32 | def active |
|
34 | def active |
|
33 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
35 | sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago]) |
|
34 | @users = [] |
|
36 | @users = [] |
|
35 | sessions.each do |session| |
|
37 | sessions.each do |session| |
|
36 | if session.data[:user_id] |
|
38 | if session.data[:user_id] |
|
37 | @users << User.find(session.data[:user_id]) |
|
39 | @users << User.find(session.data[:user_id]) |
|
38 | end |
|
40 | end |
|
39 | end |
|
41 | end |
|
40 | end |
|
42 | end |
|
41 |
|
43 | ||
|
42 | def show |
|
44 | def show |
|
43 | @user = User.find(params[:id]) |
|
45 | @user = User.find(params[:id]) |
|
44 | end |
|
46 | end |
|
45 |
|
47 | ||
|
46 | def new |
|
48 | def new |
|
47 | @user = User.new |
|
49 | @user = User.new |
|
48 | end |
|
50 | end |
|
49 |
|
51 | ||
|
50 | def create |
|
52 | def create |
@@ -281,109 +283,102 | |||||
|
281 | user.roles << admin_role |
|
283 | user.roles << admin_role |
|
282 | else |
|
284 | else |
|
283 | flash[:notice] = 'Unknown user' |
|
285 | flash[:notice] = 'Unknown user' |
|
284 | end |
|
286 | end |
|
285 | flash[:notice] = 'User added as admins' |
|
287 | flash[:notice] = 'User added as admins' |
|
286 | redirect_to :action => 'admin' |
|
288 | redirect_to :action => 'admin' |
|
287 | end |
|
289 | end |
|
288 |
|
290 | ||
|
289 | def revoke_admin |
|
291 | def revoke_admin |
|
290 | user = User.find(params[:id]) |
|
292 | user = User.find(params[:id]) |
|
291 | if user==nil |
|
293 | if user==nil |
|
292 | flash[:notice] = 'Unknown user' |
|
294 | flash[:notice] = 'Unknown user' |
|
293 | redirect_to :action => 'admin' and return |
|
295 | redirect_to :action => 'admin' and return |
|
294 | elsif user.login == 'root' |
|
296 | elsif user.login == 'root' |
|
295 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
297 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
296 | redirect_to :action => 'admin' and return |
|
298 | redirect_to :action => 'admin' and return |
|
297 | end |
|
299 | end |
|
298 |
|
300 | ||
|
299 | admin_role = Role.find_by_name('admin') |
|
301 | admin_role = Role.find_by_name('admin') |
|
300 | user.roles.delete(admin_role) |
|
302 | user.roles.delete(admin_role) |
|
301 | flash[:notice] = 'User permission revoked' |
|
303 | flash[:notice] = 'User permission revoked' |
|
302 | redirect_to :action => 'admin' |
|
304 | redirect_to :action => 'admin' |
|
303 | end |
|
305 | end |
|
304 |
|
306 | ||
|
305 | # mass mailing |
|
307 | # mass mailing |
|
306 |
|
308 | ||
|
307 | def mass_mailing |
|
309 | def mass_mailing |
|
308 | end |
|
310 | end |
|
309 |
|
311 | ||
|
310 | def bulk_mail |
|
312 | def bulk_mail |
|
311 | lines = params[:login_list] |
|
313 | lines = params[:login_list] |
|
312 | if !lines or lines.blank? |
|
314 | if !lines or lines.blank? |
|
313 | flash[:notice] = 'You entered an empty list.' |
|
315 | flash[:notice] = 'You entered an empty list.' |
|
314 | redirect_to :action => 'mass_mailing' and return |
|
316 | redirect_to :action => 'mass_mailing' and return |
|
315 | end |
|
317 | end |
|
316 |
|
318 | ||
|
317 | mail_subject = params[:subject] |
|
319 | mail_subject = params[:subject] |
|
318 | if !mail_subject or mail_subject.blank? |
|
320 | if !mail_subject or mail_subject.blank? |
|
319 | flash[:notice] = 'You entered an empty mail subject.' |
|
321 | flash[:notice] = 'You entered an empty mail subject.' |
|
320 | redirect_to :action => 'mass_mailing' and return |
|
322 | redirect_to :action => 'mass_mailing' and return |
|
321 | end |
|
323 | end |
|
322 |
|
324 | ||
|
323 | mail_body = params[:email_body] |
|
325 | mail_body = params[:email_body] |
|
324 | if !mail_body or mail_body.blank? |
|
326 | if !mail_body or mail_body.blank? |
|
325 | flash[:notice] = 'You entered an empty mail body.' |
|
327 | flash[:notice] = 'You entered an empty mail body.' |
|
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 |
|
345 |
|
340 | ||
|
346 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
341 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
347 | ' were successfully modified. ' |
|
342 | ' were successfully modified. ' |
|
348 | redirect_to :action => 'mass_mailing' |
|
343 | redirect_to :action => 'mass_mailing' |
|
349 | end |
|
344 | end |
|
350 |
|
345 | ||
|
351 | protected |
|
346 | protected |
|
352 |
|
347 | ||
|
353 | def random_password(length=5) |
|
348 | def random_password(length=5) |
|
354 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
349 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
355 | newpass = "" |
|
350 | newpass = "" |
|
356 | length.times { newpass << chars[rand(chars.size-1)] } |
|
351 | length.times { newpass << chars[rand(chars.size-1)] } |
|
357 | return newpass |
|
352 | return newpass |
|
358 | end |
|
353 | end |
|
359 |
|
354 | ||
|
360 | def import_from_file(f) |
|
355 | def import_from_file(f) |
|
361 | data_hash = YAML.load(f) |
|
356 | data_hash = YAML.load(f) |
|
362 | @import_log = "" |
|
357 | @import_log = "" |
|
363 |
|
358 | ||
|
364 | country_data = data_hash[:countries] |
|
359 | country_data = data_hash[:countries] |
|
365 | site_data = data_hash[:sites] |
|
360 | site_data = data_hash[:sites] |
|
366 | user_data = data_hash[:users] |
|
361 | user_data = data_hash[:users] |
|
367 |
|
362 | ||
|
368 | # import country |
|
363 | # import country |
|
369 | countries = {} |
|
364 | countries = {} |
|
370 | country_data.each_pair do |id,country| |
|
365 | country_data.each_pair do |id,country| |
|
371 | c = Country.find_by_name(country[:name]) |
|
366 | c = Country.find_by_name(country[:name]) |
|
372 | if c!=nil |
|
367 | if c!=nil |
|
373 | countries[id] = c |
|
368 | countries[id] = c |
|
374 | @import_log << "Found #{country[:name]}\n" |
|
369 | @import_log << "Found #{country[:name]}\n" |
|
375 | else |
|
370 | else |
|
376 | countries[id] = Country.new(:name => country[:name]) |
|
371 | countries[id] = Country.new(:name => country[:name]) |
|
377 | countries[id].save |
|
372 | countries[id].save |
|
378 | @import_log << "Created #{country[:name]}\n" |
|
373 | @import_log << "Created #{country[:name]}\n" |
|
379 | end |
|
374 | end |
|
380 | end |
|
375 | end |
|
381 |
|
376 | ||
|
382 | # import sites |
|
377 | # import sites |
|
383 | sites = {} |
|
378 | sites = {} |
|
384 | site_data.each_pair do |id,site| |
|
379 | site_data.each_pair do |id,site| |
|
385 | s = Site.find_by_name(site[:name]) |
|
380 | s = Site.find_by_name(site[:name]) |
|
386 | if s!=nil |
|
381 | if s!=nil |
|
387 | @import_log << "Found #{site[:name]}\n" |
|
382 | @import_log << "Found #{site[:name]}\n" |
|
388 | else |
|
383 | else |
|
389 | s = Site.new(:name => site[:name]) |
|
384 | s = Site.new(:name => site[:name]) |
@@ -395,73 +390,66 | |||||
|
395 | sites[id] = s |
|
390 | sites[id] = s |
|
396 | end |
|
391 | end |
|
397 |
|
392 | ||
|
398 | # import users |
|
393 | # import users |
|
399 | user_data.each_pair do |id,user| |
|
394 | user_data.each_pair do |id,user| |
|
400 | u = User.find_by_login(user[:login]) |
|
395 | u = User.find_by_login(user[:login]) |
|
401 | if u!=nil |
|
396 | if u!=nil |
|
402 | @import_log << "Found #{user[:login]}\n" |
|
397 | @import_log << "Found #{user[:login]}\n" |
|
403 | else |
|
398 | else |
|
404 | u = User.new(:login => user[:login]) |
|
399 | u = User.new(:login => user[:login]) |
|
405 | @import_log << "Created #{user[:login]}\n" |
|
400 | @import_log << "Created #{user[:login]}\n" |
|
406 | end |
|
401 | end |
|
407 | u.full_name = user[:name] |
|
402 | u.full_name = user[:name] |
|
408 | u.password = user[:password] |
|
403 | u.password = user[:password] |
|
409 | u.country = countries[user[:country_id]] |
|
404 | u.country = countries[user[:country_id]] |
|
410 | u.site = sites[user[:site_id]] |
|
405 | u.site = sites[user[:site_id]] |
|
411 | u.activated = true |
|
406 | u.activated = true |
|
412 | u.email = "empty-#{u.login}@none.com" |
|
407 | u.email = "empty-#{u.login}@none.com" |
|
413 | if not u.save |
|
408 | if not u.save |
|
414 | @import_log << "Errors\n" |
|
409 | @import_log << "Errors\n" |
|
415 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
410 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
416 | end |
|
411 | end |
|
417 | end |
|
412 | end |
|
418 |
|
413 | ||
|
419 | end |
|
414 | end |
|
420 |
|
415 | ||
|
421 | def logout_users(users) |
|
416 | def logout_users(users) |
|
422 | users.each do |user| |
|
417 | users.each do |user| |
|
423 | contest_stat = user.contest_stat(true) |
|
418 | contest_stat = user.contest_stat(true) |
|
424 | if contest_stat and !contest_stat.forced_logout |
|
419 | if contest_stat and !contest_stat.forced_logout |
|
425 | contest_stat.forced_logout = true |
|
420 | contest_stat.forced_logout = true |
|
426 | contest_stat.save |
|
421 | contest_stat.save |
|
427 | end |
|
422 | end |
|
428 | end |
|
423 | end |
|
429 | end |
|
424 | end |
|
430 |
|
425 | ||
|
431 | def send_contest_update_notification_email(user, contest) |
|
426 | def send_contest_update_notification_email(user, contest) |
|
432 | contest_title_name = GraderConfiguration['contest.name'] |
|
427 | contest_title_name = GraderConfiguration['contest.name'] |
|
433 | contest_name = contest.name |
|
428 | contest_name = contest.name |
|
434 | mail_subject = t('contest.notification.email_subject', { |
|
429 | mail_subject = t('contest.notification.email_subject', { |
|
435 | :contest_title_name => contest_title_name, |
|
430 | :contest_title_name => contest_title_name, |
|
436 | :contest_name => contest_name }) |
|
431 | :contest_name => contest_name }) |
|
437 | mail_body = t('contest.notification.email_body', { |
|
432 | mail_body = t('contest.notification.email_body', { |
|
438 | :full_name => user.full_name, |
|
433 | :full_name => user.full_name, |
|
439 | :contest_title_name => contest_title_name, |
|
434 | :contest_title_name => contest_title_name, |
|
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) |
|
455 | if id!='none' |
|
443 | if id!='none' |
|
456 | @contest = Contest.find(id) |
|
444 | @contest = Contest.find(id) |
|
457 | else |
|
445 | else |
|
458 | @contest = nil |
|
446 | @contest = nil |
|
459 | end |
|
447 | end |
|
460 | if @contest |
|
448 | if @contest |
|
461 | @users = @contest.users |
|
449 | @users = @contest.users |
|
462 | else |
|
450 | else |
|
463 | @users = User.find_users_with_no_contest |
|
451 | @users = User.find_users_with_no_contest |
|
464 | end |
|
452 | end |
|
465 | return [@contest, @users] |
|
453 | return [@contest, @users] |
|
466 | end |
|
454 | end |
|
467 | end |
|
455 | end |
@@ -1,52 +1,54 | |||||
|
1 | require 'net/smtp' |
|
1 | require 'net/smtp' |
|
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, |
|
8 | :forget, |
|
10 | :forget, |
|
9 | :retrieve_password] |
|
11 | :retrieve_password] |
|
10 |
|
12 | ||
|
11 | before_filter :verify_online_registration, :only => [:new, |
|
13 | before_filter :verify_online_registration, :only => [:new, |
|
12 | :register, |
|
14 | :register, |
|
13 | :forget, |
|
15 | :forget, |
|
14 | :retrieve_password] |
|
16 | :retrieve_password] |
|
15 |
|
17 | ||
|
16 | verify :method => :post, :only => [:chg_passwd], |
|
18 | verify :method => :post, :only => [:chg_passwd], |
|
17 | :redirect_to => { :action => :index } |
|
19 | :redirect_to => { :action => :index } |
|
18 |
|
20 | ||
|
19 | #in_place_edit_for :user, :alias_for_editing |
|
21 | #in_place_edit_for :user, :alias_for_editing |
|
20 | #in_place_edit_for :user, :email_for_editing |
|
22 | #in_place_edit_for :user, :email_for_editing |
|
21 |
|
23 | ||
|
22 | def index |
|
24 | def index |
|
23 | if !GraderConfiguration['system.user_setting_enabled'] |
|
25 | if !GraderConfiguration['system.user_setting_enabled'] |
|
24 | redirect_to :controller => 'main', :action => 'list' |
|
26 | redirect_to :controller => 'main', :action => 'list' |
|
25 | else |
|
27 | else |
|
26 | @user = User.find(session[:user_id]) |
|
28 | @user = User.find(session[:user_id]) |
|
27 | end |
|
29 | end |
|
28 | end |
|
30 | end |
|
29 |
|
31 | ||
|
30 | def chg_passwd |
|
32 | def chg_passwd |
|
31 | user = User.find(session[:user_id]) |
|
33 | user = User.find(session[:user_id]) |
|
32 | user.password = params[:passwd] |
|
34 | user.password = params[:passwd] |
|
33 | user.password_confirmation = params[:passwd_verify] |
|
35 | user.password_confirmation = params[:passwd_verify] |
|
34 | if user.save |
|
36 | if user.save |
|
35 | flash[:notice] = 'password changed' |
|
37 | flash[:notice] = 'password changed' |
|
36 | else |
|
38 | else |
|
37 | flash[:notice] = 'Error: password changing failed' |
|
39 | flash[:notice] = 'Error: password changing failed' |
|
38 | end |
|
40 | end |
|
39 | redirect_to :action => 'index' |
|
41 | redirect_to :action => 'index' |
|
40 | end |
|
42 | end |
|
41 |
|
43 | ||
|
42 | def new |
|
44 | def new |
|
43 | @user = User.new |
|
45 | @user = User.new |
|
44 | render :action => 'new', :layout => 'empty' |
|
46 | render :action => 'new', :layout => 'empty' |
|
45 | end |
|
47 | end |
|
46 |
|
48 | ||
|
47 | def register |
|
49 | def register |
|
48 | if(params[:cancel]) |
|
50 | if(params[:cancel]) |
|
49 | redirect_to :controller => 'main', :action => 'login' |
|
51 | redirect_to :controller => 'main', :action => 'login' |
|
50 | return |
|
52 | return |
|
51 | end |
|
53 | end |
|
52 | @user = User.new(params[:user]) |
|
54 | @user = User.new(params[:user]) |
@@ -71,96 +73,84 | |||||
|
71 | @user = User.find_by_login(login) |
|
73 | @user = User.find_by_login(login) |
|
72 | if (@user) and (@user.verify_activation_key(key)) |
|
74 | if (@user) and (@user.verify_activation_key(key)) |
|
73 | if @user.valid? # check uniquenss of email |
|
75 | if @user.valid? # check uniquenss of email |
|
74 | @user.activated = true |
|
76 | @user.activated = true |
|
75 | @user.save |
|
77 | @user.save |
|
76 | @result = :successful |
|
78 | @result = :successful |
|
77 | else |
|
79 | else |
|
78 | @result = :email_used |
|
80 | @result = :email_used |
|
79 | end |
|
81 | end |
|
80 | else |
|
82 | else |
|
81 | @result = :failed |
|
83 | @result = :failed |
|
82 | end |
|
84 | end |
|
83 | render :action => 'confirm', :layout => 'empty' |
|
85 | render :action => 'confirm', :layout => 'empty' |
|
84 | end |
|
86 | end |
|
85 |
|
87 | ||
|
86 | def forget |
|
88 | def forget |
|
87 | render :action => 'forget', :layout => 'empty' |
|
89 | render :action => 'forget', :layout => 'empty' |
|
88 | end |
|
90 | end |
|
89 |
|
91 | ||
|
90 | def retrieve_password |
|
92 | def retrieve_password |
|
91 | email = params[:email] |
|
93 | email = params[:email] |
|
92 | user = User.find_by_email(email) |
|
94 | user = User.find_by_email(email) |
|
93 | if user |
|
95 | if user |
|
94 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
96 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
95 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
97 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
96 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
98 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
97 | else |
|
99 | else |
|
98 | user.password = user.password_confirmation = User.random_password |
|
100 | user.password = user.password_confirmation = User.random_password |
|
99 | user.save |
|
101 | user.save |
|
100 | send_new_password_email(user) |
|
102 | send_new_password_email(user) |
|
101 | flash[:notice] = 'New password has been mailed to you.' |
|
103 | flash[:notice] = 'New password has been mailed to you.' |
|
102 | end |
|
104 | end |
|
103 | else |
|
105 | else |
|
104 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
106 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
105 | end |
|
107 | end |
|
106 | redirect_to :action => 'forget' |
|
108 | redirect_to :action => 'forget' |
|
107 | end |
|
109 | end |
|
108 |
|
110 | ||
|
109 | protected |
|
111 | protected |
|
110 |
|
112 | ||
|
111 | def verify_online_registration |
|
113 | def verify_online_registration |
|
112 | if !GraderConfiguration['system.online_registration'] |
|
114 | if !GraderConfiguration['system.online_registration'] |
|
113 | redirect_to :controller => 'main', :action => 'login' |
|
115 | redirect_to :controller => 'main', :action => 'login' |
|
114 | end |
|
116 | end |
|
115 | end |
|
117 | end |
|
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) |
|
123 | home_url = url_for(:controller => 'main', :action => 'index') |
|
124 | home_url = url_for(:controller => 'main', :action => 'index') |
|
124 | mail_subject = "[#{contest_name}] Confirmation" |
|
125 | mail_subject = "[#{contest_name}] Confirmation" |
|
125 | mail_body = t('registration.email_body', { |
|
126 | mail_body = t('registration.email_body', { |
|
126 | :full_name => user.full_name, |
|
127 | :full_name => user.full_name, |
|
127 | :contest_name => contest_name, |
|
128 | :contest_name => contest_name, |
|
128 | :login => user.login, |
|
129 | :login => user.login, |
|
129 | :password => user.password, |
|
130 | :password => user.password, |
|
130 | :activation_url => activation_url, |
|
131 | :activation_url => activation_url, |
|
131 | :admin_email => admin_email |
|
132 | :admin_email => admin_email |
|
132 | }) |
|
133 | }) |
|
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, |
|
150 | :contest_name => contest_name, |
|
145 | :contest_name => contest_name, |
|
151 | :login => user.login, |
|
146 | :login => user.login, |
|
152 | :password => user.password, |
|
147 | :password => user.password, |
|
153 | :admin_email => admin_email |
|
148 | :admin_email => admin_email |
|
154 | }) |
|
149 | }) |
|
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,36 +1,30 | |||||
|
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 |
|
36 |
|
30 |
You need to be logged in to leave comments.
Login now