Description:
add option to disable login from multiple ip
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r525:89e2deff986b - - 6 files changed: 45 inserted, 13 deleted
@@ -1,92 +1,110 | |||||
|
1 | class ApplicationController < ActionController::Base |
|
1 | class ApplicationController < ActionController::Base |
|
2 | protect_from_forgery |
|
2 | protect_from_forgery |
|
3 |
|
3 | ||
|
4 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
4 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
|
5 | + MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' | ||
|
5 |
|
6 | ||
|
6 | def admin_authorization |
|
7 | def admin_authorization |
|
7 | return false unless authenticate |
|
8 | return false unless authenticate |
|
8 | user = User.find(session[:user_id], :include => ['roles']) |
|
9 | user = User.find(session[:user_id], :include => ['roles']) |
|
9 | unless user.admin? |
|
10 | unless user.admin? |
|
10 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
11 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
11 | redirect_to :controller => 'main', :action => 'login' unless user.admin? |
|
12 | redirect_to :controller => 'main', :action => 'login' unless user.admin? |
|
12 | return false |
|
13 | return false |
|
13 | end |
|
14 | end |
|
14 | return true |
|
15 | return true |
|
15 | end |
|
16 | end |
|
16 |
|
17 | ||
|
17 | def authorization_by_roles(allowed_roles) |
|
18 | def authorization_by_roles(allowed_roles) |
|
18 | return false unless authenticate |
|
19 | return false unless authenticate |
|
19 | user = User.find(session[:user_id]) |
|
20 | user = User.find(session[:user_id]) |
|
20 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
21 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
21 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
22 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
22 | redirect_to :controller => 'main', :action => 'login' |
|
23 | redirect_to :controller => 'main', :action => 'login' |
|
23 | return false |
|
24 | return false |
|
24 | end |
|
25 | end |
|
25 | end |
|
26 | end |
|
26 |
|
27 | ||
|
27 | protected |
|
28 | protected |
|
28 |
|
29 | ||
|
29 | def authenticate |
|
30 | def authenticate |
|
30 | unless session[:user_id] |
|
31 | unless session[:user_id] |
|
31 | flash[:notice] = 'You need to login' |
|
32 | flash[:notice] = 'You need to login' |
|
32 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
33 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
33 | flash[:notice] = 'You need to login but you cannot log in at this time' |
|
34 | flash[:notice] = 'You need to login but you cannot log in at this time' |
|
34 | end |
|
35 | end |
|
35 | redirect_to :controller => 'main', :action => 'login' |
|
36 | redirect_to :controller => 'main', :action => 'login' |
|
36 | return false |
|
37 | return false |
|
37 | end |
|
38 | end |
|
38 |
|
39 | ||
|
39 | # check if run in single user mode |
|
40 | # check if run in single user mode |
|
40 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
41 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
41 | user = User.find(session[:user_id]) |
|
42 | user = User.find(session[:user_id]) |
|
42 | if user==nil or (not user.admin?) |
|
43 | if user==nil or (not user.admin?) |
|
43 | flash[:notice] = 'You cannot log in at this time' |
|
44 | flash[:notice] = 'You cannot log in at this time' |
|
44 | redirect_to :controller => 'main', :action => 'login' |
|
45 | redirect_to :controller => 'main', :action => 'login' |
|
45 | return false |
|
46 | return false |
|
46 | end |
|
47 | end |
|
47 | return true |
|
48 | return true |
|
48 | end |
|
49 | end |
|
49 |
|
50 | ||
|
50 | if GraderConfiguration.multicontests? |
|
51 | if GraderConfiguration.multicontests? |
|
51 | user = User.find(session[:user_id]) |
|
52 | user = User.find(session[:user_id]) |
|
52 | return true if user.admin? |
|
53 | return true if user.admin? |
|
53 | begin |
|
54 | begin |
|
54 | if user.contest_stat(true).forced_logout |
|
55 | if user.contest_stat(true).forced_logout |
|
55 | flash[:notice] = 'You have been automatically logged out.' |
|
56 | flash[:notice] = 'You have been automatically logged out.' |
|
56 | redirect_to :controller => 'main', :action => 'index' |
|
57 | redirect_to :controller => 'main', :action => 'index' |
|
57 | end |
|
58 | end |
|
58 | rescue |
|
59 | rescue |
|
59 | end |
|
60 | end |
|
60 | end |
|
61 | end |
|
61 | return true |
|
62 | return true |
|
62 | end |
|
63 | end |
|
63 |
|
64 | ||
|
|
65 | + def authenticate_by_ip_address | ||
|
|
66 | + #this assume that we have already authenticate normally | ||
|
|
67 | + unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] | ||
|
|
68 | + user = User.find(session[:user_id]) | ||
|
|
69 | + if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip) | ||
|
|
70 | + flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" | ||
|
|
71 | + redirect_to :controller => 'main', :action => 'login' | ||
|
|
72 | + return false | ||
|
|
73 | + end | ||
|
|
74 | + unless user.last_ip | ||
|
|
75 | + user.last_ip = request.remote_ip | ||
|
|
76 | + user.save | ||
|
|
77 | + end | ||
|
|
78 | + end | ||
|
|
79 | + return true | ||
|
|
80 | + end | ||
|
|
81 | + | ||
|
64 | def authorization |
|
82 | def authorization |
|
65 | return false unless authenticate |
|
83 | return false unless authenticate |
|
66 | user = User.find(session[:user_id]) |
|
84 | user = User.find(session[:user_id]) |
|
67 | unless user.roles.detect { |role| |
|
85 | unless user.roles.detect { |role| |
|
68 | role.rights.detect{ |right| |
|
86 | role.rights.detect{ |right| |
|
69 | right.controller == self.class.controller_name and |
|
87 | right.controller == self.class.controller_name and |
|
70 | (right.action == 'all' or right.action == action_name) |
|
88 | (right.action == 'all' or right.action == action_name) |
|
71 | } |
|
89 | } |
|
72 | } |
|
90 | } |
|
73 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
91 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
74 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
92 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
75 | redirect_to :controller => 'main', :action => 'login' |
|
93 | redirect_to :controller => 'main', :action => 'login' |
|
76 | return false |
|
94 | return false |
|
77 | end |
|
95 | end |
|
78 | end |
|
96 | end |
|
79 |
|
97 | ||
|
80 | def verify_time_limit |
|
98 | def verify_time_limit |
|
81 | return true if session[:user_id]==nil |
|
99 | return true if session[:user_id]==nil |
|
82 | user = User.find(session[:user_id], :include => :site) |
|
100 | user = User.find(session[:user_id], :include => :site) |
|
83 | return true if user==nil or user.site == nil |
|
101 | return true if user==nil or user.site == nil |
|
84 | if user.contest_finished? |
|
102 | if user.contest_finished? |
|
85 | flash[:notice] = 'Error: the contest you are participating is over.' |
|
103 | flash[:notice] = 'Error: the contest you are participating is over.' |
|
86 | redirect_to :back |
|
104 | redirect_to :back |
|
87 | return false |
|
105 | return false |
|
88 | end |
|
106 | end |
|
89 | return true |
|
107 | return true |
|
90 | end |
|
108 | end |
|
91 |
|
109 | ||
|
92 | end |
|
110 | end |
@@ -1,28 +1,29 | |||||
|
1 | class ConfigurationsController < ApplicationController |
|
1 | class ConfigurationsController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate |
|
3 | before_filter :authenticate |
|
4 | before_filter { |controller| controller.authorization_by_roles(['admin'])} |
|
4 | before_filter { |controller| controller.authorization_by_roles(['admin'])} |
|
5 |
|
5 | ||
|
6 |
|
6 | ||
|
7 | def index |
|
7 | def index |
|
8 | @configurations = GraderConfiguration.find(:all, |
|
8 | @configurations = GraderConfiguration.find(:all, |
|
9 | :order => '`key`') |
|
9 | :order => '`key`') |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | def reload |
|
12 | def reload |
|
13 | GraderConfiguration.reload |
|
13 | GraderConfiguration.reload |
|
14 | redirect_to :action => 'index' |
|
14 | redirect_to :action => 'index' |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def update |
|
17 | def update |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
|
19 | + User.clear_last_login if @config.key = 'multiple_ip_login' and @config.value == 'true' and params[:grader_configuration][:value] == 'false' | ||
|
19 | respond_to do |format| |
|
20 | respond_to do |format| |
|
20 | if @config.update_attributes(params[:grader_configuration]) |
|
21 | if @config.update_attributes(params[:grader_configuration]) |
|
21 | format.json { head :ok } |
|
22 | format.json { head :ok } |
|
22 | else |
|
23 | else |
|
23 | format.json { respond_with_bip(@config) } |
|
24 | format.json { respond_with_bip(@config) } |
|
24 | end |
|
25 | end |
|
25 | end |
|
26 | end |
|
26 | end |
|
27 | end |
|
27 |
|
28 | ||
|
28 | end |
|
29 | end |
@@ -1,111 +1,113 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | before_filter :check_viewability, :except => [:index, :login] |
|
4 | before_filter :check_viewability, :except => [:index, :login] |
|
5 |
|
5 | ||
|
6 | append_before_filter :confirm_and_update_start_time, |
|
6 | append_before_filter :confirm_and_update_start_time, |
|
7 | :except => [:index, |
|
7 | :except => [:index, |
|
8 | :login, |
|
8 | :login, |
|
9 | :confirm_contest_start] |
|
9 | :confirm_contest_start] |
|
10 |
|
10 | ||
|
11 | # to prevent log in box to be shown when user logged out of the |
|
11 | # to prevent log in box to be shown when user logged out of the |
|
12 | # system only in some tab |
|
12 | # system only in some tab |
|
13 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
13 | prepend_before_filter :reject_announcement_refresh_when_logged_out, |
|
14 | :only => [:announcements] |
|
14 | :only => [:announcements] |
|
15 |
|
15 | ||
|
|
16 | + before_filter :authenticate_by_ip_address, :only => [:list] | ||
|
|
17 | + | ||
|
16 | # COMMENTED OUT: filter in each action instead |
|
18 | # COMMENTED OUT: filter in each action instead |
|
17 | # before_filter :verify_time_limit, :only => [:submit] |
|
19 | # before_filter :verify_time_limit, :only => [:submit] |
|
18 |
|
20 | ||
|
19 | verify :method => :post, :only => [:submit], |
|
21 | verify :method => :post, :only => [:submit], |
|
20 | :redirect_to => { :action => :index } |
|
22 | :redirect_to => { :action => :index } |
|
21 |
|
23 | ||
|
22 | # COMMENT OUT: only need when having high load |
|
24 | # COMMENT OUT: only need when having high load |
|
23 | # caches_action :index, :login |
|
25 | # caches_action :index, :login |
|
24 |
|
26 | ||
|
25 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
27 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
26 | # assigned action login as a default action. |
|
28 | # assigned action login as a default action. |
|
27 | def index |
|
29 | def index |
|
28 | redirect_to :action => 'login' |
|
30 | redirect_to :action => 'login' |
|
29 | end |
|
31 | end |
|
30 |
|
32 | ||
|
31 | def login |
|
33 | def login |
|
32 | saved_notice = flash[:notice] |
|
34 | saved_notice = flash[:notice] |
|
33 | reset_session |
|
35 | reset_session |
|
34 | flash.now[:notice] = saved_notice |
|
36 | flash.now[:notice] = saved_notice |
|
35 |
|
37 | ||
|
36 | # EXPERIMENT: |
|
38 | # EXPERIMENT: |
|
37 | # Hide login if in single user mode and the url does not |
|
39 | # Hide login if in single user mode and the url does not |
|
38 | # explicitly specify /login |
|
40 | # explicitly specify /login |
|
39 | # |
|
41 | # |
|
40 | # logger.info "PATH: #{request.path}" |
|
42 | # logger.info "PATH: #{request.path}" |
|
41 | # if GraderConfiguration['system.single_user_mode'] and |
|
43 | # if GraderConfiguration['system.single_user_mode'] and |
|
42 | # request.path!='/main/login' |
|
44 | # request.path!='/main/login' |
|
43 | # @hidelogin = true |
|
45 | # @hidelogin = true |
|
44 | # end |
|
46 | # end |
|
45 |
|
47 | ||
|
46 | @announcements = Announcement.find_for_frontpage |
|
48 | @announcements = Announcement.find_for_frontpage |
|
47 | render :action => 'login', :layout => 'empty' |
|
49 | render :action => 'login', :layout => 'empty' |
|
48 | end |
|
50 | end |
|
49 |
|
51 | ||
|
50 | def list |
|
52 | def list |
|
51 | prepare_list_information |
|
53 | prepare_list_information |
|
52 | end |
|
54 | end |
|
53 |
|
55 | ||
|
54 | def help |
|
56 | def help |
|
55 | @user = User.find(session[:user_id]) |
|
57 | @user = User.find(session[:user_id]) |
|
56 | end |
|
58 | end |
|
57 |
|
59 | ||
|
58 | def submit |
|
60 | def submit |
|
59 | user = User.find(session[:user_id]) |
|
61 | user = User.find(session[:user_id]) |
|
60 |
|
62 | ||
|
61 | @submission = Submission.new |
|
63 | @submission = Submission.new |
|
62 | @submission.problem_id = params[:submission][:problem_id] |
|
64 | @submission.problem_id = params[:submission][:problem_id] |
|
63 | @submission.user = user |
|
65 | @submission.user = user |
|
64 | @submission.language_id = 0 |
|
66 | @submission.language_id = 0 |
|
65 | if (params['file']) and (params['file']!='') |
|
67 | if (params['file']) and (params['file']!='') |
|
66 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
68 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
67 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
69 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
68 | @submission.source_filename = params['file'].original_filename |
|
70 | @submission.source_filename = params['file'].original_filename |
|
69 | end |
|
71 | end |
|
70 | @submission.submitted_at = Time.new.gmtime |
|
72 | @submission.submitted_at = Time.new.gmtime |
|
71 | @submission.ip_address = request.remote_ip |
|
73 | @submission.ip_address = request.remote_ip |
|
72 |
|
74 | ||
|
73 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
75 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
74 | @submission.errors.add(:base,"The contest is over.") |
|
76 | @submission.errors.add(:base,"The contest is over.") |
|
75 | prepare_list_information |
|
77 | prepare_list_information |
|
76 | render :action => 'list' and return |
|
78 | render :action => 'list' and return |
|
77 | end |
|
79 | end |
|
78 |
|
80 | ||
|
79 | if @submission.valid? |
|
81 | if @submission.valid? |
|
80 | if @submission.save == false |
|
82 | if @submission.save == false |
|
81 | flash[:notice] = 'Error saving your submission' |
|
83 | flash[:notice] = 'Error saving your submission' |
|
82 | elsif Task.create(:submission_id => @submission.id, |
|
84 | elsif Task.create(:submission_id => @submission.id, |
|
83 | :status => Task::STATUS_INQUEUE) == false |
|
85 | :status => Task::STATUS_INQUEUE) == false |
|
84 | flash[:notice] = 'Error adding your submission to task queue' |
|
86 | flash[:notice] = 'Error adding your submission to task queue' |
|
85 | end |
|
87 | end |
|
86 | else |
|
88 | else |
|
87 | prepare_list_information |
|
89 | prepare_list_information |
|
88 | render :action => 'list' and return |
|
90 | render :action => 'list' and return |
|
89 | end |
|
91 | end |
|
90 | redirect_to :action => 'list' |
|
92 | redirect_to :action => 'list' |
|
91 | end |
|
93 | end |
|
92 |
|
94 | ||
|
93 | def source |
|
95 | def source |
|
94 | submission = Submission.find(params[:id]) |
|
96 | submission = Submission.find(params[:id]) |
|
95 | if ((submission.user_id == session[:user_id]) and |
|
97 | if ((submission.user_id == session[:user_id]) and |
|
96 | (submission.problem != nil) and |
|
98 | (submission.problem != nil) and |
|
97 | (submission.problem.available)) |
|
99 | (submission.problem.available)) |
|
98 | send_data(submission.source, |
|
100 | send_data(submission.source, |
|
99 | {:filename => submission.download_filename, |
|
101 | {:filename => submission.download_filename, |
|
100 | :type => 'text/plain'}) |
|
102 | :type => 'text/plain'}) |
|
101 | else |
|
103 | else |
|
102 | flash[:notice] = 'Error viewing source' |
|
104 | flash[:notice] = 'Error viewing source' |
|
103 | redirect_to :action => 'list' |
|
105 | redirect_to :action => 'list' |
|
104 | end |
|
106 | end |
|
105 | end |
|
107 | end |
|
106 |
|
108 | ||
|
107 | def compiler_msg |
|
109 | def compiler_msg |
|
108 | @submission = Submission.find(params[:id]) |
|
110 | @submission = Submission.find(params[:id]) |
|
109 | if @submission.user_id == session[:user_id] |
|
111 | if @submission.user_id == session[:user_id] |
|
110 | render :action => 'compiler_msg', :layout => 'empty' |
|
112 | render :action => 'compiler_msg', :layout => 'empty' |
|
111 | else |
|
113 | else |
@@ -214,163 +214,167 | |||||
|
214 | end |
|
214 | end |
|
215 |
|
215 | ||
|
216 | def contest_finished? |
|
216 | def contest_finished? |
|
217 | if GraderConfiguration.contest_mode? |
|
217 | if GraderConfiguration.contest_mode? |
|
218 | return false if site==nil |
|
218 | return false if site==nil |
|
219 | return site.finished? |
|
219 | return site.finished? |
|
220 | elsif GraderConfiguration.indv_contest_mode? |
|
220 | elsif GraderConfiguration.indv_contest_mode? |
|
221 | return false if self.contest_stat(true)==nil |
|
221 | return false if self.contest_stat(true)==nil |
|
222 | return contest_time_left == 0 |
|
222 | return contest_time_left == 0 |
|
223 | else |
|
223 | else |
|
224 | return false |
|
224 | return false |
|
225 | end |
|
225 | end |
|
226 | end |
|
226 | end |
|
227 |
|
227 | ||
|
228 | def contest_started? |
|
228 | def contest_started? |
|
229 | if GraderConfiguration.indv_contest_mode? |
|
229 | if GraderConfiguration.indv_contest_mode? |
|
230 | stat = self.contest_stat |
|
230 | stat = self.contest_stat |
|
231 | return ((stat != nil) and (stat.started_at != nil)) |
|
231 | return ((stat != nil) and (stat.started_at != nil)) |
|
232 | elsif GraderConfiguration.contest_mode? |
|
232 | elsif GraderConfiguration.contest_mode? |
|
233 | return true if site==nil |
|
233 | return true if site==nil |
|
234 | return site.started |
|
234 | return site.started |
|
235 | else |
|
235 | else |
|
236 | return true |
|
236 | return true |
|
237 | end |
|
237 | end |
|
238 | end |
|
238 | end |
|
239 |
|
239 | ||
|
240 | def update_start_time |
|
240 | def update_start_time |
|
241 | stat = self.contest_stat |
|
241 | stat = self.contest_stat |
|
242 | if stat == nil or stat.started_at == nil |
|
242 | if stat == nil or stat.started_at == nil |
|
243 | stat ||= UserContestStat.new(:user => self) |
|
243 | stat ||= UserContestStat.new(:user => self) |
|
244 | stat.started_at = Time.now.gmtime |
|
244 | stat.started_at = Time.now.gmtime |
|
245 | stat.save |
|
245 | stat.save |
|
246 | end |
|
246 | end |
|
247 | end |
|
247 | end |
|
248 |
|
248 | ||
|
249 | def problem_in_user_contests?(problem) |
|
249 | def problem_in_user_contests?(problem) |
|
250 | problem_contests = problem.contests.all |
|
250 | problem_contests = problem.contests.all |
|
251 |
|
251 | ||
|
252 | if problem_contests.length == 0 # this is public contest |
|
252 | if problem_contests.length == 0 # this is public contest |
|
253 | return true |
|
253 | return true |
|
254 | end |
|
254 | end |
|
255 |
|
255 | ||
|
256 | contests.each do |contest| |
|
256 | contests.each do |contest| |
|
257 | if problem_contests.find {|c| c.id == contest.id } |
|
257 | if problem_contests.find {|c| c.id == contest.id } |
|
258 | return true |
|
258 | return true |
|
259 | end |
|
259 | end |
|
260 | end |
|
260 | end |
|
261 | return false |
|
261 | return false |
|
262 | end |
|
262 | end |
|
263 |
|
263 | ||
|
264 | def available_problems_group_by_contests |
|
264 | def available_problems_group_by_contests |
|
265 | contest_problems = [] |
|
265 | contest_problems = [] |
|
266 | pin = {} |
|
266 | pin = {} |
|
267 | contests.enabled.each do |contest| |
|
267 | contests.enabled.each do |contest| |
|
268 | available_problems = contest.problems.available |
|
268 | available_problems = contest.problems.available |
|
269 | contest_problems << { |
|
269 | contest_problems << { |
|
270 | :contest => contest, |
|
270 | :contest => contest, |
|
271 | :problems => available_problems |
|
271 | :problems => available_problems |
|
272 | } |
|
272 | } |
|
273 | available_problems.each {|p| pin[p.id] = true} |
|
273 | available_problems.each {|p| pin[p.id] = true} |
|
274 | end |
|
274 | end |
|
275 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
275 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
276 | contest_problems << { |
|
276 | contest_problems << { |
|
277 | :contest => nil, |
|
277 | :contest => nil, |
|
278 | :problems => other_avaiable_problems |
|
278 | :problems => other_avaiable_problems |
|
279 | } |
|
279 | } |
|
280 | return contest_problems |
|
280 | return contest_problems |
|
281 | end |
|
281 | end |
|
282 |
|
282 | ||
|
283 | def available_problems |
|
283 | def available_problems |
|
284 | if not GraderConfiguration.multicontests? |
|
284 | if not GraderConfiguration.multicontests? |
|
285 | return Problem.find_available_problems |
|
285 | return Problem.find_available_problems |
|
286 | else |
|
286 | else |
|
287 | contest_problems = [] |
|
287 | contest_problems = [] |
|
288 | pin = {} |
|
288 | pin = {} |
|
289 | contests.enabled.each do |contest| |
|
289 | contests.enabled.each do |contest| |
|
290 | contest.problems.available.each do |problem| |
|
290 | contest.problems.available.each do |problem| |
|
291 | if not pin.has_key? problem.id |
|
291 | if not pin.has_key? problem.id |
|
292 | contest_problems << problem |
|
292 | contest_problems << problem |
|
293 | end |
|
293 | end |
|
294 | pin[problem.id] = true |
|
294 | pin[problem.id] = true |
|
295 | end |
|
295 | end |
|
296 | end |
|
296 | end |
|
297 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
297 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
298 | return contest_problems + other_avaiable_problems |
|
298 | return contest_problems + other_avaiable_problems |
|
299 | end |
|
299 | end |
|
300 | end |
|
300 | end |
|
301 |
|
301 | ||
|
302 | def can_view_problem?(problem) |
|
302 | def can_view_problem?(problem) |
|
303 | if not GraderConfiguration.multicontests? |
|
303 | if not GraderConfiguration.multicontests? |
|
304 | return problem.available |
|
304 | return problem.available |
|
305 | else |
|
305 | else |
|
306 | return problem_in_user_contests? problem |
|
306 | return problem_in_user_contests? problem |
|
307 | end |
|
307 | end |
|
308 | end |
|
308 | end |
|
309 |
|
309 | ||
|
|
310 | + def self.clear_last_login | ||
|
|
311 | + User.update_all(:last_ip => nil) | ||
|
|
312 | + end | ||
|
|
313 | + | ||
|
310 | protected |
|
314 | protected |
|
311 | def encrypt_new_password |
|
315 | def encrypt_new_password |
|
312 | return if password.blank? |
|
316 | return if password.blank? |
|
313 | self.salt = (10+rand(90)).to_s |
|
317 | self.salt = (10+rand(90)).to_s |
|
314 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
318 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
315 | end |
|
319 | end |
|
316 |
|
320 | ||
|
317 | def assign_default_site |
|
321 | def assign_default_site |
|
318 | # have to catch error when migrating (because self.site is not available). |
|
322 | # have to catch error when migrating (because self.site is not available). |
|
319 | begin |
|
323 | begin |
|
320 | if self.site==nil |
|
324 | if self.site==nil |
|
321 | self.site = Site.find_by_name('default') |
|
325 | self.site = Site.find_by_name('default') |
|
322 | if self.site==nil |
|
326 | if self.site==nil |
|
323 | self.site = Site.find(1) # when 'default has be renamed' |
|
327 | self.site = Site.find(1) # when 'default has be renamed' |
|
324 | end |
|
328 | end |
|
325 | end |
|
329 | end |
|
326 | rescue |
|
330 | rescue |
|
327 | end |
|
331 | end |
|
328 | end |
|
332 | end |
|
329 |
|
333 | ||
|
330 | def assign_default_contest |
|
334 | def assign_default_contest |
|
331 | # have to catch error when migrating (because self.site is not available). |
|
335 | # have to catch error when migrating (because self.site is not available). |
|
332 | begin |
|
336 | begin |
|
333 | if self.contests.length == 0 |
|
337 | if self.contests.length == 0 |
|
334 | default_contest = Contest.find_by_name(GraderConfiguration['contest.default_contest_name']) |
|
338 | default_contest = Contest.find_by_name(GraderConfiguration['contest.default_contest_name']) |
|
335 | if default_contest |
|
339 | if default_contest |
|
336 | self.contests = [default_contest] |
|
340 | self.contests = [default_contest] |
|
337 | end |
|
341 | end |
|
338 | end |
|
342 | end |
|
339 | rescue |
|
343 | rescue |
|
340 | end |
|
344 | end |
|
341 | end |
|
345 | end |
|
342 |
|
346 | ||
|
343 | def password_required? |
|
347 | def password_required? |
|
344 | self.hashed_password.blank? || !self.password.blank? |
|
348 | self.hashed_password.blank? || !self.password.blank? |
|
345 | end |
|
349 | end |
|
346 |
|
350 | ||
|
347 | def self.encrypt(string,salt) |
|
351 | def self.encrypt(string,salt) |
|
348 | Digest::SHA1.hexdigest(salt + string) |
|
352 | Digest::SHA1.hexdigest(salt + string) |
|
349 | end |
|
353 | end |
|
350 |
|
354 | ||
|
351 | def uniqueness_of_email_from_activated_users |
|
355 | def uniqueness_of_email_from_activated_users |
|
352 | user = User.activated_users.find_by_email(self.email) |
|
356 | user = User.activated_users.find_by_email(self.email) |
|
353 | if user and (user.login != self.login) |
|
357 | if user and (user.login != self.login) |
|
354 | self.errors.add(:base,"Email has already been taken") |
|
358 | self.errors.add(:base,"Email has already been taken") |
|
355 | end |
|
359 | end |
|
356 | end |
|
360 | end |
|
357 |
|
361 | ||
|
358 | def enough_time_interval_between_same_email_registrations |
|
362 | def enough_time_interval_between_same_email_registrations |
|
359 | return if !self.new_record? |
|
363 | return if !self.new_record? |
|
360 | return if self.activated |
|
364 | return if self.activated |
|
361 | open_user = User.find_by_email(self.email, |
|
365 | open_user = User.find_by_email(self.email, |
|
362 | :order => 'created_at DESC') |
|
366 | :order => 'created_at DESC') |
|
363 | if open_user and open_user.created_at and |
|
367 | if open_user and open_user.created_at and |
|
364 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
368 | (open_user.created_at > Time.now.gmtime - 5.minutes) |
|
365 | self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
369 | self.errors.add(:base,"There are already unactivated registrations with this e-mail address (please wait for 5 minutes)") |
|
366 | end |
|
370 | end |
|
367 | end |
|
371 | end |
|
368 |
|
372 | ||
|
369 | def email_validation? |
|
373 | def email_validation? |
|
370 | begin |
|
374 | begin |
|
371 | return VALIDATE_USER_EMAILS |
|
375 | return VALIDATE_USER_EMAILS |
|
372 | rescue |
|
376 | rescue |
|
373 | return false |
|
377 | return false |
|
374 | end |
|
378 | end |
|
375 | end |
|
379 | end |
|
376 | end |
|
380 | end |
@@ -1,249 +1,249 | |||||
|
1 | # encoding: UTF-8 |
|
1 | # encoding: UTF-8 |
|
2 | # This file is auto-generated from the current state of the database. Instead |
|
2 | # This file is auto-generated from the current state of the database. Instead |
|
3 | # of editing this file, please use the migrations feature of Active Record to |
|
3 | # of editing this file, please use the migrations feature of Active Record to |
|
4 | # incrementally modify your database, and then regenerate this schema definition. |
|
4 | # incrementally modify your database, and then regenerate this schema definition. |
|
5 | # |
|
5 | # |
|
6 | # Note that this schema.rb definition is the authoritative source for your |
|
6 | # Note that this schema.rb definition is the authoritative source for your |
|
7 | # database schema. If you need to create the application database on another |
|
7 | # database schema. If you need to create the application database on another |
|
8 | # system, you should be using db:schema:load, not running all the migrations |
|
8 | # system, you should be using db:schema:load, not running all the migrations |
|
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
11 | # |
|
11 | # |
|
12 | # It's strongly recommended to check this file into your version control system. |
|
12 | # It's strongly recommended to check this file into your version control system. |
|
13 |
|
13 | ||
|
14 |
- ActiveRecord::Schema.define(:version => 20150 |
|
14 | + ActiveRecord::Schema.define(:version => 20150618085823) do |
|
15 |
|
15 | ||
|
16 | create_table "announcements", :force => true do |t| |
|
16 | create_table "announcements", :force => true do |t| |
|
17 | t.string "author" |
|
17 | t.string "author" |
|
18 |
- t.text "body" |
|
18 | + t.text "body" |
|
19 | t.boolean "published" |
|
19 | t.boolean "published" |
|
20 |
t.datetime "created_at", |
|
20 | t.datetime "created_at", :null => false |
|
21 |
t.datetime "updated_at", |
|
21 | t.datetime "updated_at", :null => false |
|
22 |
t.boolean "frontpage", |
|
22 | t.boolean "frontpage", :default => false |
|
23 |
t.boolean "contest_only", |
|
23 | t.boolean "contest_only", :default => false |
|
24 | t.string "title" |
|
24 | t.string "title" |
|
25 | t.string "notes" |
|
25 | t.string "notes" |
|
26 | end |
|
26 | end |
|
27 |
|
27 | ||
|
28 | create_table "contests", :force => true do |t| |
|
28 | create_table "contests", :force => true do |t| |
|
29 | t.string "title" |
|
29 | t.string "title" |
|
30 | t.boolean "enabled" |
|
30 | t.boolean "enabled" |
|
31 | t.datetime "created_at", :null => false |
|
31 | t.datetime "created_at", :null => false |
|
32 | t.datetime "updated_at", :null => false |
|
32 | t.datetime "updated_at", :null => false |
|
33 | t.string "name" |
|
33 | t.string "name" |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | create_table "contests_problems", :id => false, :force => true do |t| |
|
36 | create_table "contests_problems", :id => false, :force => true do |t| |
|
37 | t.integer "contest_id" |
|
37 | t.integer "contest_id" |
|
38 | t.integer "problem_id" |
|
38 | t.integer "problem_id" |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | create_table "contests_users", :id => false, :force => true do |t| |
|
41 | create_table "contests_users", :id => false, :force => true do |t| |
|
42 | t.integer "contest_id" |
|
42 | t.integer "contest_id" |
|
43 | t.integer "user_id" |
|
43 | t.integer "user_id" |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | create_table "countries", :force => true do |t| |
|
46 | create_table "countries", :force => true do |t| |
|
47 | t.string "name" |
|
47 | t.string "name" |
|
48 | t.datetime "created_at", :null => false |
|
48 | t.datetime "created_at", :null => false |
|
49 | t.datetime "updated_at", :null => false |
|
49 | t.datetime "updated_at", :null => false |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | create_table "descriptions", :force => true do |t| |
|
52 | create_table "descriptions", :force => true do |t| |
|
53 |
- t.text "body" |
|
53 | + t.text "body" |
|
54 | t.boolean "markdowned" |
|
54 | t.boolean "markdowned" |
|
55 |
t.datetime "created_at", |
|
55 | t.datetime "created_at", :null => false |
|
56 |
t.datetime "updated_at", |
|
56 | t.datetime "updated_at", :null => false |
|
57 | end |
|
57 | end |
|
58 |
|
58 | ||
|
59 | create_table "grader_configurations", :force => true do |t| |
|
59 | create_table "grader_configurations", :force => true do |t| |
|
60 | t.string "key" |
|
60 | t.string "key" |
|
61 | t.string "value_type" |
|
61 | t.string "value_type" |
|
62 | t.string "value" |
|
62 | t.string "value" |
|
63 |
t.datetime "created_at", |
|
63 | t.datetime "created_at", :null => false |
|
64 |
t.datetime "updated_at", |
|
64 | t.datetime "updated_at", :null => false |
|
65 |
- t.text "description" |
|
65 | + t.text "description" |
|
66 | end |
|
66 | end |
|
67 |
|
67 | ||
|
68 | create_table "grader_processes", :force => true do |t| |
|
68 | create_table "grader_processes", :force => true do |t| |
|
69 | t.string "host", :limit => 20 |
|
69 | t.string "host", :limit => 20 |
|
70 | t.integer "pid" |
|
70 | t.integer "pid" |
|
71 | t.string "mode" |
|
71 | t.string "mode" |
|
72 | t.boolean "active" |
|
72 | t.boolean "active" |
|
73 | t.datetime "created_at", :null => false |
|
73 | t.datetime "created_at", :null => false |
|
74 | t.datetime "updated_at", :null => false |
|
74 | t.datetime "updated_at", :null => false |
|
75 | t.integer "task_id" |
|
75 | t.integer "task_id" |
|
76 | t.string "task_type" |
|
76 | t.string "task_type" |
|
77 | t.boolean "terminated" |
|
77 | t.boolean "terminated" |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
80 | add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid" |
|
81 |
|
81 | ||
|
82 | create_table "languages", :force => true do |t| |
|
82 | create_table "languages", :force => true do |t| |
|
83 | t.string "name", :limit => 10 |
|
83 | t.string "name", :limit => 10 |
|
84 | t.string "pretty_name" |
|
84 | t.string "pretty_name" |
|
85 | t.string "ext", :limit => 10 |
|
85 | t.string "ext", :limit => 10 |
|
86 | t.string "common_ext" |
|
86 | t.string "common_ext" |
|
87 | end |
|
87 | end |
|
88 |
|
88 | ||
|
89 | create_table "logins", :force => true do |t| |
|
89 | create_table "logins", :force => true do |t| |
|
90 | t.integer "user_id" |
|
90 | t.integer "user_id" |
|
91 | t.string "ip_address" |
|
91 | t.string "ip_address" |
|
92 | t.datetime "created_at", :null => false |
|
92 | t.datetime "created_at", :null => false |
|
93 | t.datetime "updated_at", :null => false |
|
93 | t.datetime "updated_at", :null => false |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | create_table "messages", :force => true do |t| |
|
96 | create_table "messages", :force => true do |t| |
|
97 | t.integer "sender_id" |
|
97 | t.integer "sender_id" |
|
98 | t.integer "receiver_id" |
|
98 | t.integer "receiver_id" |
|
99 | t.integer "replying_message_id" |
|
99 | t.integer "replying_message_id" |
|
100 | - t.text "body", :limit => 16777215 |
|
100 | + t.text "body" |
|
101 | t.boolean "replied" |
|
101 | t.boolean "replied" |
|
102 |
t.datetime "created_at", |
|
102 | t.datetime "created_at", :null => false |
|
103 |
t.datetime "updated_at", |
|
103 | t.datetime "updated_at", :null => false |
|
104 | end |
|
104 | end |
|
105 |
|
105 | ||
|
106 | create_table "problems", :force => true do |t| |
|
106 | create_table "problems", :force => true do |t| |
|
107 | t.string "name", :limit => 30 |
|
107 | t.string "name", :limit => 30 |
|
108 | t.string "full_name" |
|
108 | t.string "full_name" |
|
109 | t.integer "full_score" |
|
109 | t.integer "full_score" |
|
110 | t.date "date_added" |
|
110 | t.date "date_added" |
|
111 | t.boolean "available" |
|
111 | t.boolean "available" |
|
112 | t.string "url" |
|
112 | t.string "url" |
|
113 | t.integer "description_id" |
|
113 | t.integer "description_id" |
|
114 | t.boolean "test_allowed" |
|
114 | t.boolean "test_allowed" |
|
115 | t.boolean "output_only" |
|
115 | t.boolean "output_only" |
|
116 | t.string "description_filename" |
|
116 | t.string "description_filename" |
|
117 | end |
|
117 | end |
|
118 |
|
118 | ||
|
119 | create_table "rights", :force => true do |t| |
|
119 | create_table "rights", :force => true do |t| |
|
120 | t.string "name" |
|
120 | t.string "name" |
|
121 | t.string "controller" |
|
121 | t.string "controller" |
|
122 | t.string "action" |
|
122 | t.string "action" |
|
123 | end |
|
123 | end |
|
124 |
|
124 | ||
|
125 | create_table "rights_roles", :id => false, :force => true do |t| |
|
125 | create_table "rights_roles", :id => false, :force => true do |t| |
|
126 | t.integer "right_id" |
|
126 | t.integer "right_id" |
|
127 | t.integer "role_id" |
|
127 | t.integer "role_id" |
|
128 | end |
|
128 | end |
|
129 |
|
129 | ||
|
130 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
130 | add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id" |
|
131 |
|
131 | ||
|
132 | create_table "roles", :force => true do |t| |
|
132 | create_table "roles", :force => true do |t| |
|
133 | t.string "name" |
|
133 | t.string "name" |
|
134 | end |
|
134 | end |
|
135 |
|
135 | ||
|
136 | create_table "roles_users", :id => false, :force => true do |t| |
|
136 | create_table "roles_users", :id => false, :force => true do |t| |
|
137 | t.integer "role_id" |
|
137 | t.integer "role_id" |
|
138 | t.integer "user_id" |
|
138 | t.integer "user_id" |
|
139 | end |
|
139 | end |
|
140 |
|
140 | ||
|
141 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
141 | add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id" |
|
142 |
|
142 | ||
|
143 | create_table "sessions", :force => true do |t| |
|
143 | create_table "sessions", :force => true do |t| |
|
144 | t.string "session_id" |
|
144 | t.string "session_id" |
|
145 |
- t.text "data" |
|
145 | + t.text "data" |
|
146 | t.datetime "updated_at" |
|
146 | t.datetime "updated_at" |
|
147 | end |
|
147 | end |
|
148 |
|
148 | ||
|
149 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
149 | add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" |
|
150 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
150 | add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at" |
|
151 |
|
151 | ||
|
152 | create_table "sites", :force => true do |t| |
|
152 | create_table "sites", :force => true do |t| |
|
153 | t.string "name" |
|
153 | t.string "name" |
|
154 | t.boolean "started" |
|
154 | t.boolean "started" |
|
155 | t.datetime "start_time" |
|
155 | t.datetime "start_time" |
|
156 | t.datetime "created_at", :null => false |
|
156 | t.datetime "created_at", :null => false |
|
157 | t.datetime "updated_at", :null => false |
|
157 | t.datetime "updated_at", :null => false |
|
158 | t.integer "country_id" |
|
158 | t.integer "country_id" |
|
159 | t.string "password" |
|
159 | t.string "password" |
|
160 | end |
|
160 | end |
|
161 |
|
161 | ||
|
162 | create_table "submissions", :force => true do |t| |
|
162 | create_table "submissions", :force => true do |t| |
|
163 | t.integer "user_id" |
|
163 | t.integer "user_id" |
|
164 | t.integer "problem_id" |
|
164 | t.integer "problem_id" |
|
165 | t.integer "language_id" |
|
165 | t.integer "language_id" |
|
166 | - t.text "source", :limit => 16777215 |
|
166 | + t.text "source" |
|
167 | t.binary "binary" |
|
167 | t.binary "binary" |
|
168 | t.datetime "submitted_at" |
|
168 | t.datetime "submitted_at" |
|
169 | t.datetime "compiled_at" |
|
169 | t.datetime "compiled_at" |
|
170 |
- t.text "compiler_message" |
|
170 | + t.text "compiler_message" |
|
171 | t.datetime "graded_at" |
|
171 | t.datetime "graded_at" |
|
172 | t.integer "points" |
|
172 | t.integer "points" |
|
173 |
- t.text "grader_comment" |
|
173 | + t.text "grader_comment" |
|
174 | t.integer "number" |
|
174 | t.integer "number" |
|
175 | t.string "source_filename" |
|
175 | t.string "source_filename" |
|
176 | t.float "max_runtime" |
|
176 | t.float "max_runtime" |
|
177 | t.integer "peak_memory" |
|
177 | t.integer "peak_memory" |
|
178 | t.integer "effective_code_length" |
|
178 | t.integer "effective_code_length" |
|
179 | t.string "ip_address" |
|
179 | t.string "ip_address" |
|
180 | end |
|
180 | end |
|
181 |
|
181 | ||
|
182 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
182 | add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true |
|
183 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
183 | add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id" |
|
184 |
|
184 | ||
|
185 | create_table "tasks", :force => true do |t| |
|
185 | create_table "tasks", :force => true do |t| |
|
186 | t.integer "submission_id" |
|
186 | t.integer "submission_id" |
|
187 | t.datetime "created_at" |
|
187 | t.datetime "created_at" |
|
188 | t.integer "status" |
|
188 | t.integer "status" |
|
189 | t.datetime "updated_at" |
|
189 | t.datetime "updated_at" |
|
190 | end |
|
190 | end |
|
191 |
|
191 | ||
|
192 | create_table "test_pairs", :force => true do |t| |
|
192 | create_table "test_pairs", :force => true do |t| |
|
193 | t.integer "problem_id" |
|
193 | t.integer "problem_id" |
|
194 |
- t.text "input", :limit => |
|
194 | + t.text "input", :limit => 16777215 |
|
195 |
- t.text "solution", :limit => |
|
195 | + t.text "solution", :limit => 16777215 |
|
196 |
t.datetime "created_at", |
|
196 | t.datetime "created_at", :null => false |
|
197 |
t.datetime "updated_at", |
|
197 | t.datetime "updated_at", :null => false |
|
198 | end |
|
198 | end |
|
199 |
|
199 | ||
|
200 | create_table "test_requests", :force => true do |t| |
|
200 | create_table "test_requests", :force => true do |t| |
|
201 | t.integer "user_id" |
|
201 | t.integer "user_id" |
|
202 | t.integer "problem_id" |
|
202 | t.integer "problem_id" |
|
203 | t.integer "submission_id" |
|
203 | t.integer "submission_id" |
|
204 | t.string "input_file_name" |
|
204 | t.string "input_file_name" |
|
205 | t.string "output_file_name" |
|
205 | t.string "output_file_name" |
|
206 | t.string "running_stat" |
|
206 | t.string "running_stat" |
|
207 | t.integer "status" |
|
207 | t.integer "status" |
|
208 |
t.datetime "updated_at", |
|
208 | t.datetime "updated_at", :null => false |
|
209 | t.datetime "submitted_at" |
|
209 | t.datetime "submitted_at" |
|
210 | t.datetime "compiled_at" |
|
210 | t.datetime "compiled_at" |
|
211 |
- t.text "compiler_message" |
|
211 | + t.text "compiler_message" |
|
212 | t.datetime "graded_at" |
|
212 | t.datetime "graded_at" |
|
213 | t.string "grader_comment" |
|
213 | t.string "grader_comment" |
|
214 |
t.datetime "created_at", |
|
214 | t.datetime "created_at", :null => false |
|
215 | t.float "running_time" |
|
215 | t.float "running_time" |
|
216 | t.string "exit_status" |
|
216 | t.string "exit_status" |
|
217 | t.integer "memory_usage" |
|
217 | t.integer "memory_usage" |
|
218 | end |
|
218 | end |
|
219 |
|
219 | ||
|
220 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
220 | add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id" |
|
221 |
|
221 | ||
|
222 | create_table "user_contest_stats", :force => true do |t| |
|
222 | create_table "user_contest_stats", :force => true do |t| |
|
223 | t.integer "user_id" |
|
223 | t.integer "user_id" |
|
224 | t.datetime "started_at" |
|
224 | t.datetime "started_at" |
|
225 | t.datetime "created_at", :null => false |
|
225 | t.datetime "created_at", :null => false |
|
226 | t.datetime "updated_at", :null => false |
|
226 | t.datetime "updated_at", :null => false |
|
227 | t.boolean "forced_logout" |
|
227 | t.boolean "forced_logout" |
|
228 | end |
|
228 | end |
|
229 |
|
229 | ||
|
230 | create_table "users", :force => true do |t| |
|
230 | create_table "users", :force => true do |t| |
|
231 | t.string "login", :limit => 50 |
|
231 | t.string "login", :limit => 50 |
|
232 | t.string "full_name" |
|
232 | t.string "full_name" |
|
233 | t.string "hashed_password" |
|
233 | t.string "hashed_password" |
|
234 | t.string "salt", :limit => 5 |
|
234 | t.string "salt", :limit => 5 |
|
235 | t.string "alias" |
|
235 | t.string "alias" |
|
236 | t.string "email" |
|
236 | t.string "email" |
|
237 | t.integer "site_id" |
|
237 | t.integer "site_id" |
|
238 | t.integer "country_id" |
|
238 | t.integer "country_id" |
|
239 | t.boolean "activated", :default => false |
|
239 | t.boolean "activated", :default => false |
|
240 | t.datetime "created_at" |
|
240 | t.datetime "created_at" |
|
241 | t.datetime "updated_at" |
|
241 | t.datetime "updated_at" |
|
242 | - t.string "section" |
|
||
|
243 | t.boolean "enabled", :default => true |
|
242 | t.boolean "enabled", :default => true |
|
244 | t.string "remark" |
|
243 | t.string "remark" |
|
|
244 | + t.string "last_ip" | ||
|
245 | end |
|
245 | end |
|
246 |
|
246 | ||
|
247 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
247 | add_index "users", ["login"], :name => "index_users_on_login", :unique => true |
|
248 |
|
248 | ||
|
249 | end |
|
249 | end |
@@ -1,159 +1,166 | |||||
|
1 | CONFIGURATIONS = |
|
1 | CONFIGURATIONS = |
|
2 | [ |
|
2 | [ |
|
3 | { |
|
3 | { |
|
4 | :key => 'system.single_user_mode', |
|
4 | :key => 'system.single_user_mode', |
|
5 | :value_type => 'boolean', |
|
5 | :value_type => 'boolean', |
|
6 | :default_value => 'false', |
|
6 | :default_value => 'false', |
|
7 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
7 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
8 | }, |
|
8 | }, |
|
9 |
|
9 | ||
|
10 | { |
|
10 | { |
|
11 | :key => 'ui.front.title', |
|
11 | :key => 'ui.front.title', |
|
12 | :value_type => 'string', |
|
12 | :value_type => 'string', |
|
13 | :default_value => 'Grader' |
|
13 | :default_value => 'Grader' |
|
14 | }, |
|
14 | }, |
|
15 |
|
15 | ||
|
16 | { |
|
16 | { |
|
17 | :key => 'ui.front.welcome_message', |
|
17 | :key => 'ui.front.welcome_message', |
|
18 | :value_type => 'string', |
|
18 | :value_type => 'string', |
|
19 | :default_value => 'Welcome!' |
|
19 | :default_value => 'Welcome!' |
|
20 | }, |
|
20 | }, |
|
21 |
|
21 | ||
|
22 | { |
|
22 | { |
|
23 | :key => 'ui.show_score', |
|
23 | :key => 'ui.show_score', |
|
24 | :value_type => 'boolean', |
|
24 | :value_type => 'boolean', |
|
25 | :default_value => 'true' |
|
25 | :default_value => 'true' |
|
26 | }, |
|
26 | }, |
|
27 |
|
27 | ||
|
28 | { |
|
28 | { |
|
29 | :key => 'contest.time_limit', |
|
29 | :key => 'contest.time_limit', |
|
30 | :value_type => 'string', |
|
30 | :value_type => 'string', |
|
31 | :default_value => 'unlimited', |
|
31 | :default_value => 'unlimited', |
|
32 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.' |
|
32 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.' |
|
33 | }, |
|
33 | }, |
|
34 |
|
34 | ||
|
35 | { |
|
35 | { |
|
36 | :key => 'system.mode', |
|
36 | :key => 'system.mode', |
|
37 | :value_type => 'string', |
|
37 | :value_type => 'string', |
|
38 | :default_value => 'standard', |
|
38 | :default_value => 'standard', |
|
39 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
39 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
40 | }, |
|
40 | }, |
|
41 |
|
41 | ||
|
42 | { |
|
42 | { |
|
43 | :key => 'contest.name', |
|
43 | :key => 'contest.name', |
|
44 | :value_type => 'string', |
|
44 | :value_type => 'string', |
|
45 | :default_value => 'Grader', |
|
45 | :default_value => 'Grader', |
|
46 | :description => 'This name will be shown on the user header bar.' |
|
46 | :description => 'This name will be shown on the user header bar.' |
|
47 | }, |
|
47 | }, |
|
48 |
|
48 | ||
|
49 | { |
|
49 | { |
|
50 | :key => 'contest.multisites', |
|
50 | :key => 'contest.multisites', |
|
51 | :value_type => 'boolean', |
|
51 | :value_type => 'boolean', |
|
52 | :default_value => 'false', |
|
52 | :default_value => 'false', |
|
53 | :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.' |
|
53 | :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.' |
|
54 | }, |
|
54 | }, |
|
55 |
|
55 | ||
|
56 | { |
|
56 | { |
|
57 | :key => 'right.user_hall_of_fame', |
|
57 | :key => 'right.user_hall_of_fame', |
|
58 | :value_type => 'boolean', |
|
58 | :value_type => 'boolean', |
|
59 | :default_value => 'false', |
|
59 | :default_value => 'false', |
|
60 | :description => 'If true, any user can access hall of fame page.' |
|
60 | :description => 'If true, any user can access hall of fame page.' |
|
61 | }, |
|
61 | }, |
|
62 |
|
62 | ||
|
63 | { |
|
63 | { |
|
|
64 | + :key => 'right.multiple_ip_login', | ||
|
|
65 | + :value_type => 'boolean', | ||
|
|
66 | + :default_value => 'true', | ||
|
|
67 | + :description => 'When change from true to false, a user can login from the first IP they logged into afterward.' | ||
|
|
68 | + }, | ||
|
|
69 | + | ||
|
|
70 | + { | ||
|
64 | :key => 'right.user_view_submission', |
|
71 | :key => 'right.user_view_submission', |
|
65 | :value_type => 'boolean', |
|
72 | :value_type => 'boolean', |
|
66 | :default_value => 'false', |
|
73 | :default_value => 'false', |
|
67 | :description => 'If true, any user can view submissions of every one.' |
|
74 | :description => 'If true, any user can view submissions of every one.' |
|
68 | }, |
|
75 | }, |
|
69 |
|
76 | ||
|
70 | # If Configuration['system.online_registration'] is true, the |
|
77 | # If Configuration['system.online_registration'] is true, the |
|
71 | # system allows online registration, and will use these |
|
78 | # system allows online registration, and will use these |
|
72 | # information for sending confirmation emails. |
|
79 | # information for sending confirmation emails. |
|
73 | { |
|
80 | { |
|
74 | :key => 'system.online_registration.smtp', |
|
81 | :key => 'system.online_registration.smtp', |
|
75 | :value_type => 'string', |
|
82 | :value_type => 'string', |
|
76 | :default_value => 'smtp.somehost.com' |
|
83 | :default_value => 'smtp.somehost.com' |
|
77 | }, |
|
84 | }, |
|
78 |
|
85 | ||
|
79 | { |
|
86 | { |
|
80 | :key => 'system.online_registration.from', |
|
87 | :key => 'system.online_registration.from', |
|
81 | :value_type => 'string', |
|
88 | :value_type => 'string', |
|
82 | :default_value => 'your.email@address' |
|
89 | :default_value => 'your.email@address' |
|
83 | }, |
|
90 | }, |
|
84 |
|
91 | ||
|
85 | { |
|
92 | { |
|
86 | :key => 'system.admin_email', |
|
93 | :key => 'system.admin_email', |
|
87 | :value_type => 'string', |
|
94 | :value_type => 'string', |
|
88 | :default_value => 'admin@admin.email' |
|
95 | :default_value => 'admin@admin.email' |
|
89 | }, |
|
96 | }, |
|
90 |
|
97 | ||
|
91 | { |
|
98 | { |
|
92 | :key => 'system.user_setting_enabled', |
|
99 | :key => 'system.user_setting_enabled', |
|
93 | :value_type => 'boolean', |
|
100 | :value_type => 'boolean', |
|
94 | :default_value => 'true', |
|
101 | :default_value => 'true', |
|
95 | :description => 'If this option is true, users can change their settings' |
|
102 | :description => 'If this option is true, users can change their settings' |
|
96 | }, |
|
103 | }, |
|
97 |
|
104 | ||
|
98 | { |
|
105 | { |
|
99 | :key => 'system.user_setting_enabled', |
|
106 | :key => 'system.user_setting_enabled', |
|
100 | :value_type => 'boolean', |
|
107 | :value_type => 'boolean', |
|
101 | :default_value => 'true', |
|
108 | :default_value => 'true', |
|
102 | :description => 'If this option is true, users can change their settings' |
|
109 | :description => 'If this option is true, users can change their settings' |
|
103 | }, |
|
110 | }, |
|
104 |
|
111 | ||
|
105 | # If Configuration['contest.test_request.early_timeout'] is true |
|
112 | # If Configuration['contest.test_request.early_timeout'] is true |
|
106 | # the user will not be able to use test request at 30 minutes |
|
113 | # the user will not be able to use test request at 30 minutes |
|
107 | # before the contest ends. |
|
114 | # before the contest ends. |
|
108 | { |
|
115 | { |
|
109 | :key => 'contest.test_request.early_timeout', |
|
116 | :key => 'contest.test_request.early_timeout', |
|
110 | :value_type => 'boolean', |
|
117 | :value_type => 'boolean', |
|
111 | :default_value => 'false' |
|
118 | :default_value => 'false' |
|
112 | }, |
|
119 | }, |
|
113 |
|
120 | ||
|
114 | { |
|
121 | { |
|
115 | :key => 'system.multicontests', |
|
122 | :key => 'system.multicontests', |
|
116 | :value_type => 'boolean', |
|
123 | :value_type => 'boolean', |
|
117 | :default_value => 'false' |
|
124 | :default_value => 'false' |
|
118 | }, |
|
125 | }, |
|
119 |
|
126 | ||
|
120 | { |
|
127 | { |
|
121 | :key => 'contest.confirm_indv_contest_start', |
|
128 | :key => 'contest.confirm_indv_contest_start', |
|
122 | :value_type => 'boolean', |
|
129 | :value_type => 'boolean', |
|
123 | :default_value => 'false' |
|
130 | :default_value => 'false' |
|
124 | }, |
|
131 | }, |
|
125 |
|
132 | ||
|
126 | { |
|
133 | { |
|
127 | :key => 'contest.default_contest_name', |
|
134 | :key => 'contest.default_contest_name', |
|
128 | :value_type => 'string', |
|
135 | :value_type => 'string', |
|
129 | :default_value => 'none', |
|
136 | :default_value => 'none', |
|
130 | :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest." |
|
137 | :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest." |
|
131 | } |
|
138 | } |
|
132 |
|
139 | ||
|
133 | ] |
|
140 | ] |
|
134 |
|
141 | ||
|
135 |
|
142 | ||
|
136 | def create_configuration_key(key, |
|
143 | def create_configuration_key(key, |
|
137 | value_type, |
|
144 | value_type, |
|
138 | default_value, |
|
145 | default_value, |
|
139 | description='') |
|
146 | description='') |
|
140 | conf = (GraderConfiguration.find_by_key(key) || |
|
147 | conf = (GraderConfiguration.find_by_key(key) || |
|
141 | GraderConfiguration.new(:key => key, |
|
148 | GraderConfiguration.new(:key => key, |
|
142 | :value_type => value_type, |
|
149 | :value_type => value_type, |
|
143 | :value => default_value)) |
|
150 | :value => default_value)) |
|
144 | conf.description = description |
|
151 | conf.description = description |
|
145 | conf.save |
|
152 | conf.save |
|
146 | end |
|
153 | end |
|
147 |
|
154 | ||
|
148 | def seed_config |
|
155 | def seed_config |
|
149 | CONFIGURATIONS.each do |conf| |
|
156 | CONFIGURATIONS.each do |conf| |
|
150 | if conf.has_key? :description |
|
157 | if conf.has_key? :description |
|
151 | desc = conf[:description] |
|
158 | desc = conf[:description] |
|
152 | else |
|
159 | else |
|
153 | desc = '' |
|
160 | desc = '' |
|
154 | end |
|
161 | end |
|
155 | create_configuration_key(conf[:key], |
|
162 | create_configuration_key(conf[:key], |
|
156 | conf[:value_type], |
|
163 | conf[:value_type], |
|
157 | conf[:default_value], |
|
164 | conf[:default_value], |
|
158 | desc) |
|
165 | desc) |
|
159 | end |
|
166 | end |
You need to be logged in to leave comments.
Login now