Description:
add ip to front page, also fix seeds.rb
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r783:f1343ca4b141 - - 3 files changed: 3 inserted, 1 deleted
@@ -1,215 +1,216 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_action :check_valid_login, :except => [:login] |
|
4 | 4 | before_action :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | 6 | append_before_action :confirm_and_update_start_time, |
|
7 | 7 | :except => [:index, |
|
8 | 8 | :login, |
|
9 | 9 | :confirm_contest_start] |
|
10 | 10 | |
|
11 | 11 | # to prevent log in box to be shown when user logged out of the |
|
12 | 12 | # system only in some tab |
|
13 | 13 | prepend_before_action :reject_announcement_refresh_when_logged_out, |
|
14 | 14 | :only => [:announcements] |
|
15 | 15 | |
|
16 | 16 | before_action :authenticate_by_ip_address, :only => [:list] |
|
17 | 17 | |
|
18 | 18 | #reset login, clear session |
|
19 | 19 | #front page |
|
20 | 20 | def login |
|
21 | 21 | saved_notice = flash[:notice] |
|
22 | 22 | reset_session |
|
23 | 23 | flash.now[:notice] = saved_notice |
|
24 | + @remote_ip = request.remote_ip | |
|
24 | 25 | |
|
25 | 26 | # EXPERIMENT: |
|
26 | 27 | # Hide login if in single user mode and the url does not |
|
27 | 28 | # explicitly specify /login |
|
28 | 29 | # |
|
29 | 30 | # logger.info "PATH: #{request.path}" |
|
30 | 31 | # if GraderConfiguration['system.single_user_mode'] and |
|
31 | 32 | # request.path!='/main/login' |
|
32 | 33 | # @hidelogin = true |
|
33 | 34 | # end |
|
34 | 35 | |
|
35 | 36 | @announcements = Announcement.frontpage |
|
36 | 37 | render :action => 'login', :layout => 'empty' |
|
37 | 38 | end |
|
38 | 39 | |
|
39 | 40 | def logout |
|
40 | 41 | reset_session |
|
41 | 42 | redirect_to root_path |
|
42 | 43 | end |
|
43 | 44 | |
|
44 | 45 | def list |
|
45 | 46 | prepare_list_information |
|
46 | 47 | end |
|
47 | 48 | |
|
48 | 49 | def help |
|
49 | 50 | @user = User.find(session[:user_id]) |
|
50 | 51 | end |
|
51 | 52 | |
|
52 | 53 | def submit |
|
53 | 54 | user = User.find(session[:user_id]) |
|
54 | 55 | |
|
55 | 56 | @submission = Submission.new |
|
56 | 57 | @submission.problem_id = params[:submission][:problem_id] |
|
57 | 58 | @submission.user = user |
|
58 | 59 | @submission.language_id = 0 |
|
59 | 60 | if (params['file']) and (params['file']!='') |
|
60 | 61 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
61 | 62 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
62 | 63 | @submission.source_filename = params['file'].original_filename |
|
63 | 64 | end |
|
64 | 65 | |
|
65 | 66 | if (params[:editor_text]) |
|
66 | 67 | language = Language.find_by_id(params[:language_id]) |
|
67 | 68 | @submission.source = params[:editor_text] |
|
68 | 69 | @submission.source_filename = "live_edit.#{language.ext}" |
|
69 | 70 | @submission.language = language |
|
70 | 71 | end |
|
71 | 72 | |
|
72 | 73 | @submission.submitted_at = Time.new.gmtime |
|
73 | 74 | @submission.ip_address = request.remote_ip |
|
74 | 75 | |
|
75 | 76 | if GraderConfiguration.time_limit_mode? and user.contest_finished? |
|
76 | 77 | @submission.errors.add(:base,"The contest is over.") |
|
77 | 78 | prepare_list_information |
|
78 | 79 | render :action => 'list' and return |
|
79 | 80 | end |
|
80 | 81 | |
|
81 | 82 | if @submission.valid?(@current_user) |
|
82 | 83 | if @submission.save == false |
|
83 | 84 | flash[:notice] = 'Error saving your submission' |
|
84 | 85 | elsif Task.create(:submission_id => @submission.id, |
|
85 | 86 | :status => Task::STATUS_INQUEUE) == false |
|
86 | 87 | flash[:notice] = 'Error adding your submission to task queue' |
|
87 | 88 | end |
|
88 | 89 | else |
|
89 | 90 | prepare_list_information |
|
90 | 91 | render :action => 'list' and return |
|
91 | 92 | end |
|
92 | 93 | redirect_to edit_submission_path(@submission) |
|
93 | 94 | end |
|
94 | 95 | |
|
95 | 96 | def source |
|
96 | 97 | submission = Submission.find(params[:id]) |
|
97 | 98 | if ((submission.user_id == session[:user_id]) and |
|
98 | 99 | (submission.problem != nil) and |
|
99 | 100 | (submission.problem.available)) |
|
100 | 101 | send_data(submission.source, |
|
101 | 102 | {:filename => submission.download_filename, |
|
102 | 103 | :type => 'text/plain'}) |
|
103 | 104 | else |
|
104 | 105 | flash[:notice] = 'Error viewing source' |
|
105 | 106 | redirect_to :action => 'list' |
|
106 | 107 | end |
|
107 | 108 | end |
|
108 | 109 | |
|
109 | 110 | def compiler_msg |
|
110 | 111 | @submission = Submission.find(params[:id]) |
|
111 | 112 | if @submission.user_id == session[:user_id] |
|
112 | 113 | render :action => 'compiler_msg', :layout => 'empty' |
|
113 | 114 | else |
|
114 | 115 | flash[:notice] = 'Error viewing source' |
|
115 | 116 | redirect_to :action => 'list' |
|
116 | 117 | end |
|
117 | 118 | end |
|
118 | 119 | |
|
119 | 120 | def result |
|
120 | 121 | if !GraderConfiguration.show_grading_result |
|
121 | 122 | redirect_to :action => 'list' and return |
|
122 | 123 | end |
|
123 | 124 | @user = User.find(session[:user_id]) |
|
124 | 125 | @submission = Submission.find(params[:id]) |
|
125 | 126 | if @submission.user!=@user |
|
126 | 127 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
127 | 128 | redirect_to :action => 'list' and return |
|
128 | 129 | end |
|
129 | 130 | prepare_grading_result(@submission) |
|
130 | 131 | end |
|
131 | 132 | |
|
132 | 133 | def load_output |
|
133 | 134 | if !GraderConfiguration.show_grading_result or params[:num]==nil |
|
134 | 135 | redirect_to :action => 'list' and return |
|
135 | 136 | end |
|
136 | 137 | @user = User.find(session[:user_id]) |
|
137 | 138 | @submission = Submission.find(params[:id]) |
|
138 | 139 | if @submission.user!=@user |
|
139 | 140 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
140 | 141 | redirect_to :action => 'list' and return |
|
141 | 142 | end |
|
142 | 143 | case_num = params[:num].to_i |
|
143 | 144 | out_filename = output_filename(@user.login, |
|
144 | 145 | @submission.problem.name, |
|
145 | 146 | @submission.id, |
|
146 | 147 | case_num) |
|
147 | 148 | if !FileTest.exists?(out_filename) |
|
148 | 149 | flash[:notice] = 'Output not found.' |
|
149 | 150 | redirect_to :action => 'list' and return |
|
150 | 151 | end |
|
151 | 152 | |
|
152 | 153 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
153 | 154 | response.headers['Content-Type'] = "application/force-download" |
|
154 | 155 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
155 | 156 | response.headers["X-Sendfile"] = out_filename |
|
156 | 157 | response.headers['Content-length'] = File.size(out_filename) |
|
157 | 158 | render :nothing => true |
|
158 | 159 | else |
|
159 | 160 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
160 | 161 | end |
|
161 | 162 | end |
|
162 | 163 | |
|
163 | 164 | def error |
|
164 | 165 | @user = User.find(session[:user_id]) |
|
165 | 166 | end |
|
166 | 167 | |
|
167 | 168 | # announcement refreshing and hiding methods |
|
168 | 169 | |
|
169 | 170 | def announcements |
|
170 | 171 | if params.has_key? 'recent' |
|
171 | 172 | prepare_announcements(params[:recent]) |
|
172 | 173 | else |
|
173 | 174 | prepare_announcements |
|
174 | 175 | end |
|
175 | 176 | render(:partial => 'announcement', |
|
176 | 177 | :collection => @announcements, |
|
177 | 178 | :locals => {:announcement_effect => true}) |
|
178 | 179 | end |
|
179 | 180 | |
|
180 | 181 | def confirm_contest_start |
|
181 | 182 | user = User.find(session[:user_id]) |
|
182 | 183 | if request.method == 'POST' |
|
183 | 184 | user.update_start_time |
|
184 | 185 | redirect_to :action => 'list' |
|
185 | 186 | else |
|
186 | 187 | @contests = user.contests |
|
187 | 188 | @user = user |
|
188 | 189 | end |
|
189 | 190 | end |
|
190 | 191 | |
|
191 | 192 | protected |
|
192 | 193 | |
|
193 | 194 | def prepare_announcements(recent=nil) |
|
194 | 195 | if GraderConfiguration.show_tasks_to?(@user) |
|
195 | 196 | @announcements = Announcement.published(true) |
|
196 | 197 | else |
|
197 | 198 | @announcements = Announcement.published |
|
198 | 199 | end |
|
199 | 200 | if recent!=nil |
|
200 | 201 | recent_id = recent.to_i |
|
201 | 202 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
202 | 203 | end |
|
203 | 204 | end |
|
204 | 205 | |
|
205 | 206 | def prepare_list_information |
|
206 | 207 | @user = User.find(session[:user_id]) |
|
207 | 208 | if not GraderConfiguration.multicontests? |
|
208 | 209 | @problems = @user.available_problems |
|
209 | 210 | else |
|
210 | 211 | @contest_problems = @user.available_problems_group_by_contests |
|
211 | 212 | @problems = @user.available_problems |
|
212 | 213 | end |
|
213 | 214 | @prob_submissions = {} |
|
214 | 215 | @problems.each do |p| |
|
215 | 216 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
@@ -1,11 +1,12 | |||
|
1 | 1 | %h1= GraderConfiguration['ui.front.title'] |
|
2 | 2 | |
|
3 | 3 | .row |
|
4 | 4 | .col-md-6 |
|
5 | 5 | - if @announcements.length!=0 |
|
6 | 6 | .announcementbox{:style => 'margin-top: 0px'} |
|
7 | 7 | %span{:class => 'title'} |
|
8 | 8 | Announcements |
|
9 | 9 | = render :partial => 'announcement', :collection => @announcements |
|
10 | 10 | .col-md-4{style: "padding-left: 20px;"} |
|
11 | 11 | = render :partial => 'login_box' |
|
12 | + = "current ip is #{@remote_ip}" |
@@ -85,204 +85,204 | |||
|
85 | 85 | { |
|
86 | 86 | :key => 'right.heartbeat_response', |
|
87 | 87 | :value_type => 'string', |
|
88 | 88 | :default_value => 'OK', |
|
89 | 89 | :description => 'Heart beat response text' |
|
90 | 90 | }, |
|
91 | 91 | |
|
92 | 92 | { |
|
93 | 93 | :key => 'right.heartbeat_response_full', |
|
94 | 94 | :value_type => 'string', |
|
95 | 95 | :default_value => 'OK', |
|
96 | 96 | :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)' |
|
97 | 97 | }, |
|
98 | 98 | |
|
99 | 99 | { |
|
100 | 100 | :key => 'right.view_testcase', |
|
101 | 101 | :value_type => 'boolean', |
|
102 | 102 | :default_value => 'false', |
|
103 | 103 | :description => 'When true, any user can view/download test data' |
|
104 | 104 | }, |
|
105 | 105 | |
|
106 | 106 | { |
|
107 | 107 | :key => 'system.online_registration', |
|
108 | 108 | :value_type => 'boolean', |
|
109 | 109 | :default_value => 'false', |
|
110 | 110 | :description => 'This option enables online registration.' |
|
111 | 111 | }, |
|
112 | 112 | |
|
113 | 113 | # If Configuration['system.online_registration'] is true, the |
|
114 | 114 | # system allows online registration, and will use these |
|
115 | 115 | # information for sending confirmation emails. |
|
116 | 116 | { |
|
117 | 117 | :key => 'system.online_registration.smtp', |
|
118 | 118 | :value_type => 'string', |
|
119 | 119 | :default_value => 'smtp.somehost.com' |
|
120 | 120 | }, |
|
121 | 121 | |
|
122 | 122 | { |
|
123 | 123 | :key => 'system.online_registration.from', |
|
124 | 124 | :value_type => 'string', |
|
125 | 125 | :default_value => 'your.email@address' |
|
126 | 126 | }, |
|
127 | 127 | |
|
128 | 128 | { |
|
129 | 129 | :key => 'system.admin_email', |
|
130 | 130 | :value_type => 'string', |
|
131 | 131 | :default_value => 'admin@admin.email' |
|
132 | 132 | }, |
|
133 | 133 | |
|
134 | 134 | { |
|
135 | 135 | :key => 'system.user_setting_enabled', |
|
136 | 136 | :value_type => 'boolean', |
|
137 | 137 | :default_value => 'true', |
|
138 | 138 | :description => 'If this option is true, users can change their settings' |
|
139 | 139 | }, |
|
140 | 140 | |
|
141 | 141 | { |
|
142 | 142 | :key => 'system.user_setting_enabled', |
|
143 | 143 | :value_type => 'boolean', |
|
144 | 144 | :default_value => 'true', |
|
145 | 145 | :description => 'If this option is true, users can change their settings' |
|
146 | 146 | }, |
|
147 | 147 | |
|
148 | 148 | # If Configuration['contest.test_request.early_timeout'] is true |
|
149 | 149 | # the user will not be able to use test request at 30 minutes |
|
150 | 150 | # before the contest ends. |
|
151 | 151 | { |
|
152 | 152 | :key => 'contest.test_request.early_timeout', |
|
153 | 153 | :value_type => 'boolean', |
|
154 | 154 | :default_value => 'false' |
|
155 | 155 | }, |
|
156 | 156 | |
|
157 | 157 | { |
|
158 | 158 | :key => 'system.multicontests', |
|
159 | 159 | :value_type => 'boolean', |
|
160 | 160 | :default_value => 'false' |
|
161 | 161 | }, |
|
162 | 162 | |
|
163 | 163 | { |
|
164 | 164 | :key => 'contest.confirm_indv_contest_start', |
|
165 | 165 | :value_type => 'boolean', |
|
166 | 166 | :default_value => 'false' |
|
167 | 167 | }, |
|
168 | 168 | |
|
169 | 169 | { |
|
170 | 170 | :key => 'contest.default_contest_name', |
|
171 | 171 | :value_type => 'string', |
|
172 | 172 | :default_value => 'none', |
|
173 | 173 | :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest." |
|
174 | 174 | }, |
|
175 | 175 | |
|
176 | 176 | { |
|
177 | 177 | :key => 'system.use_problem_group', |
|
178 | 178 | :value_type => 'boolean', |
|
179 | 179 | :default_value => 'false', |
|
180 | 180 | :description => "If true, available problem to the user will be only ones associated with the group of the user." |
|
181 | 181 | }, |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | { |
|
185 | 185 | :key => 'right.whitelist_ip_only', |
|
186 | 186 | :value_type => 'boolean', |
|
187 | 187 | :default_value => 'false', |
|
188 | 188 | :description => "If true, non-admin user will be able to use the system only when their ip is in the 'whitelist_ip'." |
|
189 | 189 | }, |
|
190 | 190 | |
|
191 | 191 | { |
|
192 | 192 | :key => 'right.whitelist_ip', |
|
193 | 193 | :value_type => 'string', |
|
194 | 194 | :default_value => '0.0.0.0/0', |
|
195 | 195 | :description => "list of whitelist ip, given in comma separated CIDR notation. For example '161.200.92.0/23, 161.200.80.1/32'" |
|
196 | 196 | }, |
|
197 | 197 | |
|
198 | 198 | ] |
|
199 | 199 | |
|
200 | 200 | |
|
201 | 201 | def create_configuration_key(key, |
|
202 | 202 | value_type, |
|
203 | 203 | default_value, |
|
204 | 204 | description='') |
|
205 | 205 | conf = (GraderConfiguration.find_by_key(key) || |
|
206 | 206 | GraderConfiguration.new(:key => key, |
|
207 | 207 | :value_type => value_type, |
|
208 | 208 | :value => default_value)) |
|
209 | 209 | conf.description = description |
|
210 | 210 | conf.save |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def seed_config |
|
214 | 214 | CONFIGURATIONS.each do |conf| |
|
215 | 215 | if conf.has_key? :description |
|
216 | 216 | desc = conf[:description] |
|
217 | 217 | else |
|
218 | 218 | desc = '' |
|
219 | 219 | end |
|
220 | 220 | create_configuration_key(conf[:key], |
|
221 | 221 | conf[:value_type], |
|
222 | 222 | conf[:default_value], |
|
223 | 223 | desc) |
|
224 | 224 | end |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def seed_roles |
|
228 | 228 | return if Role.find_by_name('admin') |
|
229 | 229 | |
|
230 | 230 | role = Role.create(:name => 'admin') |
|
231 | 231 | user_admin_right = Right.create(:name => 'user_admin', |
|
232 | 232 | :controller => 'user_admin', |
|
233 | 233 | :action => 'all') |
|
234 | 234 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
235 | 235 | :controller => 'problems', |
|
236 | 236 | :action => 'all') |
|
237 | 237 | |
|
238 | 238 | graders_right = Right.create(:name => 'graders_admin', |
|
239 | 239 | :controller => 'graders', |
|
240 | 240 | :action => 'all') |
|
241 | 241 | |
|
242 | 242 | role.rights << user_admin_right; |
|
243 | 243 | role.rights << problem_admin_right; |
|
244 | 244 | role.rights << graders_right; |
|
245 | 245 | role.save |
|
246 | 246 | end |
|
247 | 247 | |
|
248 | 248 | def seed_root |
|
249 | 249 | return if User.find_by_login('root') |
|
250 | 250 | |
|
251 | 251 | root = User.new(:login => 'root', |
|
252 | 252 | :full_name => 'Administrator', |
|
253 | 253 | :alias => 'root') |
|
254 | 254 | root.password = 'ioionrails'; |
|
255 | 255 | |
|
256 | 256 | class << root |
|
257 | 257 | public :encrypt_new_password |
|
258 | 258 | def valid?(context=nil) |
|
259 | 259 | true |
|
260 | 260 | end |
|
261 | 261 | end |
|
262 | 262 | |
|
263 | 263 | root.encrypt_new_password |
|
264 | 264 | |
|
265 | 265 | root.roles << Role.find_by_name('admin') |
|
266 | 266 | |
|
267 | 267 | root.activated = true |
|
268 | 268 | root.save |
|
269 | 269 | end |
|
270 | 270 | |
|
271 | 271 | def seed_users_and_roles |
|
272 | 272 | seed_roles |
|
273 | 273 | seed_root |
|
274 | 274 | end |
|
275 | 275 | |
|
276 | 276 | def seed_more_languages |
|
277 | - Language.delete_all | |
|
277 | + #Language.delete_all | |
|
278 | 278 | Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' ) |
|
279 | 279 | Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' ) |
|
280 | 280 | Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' ) |
|
281 | 281 | Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' ) |
|
282 | 282 | Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' ) |
|
283 | 283 | Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' ) |
|
284 | 284 | end |
|
285 | 285 | |
|
286 | 286 | seed_config |
|
287 | 287 | seed_users_and_roles |
|
288 | 288 | seed_more_languages |
You need to be logged in to leave comments.
Login now