Description:
update errors.add_to_base("x") to Rails 3 errors.add(:base,"x")
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r347:6d2339b98fac - - 6 files changed: 12 inserted, 12 deleted
@@ -24,97 +24,97 | |||
|
24 | 24 | |
|
25 | 25 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
26 | 26 | # assigned action login as a default action. |
|
27 | 27 | def index |
|
28 | 28 | redirect_to :action => 'login' |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def login |
|
32 | 32 | saved_notice = flash[:notice] |
|
33 | 33 | reset_session |
|
34 | 34 | flash.now[:notice] = saved_notice |
|
35 | 35 | |
|
36 | 36 | # EXPERIMENT: |
|
37 | 37 | # Hide login if in single user mode and the url does not |
|
38 | 38 | # explicitly specify /login |
|
39 | 39 | # |
|
40 | 40 | # logger.info "PATH: #{request.path}" |
|
41 | 41 | # if GraderConfiguration['system.single_user_mode'] and |
|
42 | 42 | # request.path!='/main/login' |
|
43 | 43 | # @hidelogin = true |
|
44 | 44 | # end |
|
45 | 45 | |
|
46 | 46 | @announcements = Announcement.find_for_frontpage |
|
47 | 47 | render :action => 'login', :layout => 'empty' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def list |
|
51 | 51 | prepare_list_information |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def help |
|
55 | 55 | @user = User.find(session[:user_id]) |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def submit |
|
59 | 59 | user = User.find(session[:user_id]) |
|
60 | 60 | |
|
61 | 61 | @submission = Submission.new |
|
62 | 62 | @submission.problem_id = params[:submission][:problem_id] |
|
63 | 63 | @submission.user = user |
|
64 | 64 | @submission.language_id = 0 |
|
65 | 65 | if (params['file']) and (params['file']!='') |
|
66 | 66 | @submission.source = params['file'].read |
|
67 | 67 | @submission.source_filename = params['file'].original_filename |
|
68 | 68 | end |
|
69 | 69 | @submission.submitted_at = Time.new.gmtime |
|
70 | 70 | |
|
71 | 71 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
72 |
- @submission.errors.add |
|
|
72 | + @submission.errors.add(:base,"The contest is over.") | |
|
73 | 73 | prepare_list_information |
|
74 | 74 | render :action => 'list' and return |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | if @submission.valid? |
|
78 | 78 | if @submission.save == false |
|
79 | 79 | flash[:notice] = 'Error saving your submission' |
|
80 | 80 | elsif Task.create(:submission_id => @submission.id, |
|
81 | 81 | :status => Task::STATUS_INQUEUE) == false |
|
82 | 82 | flash[:notice] = 'Error adding your submission to task queue' |
|
83 | 83 | end |
|
84 | 84 | else |
|
85 | 85 | prepare_list_information |
|
86 | 86 | render :action => 'list' and return |
|
87 | 87 | end |
|
88 | 88 | redirect_to :action => 'list' |
|
89 | 89 | end |
|
90 | 90 | |
|
91 | 91 | def source |
|
92 | 92 | submission = Submission.find(params[:id]) |
|
93 | 93 | if ((submission.user_id == session[:user_id]) and |
|
94 | 94 | (submission.problem != nil) and |
|
95 | 95 | (submission.problem.available)) |
|
96 | 96 | send_data(submission.source, |
|
97 | 97 | {:filename => submission.download_filename, |
|
98 | 98 | :type => 'text/plain'}) |
|
99 | 99 | else |
|
100 | 100 | flash[:notice] = 'Error viewing source' |
|
101 | 101 | redirect_to :action => 'list' |
|
102 | 102 | end |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | def compiler_msg |
|
106 | 106 | @submission = Submission.find(params[:id]) |
|
107 | 107 | if @submission.user_id == session[:user_id] |
|
108 | 108 | render :action => 'compiler_msg', :layout => 'empty' |
|
109 | 109 | else |
|
110 | 110 | flash[:notice] = 'Error viewing source' |
|
111 | 111 | redirect_to :action => 'list' |
|
112 | 112 | end |
|
113 | 113 | end |
|
114 | 114 | |
|
115 | 115 | def submission |
|
116 | 116 | @user = User.find(session[:user_id]) |
|
117 | 117 | @problems = @user.available_problems |
|
118 | 118 | if params[:id]==nil |
|
119 | 119 | @problem = nil |
|
120 | 120 | @submissions = nil |
@@ -1,77 +1,77 | |||
|
1 | 1 | class TestController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :check_viewability |
|
4 | 4 | |
|
5 | 5 | # |
|
6 | 6 | # COMMENT OUT: filter in each action instead |
|
7 | 7 | # |
|
8 | 8 | # before_filter :verify_time_limit, :only => [:submit] |
|
9 | 9 | |
|
10 | 10 | verify :method => :post, :only => [:submit], |
|
11 | 11 | :redirect_to => { :action => :index } |
|
12 | 12 | |
|
13 | 13 | def index |
|
14 | 14 | prepare_index_information |
|
15 | 15 | end |
|
16 | 16 | |
|
17 | 17 | def submit |
|
18 | 18 | @user = User.find(session[:user_id]) |
|
19 | 19 | |
|
20 | 20 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
21 | 21 | |
|
22 | 22 | if ! @submitted_test_request.errors.empty? |
|
23 | 23 | prepare_index_information |
|
24 | 24 | render :action => 'index' and return |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | if GraderConfiguration.time_limit_mode? |
|
28 | 28 | if @user.contest_finished? |
|
29 |
- @submitted_test_request.errors.add |
|
|
29 | + @submitted_test_request.errors.add(:base,'Contest is over.') | |
|
30 | 30 | prepare_index_information |
|
31 | 31 | render :action => 'index' and return |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | if !GraderConfiguration.allow_test_request(@user) |
|
35 | 35 | prepare_index_information |
|
36 | 36 | flash[:notice] = 'Test request is not allowed during the last 30 minutes' |
|
37 | 37 | redirect_to :action => 'index' and return |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | if @submitted_test_request.save |
|
42 | 42 | redirect_to :action => 'index' |
|
43 | 43 | else |
|
44 | 44 | prepare_index_information |
|
45 | 45 | render :action => 'index' |
|
46 | 46 | end |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def read |
|
50 | 50 | user = User.find(session[:user_id]) |
|
51 | 51 | begin |
|
52 | 52 | test_request = TestRequest.find(params[:id]) |
|
53 | 53 | rescue |
|
54 | 54 | test_request = nil |
|
55 | 55 | end |
|
56 | 56 | if test_request==nil or test_request.user_id != user.id |
|
57 | 57 | flash[:notice] = 'Invalid output' |
|
58 | 58 | redirect_to :action => 'index' |
|
59 | 59 | return |
|
60 | 60 | end |
|
61 | 61 | if test_request.output_file_name!=nil |
|
62 | 62 | data = File.open(test_request.output_file_name).read(2048) |
|
63 | 63 | if data==nil |
|
64 | 64 | data="" |
|
65 | 65 | end |
|
66 | 66 | send_data(data, |
|
67 | 67 | {:filename => 'output.txt', |
|
68 | 68 | :type => 'text/plain'}) |
|
69 | 69 | return |
|
70 | 70 | end |
|
71 | 71 | redirect_to :action => 'index' |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def result |
|
75 | 75 | @user = User.find(session[:user_id]) |
|
76 | 76 | begin |
|
77 | 77 | @test_request = TestRequest.find(params[:id]) |
@@ -17,97 +17,97 | |||
|
17 | 17 | |
|
18 | 18 | verify :method => :post, :only => [:chg_passwd], |
|
19 | 19 | :redirect_to => { :action => :index } |
|
20 | 20 | |
|
21 | 21 | #in_place_edit_for :user, :alias_for_editing |
|
22 | 22 | #in_place_edit_for :user, :email_for_editing |
|
23 | 23 | |
|
24 | 24 | def index |
|
25 | 25 | if !GraderConfiguration['system.user_setting_enabled'] |
|
26 | 26 | redirect_to :controller => 'main', :action => 'list' |
|
27 | 27 | else |
|
28 | 28 | @user = User.find(session[:user_id]) |
|
29 | 29 | end |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def chg_passwd |
|
33 | 33 | user = User.find(session[:user_id]) |
|
34 | 34 | user.password = params[:passwd] |
|
35 | 35 | user.password_confirmation = params[:passwd_verify] |
|
36 | 36 | if user.save |
|
37 | 37 | flash[:notice] = 'password changed' |
|
38 | 38 | else |
|
39 | 39 | flash[:notice] = 'Error: password changing failed' |
|
40 | 40 | end |
|
41 | 41 | redirect_to :action => 'index' |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def new |
|
45 | 45 | @user = User.new |
|
46 | 46 | render :action => 'new', :layout => 'empty' |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def register |
|
50 | 50 | if(params[:cancel]) |
|
51 | 51 | redirect_to :controller => 'main', :action => 'login' |
|
52 | 52 | return |
|
53 | 53 | end |
|
54 | 54 | @user = User.new(params[:user]) |
|
55 | 55 | @user.password_confirmation = @user.password = User.random_password |
|
56 | 56 | @user.activated = false |
|
57 | 57 | if (@user.valid?) and (@user.save) |
|
58 | 58 | if send_confirmation_email(@user) |
|
59 | 59 | render :action => 'new_splash', :layout => 'empty' |
|
60 | 60 | else |
|
61 | 61 | @admin_email = GraderConfiguration['system.admin_email'] |
|
62 | 62 | render :action => 'email_error', :layout => 'empty' |
|
63 | 63 | end |
|
64 | 64 | else |
|
65 |
- @user.errors.add |
|
|
65 | + @user.errors.add(:base,"Email cannot be blank") if @user.email=='' | |
|
66 | 66 | render :action => 'new', :layout => 'empty' |
|
67 | 67 | end |
|
68 | 68 | end |
|
69 | 69 | |
|
70 | 70 | def confirm |
|
71 | 71 | login = params[:login] |
|
72 | 72 | key = params[:activation] |
|
73 | 73 | @user = User.find_by_login(login) |
|
74 | 74 | if (@user) and (@user.verify_activation_key(key)) |
|
75 | 75 | if @user.valid? # check uniquenss of email |
|
76 | 76 | @user.activated = true |
|
77 | 77 | @user.save |
|
78 | 78 | @result = :successful |
|
79 | 79 | else |
|
80 | 80 | @result = :email_used |
|
81 | 81 | end |
|
82 | 82 | else |
|
83 | 83 | @result = :failed |
|
84 | 84 | end |
|
85 | 85 | render :action => 'confirm', :layout => 'empty' |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def forget |
|
89 | 89 | render :action => 'forget', :layout => 'empty' |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def retrieve_password |
|
93 | 93 | email = params[:email] |
|
94 | 94 | user = User.find_by_email(email) |
|
95 | 95 | if user |
|
96 | 96 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
97 | 97 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
98 | 98 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
99 | 99 | else |
|
100 | 100 | user.password = user.password_confirmation = User.random_password |
|
101 | 101 | user.save |
|
102 | 102 | send_new_password_email(user) |
|
103 | 103 | flash[:notice] = 'New password has been mailed to you.' |
|
104 | 104 | end |
|
105 | 105 | else |
|
106 | 106 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
107 | 107 | end |
|
108 | 108 | redirect_to :action => 'forget' |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | protected |
|
112 | 112 | |
|
113 | 113 | def verify_online_registration |
@@ -1,114 +1,114 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | has_many :test_pairs, :dependent => :delete_all |
|
6 | 6 | |
|
7 | 7 | validates_presence_of :name |
|
8 | 8 | validates_format_of :name, :with => /^\w+$/ |
|
9 | 9 | validates_presence_of :full_name |
|
10 | 10 | |
|
11 | 11 | scope :available, :conditions => {:available => true} |
|
12 | 12 | |
|
13 | 13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | 14 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 | 15 | |
|
16 | 16 | def self.find_available_problems |
|
17 | 17 | Problem.available.all(:order => "date_added DESC") |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | 21 | org_problem = old_problem || Problem.new |
|
22 | 22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 23 | org_problem) |
|
24 | 24 | |
|
25 | 25 | if !problem.errors.empty? |
|
26 | 26 | return problem, 'Error importing' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | problem.full_score = 100 |
|
30 | 30 | problem.date_added = Time.new |
|
31 | 31 | problem.test_allowed = true |
|
32 | 32 | problem.output_only = false |
|
33 | 33 | problem.available = false |
|
34 | 34 | |
|
35 | 35 | if not problem.save |
|
36 | 36 | return problem, 'Error importing' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | import_to_db = params.has_key? :import_to_db |
|
40 | 40 | |
|
41 | 41 | importer = TestdataImporter.new(problem) |
|
42 | 42 | |
|
43 | 43 | if not importer.import_from_file(import_params[:file], |
|
44 | 44 | import_params[:time_limit], |
|
45 | 45 | import_params[:memory_limit], |
|
46 | 46 | import_to_db) |
|
47 |
- problem.errors.add |
|
|
47 | + problem.errors.add(:base,'Import error.') | |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | return problem, importer.log_msg |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def self.download_file_basedir |
|
54 | 54 | return "#{Rails.root}/data/tasks" |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | protected |
|
58 | 58 | |
|
59 | 59 | def self.to_i_or_default(st, default) |
|
60 | 60 | if st!='' |
|
61 | 61 | result = st.to_i |
|
62 | 62 | end |
|
63 | 63 | result ||= default |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | def self.to_f_or_default(st, default) |
|
67 | 67 | if st!='' |
|
68 | 68 | result = st.to_f |
|
69 | 69 | end |
|
70 | 70 | result ||= default |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def self.extract_params_and_check(params, problem) |
|
74 | 74 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
75 | 75 | DEFAULT_TIME_LIMIT) |
|
76 | 76 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
77 | 77 | DEFAULT_MEMORY_LIMIT) |
|
78 | 78 | |
|
79 | 79 | if time_limit<=0 or time_limit >60 |
|
80 |
- problem.errors.add |
|
|
80 | + problem.errors.add(:base,'Time limit out of range.') | |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | if memory_limit==0 and params[:memory_limit]!='0' |
|
84 |
- problem.errors.add |
|
|
84 | + problem.errors.add(:base,'Memory limit format errors.') | |
|
85 | 85 | elsif memory_limit<=0 or memory_limit >512 |
|
86 |
- problem.errors.add |
|
|
86 | + problem.errors.add(:base,'Memory limit out of range.') | |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | if params[:file]==nil or params[:file]=='' |
|
90 |
- problem.errors.add |
|
|
90 | + problem.errors.add(:base,'No testdata file.') | |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | file = params[:file] |
|
94 | 94 | |
|
95 | 95 | if !problem.errors.empty? |
|
96 | 96 | return nil, problem |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | problem.name = params[:name] |
|
100 | 100 | if params[:full_name]!='' |
|
101 | 101 | problem.full_name = params[:full_name] |
|
102 | 102 | else |
|
103 | 103 | problem.full_name = params[:name] |
|
104 | 104 | end |
|
105 | 105 | |
|
106 | 106 | return [{ |
|
107 | 107 | :time_limit => time_limit, |
|
108 | 108 | :memory_limit => memory_limit, |
|
109 | 109 | :file => file |
|
110 | 110 | }, |
|
111 | 111 | problem] |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | end |
@@ -25,102 +25,102 | |||
|
25 | 25 | |
|
26 | 26 | validates_presence_of :submission |
|
27 | 27 | validate :must_have_valid_problem |
|
28 | 28 | |
|
29 | 29 | def problem_name |
|
30 | 30 | TestRequest.name_of(self.problem) |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def language |
|
34 | 34 | self.submission.language |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def self.get_inqueue_and_change_status(status) |
|
38 | 38 | # since there will be only one grader grading TestRequest |
|
39 | 39 | # we do not need locking (hopefully) |
|
40 | 40 | |
|
41 | 41 | test_request = TestRequest.find(:first, |
|
42 | 42 | :order => "created_at", |
|
43 | 43 | :conditions => {:status=> Task::STATUS_INQUEUE}) |
|
44 | 44 | if test_request!=nil |
|
45 | 45 | test_request.status = status |
|
46 | 46 | test_request.save! |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | test_request |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | # interfacing with form |
|
53 | 53 | def self.new_from_form_params(user,params) |
|
54 | 54 | test_request = TestRequest.new |
|
55 | 55 | test_request.user = user |
|
56 | 56 | begin |
|
57 | 57 | problem = Problem.find(params[:problem_id]) |
|
58 | 58 | rescue ActiveRecord::RecordNotFound |
|
59 | 59 | problem = nil |
|
60 | 60 | end |
|
61 | 61 | test_request.problem = problem |
|
62 | 62 | if problem!=nil |
|
63 | 63 | test_request.submission = |
|
64 | 64 | Submission.find_by_user_problem_number(user.id, |
|
65 | 65 | problem.id, |
|
66 | 66 | params[:submission_number]) |
|
67 | 67 | else |
|
68 | 68 | test_request.submission = nil |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | # checks if the user submits any input file |
|
72 | 72 | if params[:input_file]==nil or params[:input_file]=="" |
|
73 |
- test_request.errors.add |
|
|
73 | + test_request.errors.add(:base,"No input submitted.") | |
|
74 | 74 | test_request.input_file_name = nil |
|
75 | 75 | else |
|
76 | 76 | test_request.input_file_name = save_input_file(params[:input_file], user, problem) |
|
77 | 77 | if test_request.input_file_name == nil |
|
78 |
- test_request.errors.add |
|
|
78 | + test_request.errors.adds(:base,"No input submitted.") | |
|
79 | 79 | end |
|
80 | 80 | if params[:additional_file]!=nil and params[:additional_file]!="" |
|
81 | 81 | save_additional_file(params[:additional_file], |
|
82 | 82 | "#{test_request.input_file_name}.files") |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | test_request.submitted_at = Time.new.gmtime |
|
86 | 86 | test_request.status_inqueue |
|
87 | 87 | test_request |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | protected |
|
91 | 91 | |
|
92 | 92 | def self.name_of(problem) |
|
93 | 93 | if problem!=nil |
|
94 | 94 | problem.name |
|
95 | 95 | else |
|
96 | 96 | "default" |
|
97 | 97 | end |
|
98 | 98 | end |
|
99 | 99 | |
|
100 | 100 | def self.random_input_file_name(user,problem) |
|
101 | 101 | problem_name = TestRequest.name_of(problem) |
|
102 | 102 | begin |
|
103 | 103 | tmpname = TEST_REQUEST_INPUT_FILE_DIR + "/#{user.login}/#{problem_name}/#{rand(10000)}" |
|
104 | 104 | end while File.exists?(tmpname) |
|
105 | 105 | tmpname |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def self.save_input_file(tempfile, user, problem) |
|
109 | 109 | new_file_name = random_input_file_name(user,problem) |
|
110 | 110 | dirname = File.dirname(new_file_name) |
|
111 | 111 | FileUtils.mkdir_p(File.dirname(new_file_name)) if !File.exists?(dirname) |
|
112 | 112 | |
|
113 | 113 | # when the user did not submit any file |
|
114 | 114 | return nil if tempfile=="" |
|
115 | 115 | |
|
116 | 116 | if tempfile.instance_of?(Tempfile) |
|
117 | 117 | tempfile.close |
|
118 | 118 | FileUtils.move(tempfile.path,new_file_name) |
|
119 | 119 | else |
|
120 | 120 | File.open(new_file_name, "wb") do |f| |
|
121 | 121 | f.write(tempfile.read) |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | 124 | new_file_name |
|
125 | 125 | end |
|
126 | 126 |
@@ -253,71 +253,71 | |||
|
253 | 253 | return problem_in_user_contests? problem |
|
254 | 254 | end |
|
255 | 255 | end |
|
256 | 256 | |
|
257 | 257 | protected |
|
258 | 258 | def encrypt_new_password |
|
259 | 259 | return if password.blank? |
|
260 | 260 | self.salt = (10+rand(90)).to_s |
|
261 | 261 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
262 | 262 | end |
|
263 | 263 | |
|
264 | 264 | def assign_default_site |
|
265 | 265 | # have to catch error when migrating (because self.site is not available). |
|
266 | 266 | begin |
|
267 | 267 | if self.site==nil |
|
268 | 268 | self.site = Site.find_by_name('default') |
|
269 | 269 | if self.site==nil |
|
270 | 270 | self.site = Site.find(1) # when 'default has be renamed' |
|
271 | 271 | end |
|
272 | 272 | end |
|
273 | 273 | rescue |
|
274 | 274 | end |
|
275 | 275 | end |
|
276 | 276 | |
|
277 | 277 | def assign_default_contest |
|
278 | 278 | # have to catch error when migrating (because self.site is not available). |
|
279 | 279 | begin |
|
280 | 280 | if self.contests.length == 0 |
|
281 | 281 | default_contest = Contest.find_by_name(GraderConfiguration['contest.default_contest_name']) |
|
282 | 282 | if default_contest |
|
283 | 283 | self.contests = [default_contest] |
|
284 | 284 | end |
|
285 | 285 | end |
|
286 | 286 | rescue |
|
287 | 287 | end |
|
288 | 288 | end |
|
289 | 289 | |
|
290 | 290 | def password_required? |
|
291 | 291 | self.hashed_password.blank? || !self.password.blank? |
|
292 | 292 | end |
|
293 | 293 | |
|
294 | 294 | def self.encrypt(string,salt) |
|
295 | 295 | Digest::SHA1.hexdigest(salt + string) |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | 298 | def uniqueness_of_email_from_activated_users |
|
299 | 299 | user = User.activated_users.find_by_email(self.email) |
|
300 | 300 | if user and (user.login != self.login) |
|
301 |
- self.errors.add |
|
|
301 | + self.errors.add(:base,"Email has already been taken") | |
|
302 | 302 | end |
|
303 | 303 | end |
|
304 | 304 | |
|
305 | 305 | def enough_time_interval_between_same_email_registrations |
|
306 | 306 | return if !self.new_record? |
|
307 | 307 | return if self.activated |
|
308 | 308 | open_user = User.find_by_email(self.email, |
|
309 | 309 | :order => 'created_at DESC') |
|
310 | 310 | if open_user and open_user.created_at and |
|
311 | 311 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
312 |
- self.errors.add |
|
|
312 | + self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") | |
|
313 | 313 | end |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def email_validation? |
|
317 | 317 | begin |
|
318 | 318 | return VALIDATE_USER_EMAILS |
|
319 | 319 | rescue |
|
320 | 320 | return false |
|
321 | 321 | end |
|
322 | 322 | end |
|
323 | 323 | end |
You need to be logged in to leave comments.
Login now