Description:
fixed login box showing in announcement box after user logged out in other tabs
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r249:11f906d2e75a - - 1 file changed: 10 inserted, 0 deleted

@@ -1,103 +1,107
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 :update_user_start_time, :except => [:index, :login]
6 append_before_filter :update_user_start_time, :except => [:index, :login]
7
7
8 + # to prevent log in box to be shown when user logged out of the
9 + # system only in some tab
10 + prepend_before_filter :reject_announcement_refresh_when_logged_out, :only => [:announcements]
11 +
8 # COMMENTED OUT: filter in each action instead
12 # COMMENTED OUT: filter in each action instead
9 # before_filter :verify_time_limit, :only => [:submit]
13 # before_filter :verify_time_limit, :only => [:submit]
10
14
11 verify :method => :post, :only => [:submit],
15 verify :method => :post, :only => [:submit],
12 :redirect_to => { :action => :index }
16 :redirect_to => { :action => :index }
13
17
14 # COMMENT OUT: only need when having high load
18 # COMMENT OUT: only need when having high load
15 # caches_action :index, :login
19 # caches_action :index, :login
16
20
17 # NOTE: This method is not actually needed, 'config/routes.rb' has
21 # NOTE: This method is not actually needed, 'config/routes.rb' has
18 # assigned action login as a default action.
22 # assigned action login as a default action.
19 def index
23 def index
20 redirect_to :action => 'login'
24 redirect_to :action => 'login'
21 end
25 end
22
26
23 def login
27 def login
24 saved_notice = flash[:notice]
28 saved_notice = flash[:notice]
25 reset_session
29 reset_session
26 flash.now[:notice] = saved_notice
30 flash.now[:notice] = saved_notice
27
31
28 # EXPERIMENT:
32 # EXPERIMENT:
29 # Hide login if in single user mode and the url does not
33 # Hide login if in single user mode and the url does not
30 # explicitly specify /login
34 # explicitly specify /login
31 #
35 #
32 # logger.info "PATH: #{request.path}"
36 # logger.info "PATH: #{request.path}"
33 # if Configuration['system.single_user_mode'] and
37 # if Configuration['system.single_user_mode'] and
34 # request.path!='/main/login'
38 # request.path!='/main/login'
35 # @hidelogin = true
39 # @hidelogin = true
36 # end
40 # end
37
41
38 @announcements = Announcement.find_for_frontpage
42 @announcements = Announcement.find_for_frontpage
39 render :action => 'login', :layout => 'empty'
43 render :action => 'login', :layout => 'empty'
40 end
44 end
41
45
42 def list
46 def list
43 prepare_list_information
47 prepare_list_information
44 end
48 end
45
49
46 def help
50 def help
47 @user = User.find(session[:user_id])
51 @user = User.find(session[:user_id])
48 end
52 end
49
53
50 def submit
54 def submit
51 user = User.find(session[:user_id])
55 user = User.find(session[:user_id])
52
56
53 @submission = Submission.new(params[:submission])
57 @submission = Submission.new(params[:submission])
54 @submission.user = user
58 @submission.user = user
55 @submission.language_id = 0
59 @submission.language_id = 0
56 if (params['file']) and (params['file']!='')
60 if (params['file']) and (params['file']!='')
57 @submission.source = params['file'].read
61 @submission.source = params['file'].read
58 @submission.source_filename = params['file'].original_filename
62 @submission.source_filename = params['file'].original_filename
59 end
63 end
60 @submission.submitted_at = Time.new.gmtime
64 @submission.submitted_at = Time.new.gmtime
61
65
62 if Configuration.time_limit_mode? and user.contest_finished?
66 if Configuration.time_limit_mode? and user.contest_finished?
63 @submission.errors.add_to_base "The contest is over."
67 @submission.errors.add_to_base "The contest is over."
64 prepare_list_information
68 prepare_list_information
65 render :action => 'list' and return
69 render :action => 'list' and return
66 end
70 end
67
71
68 if @submission.valid?
72 if @submission.valid?
69 if @submission.save == false
73 if @submission.save == false
70 flash[:notice] = 'Error saving your submission'
74 flash[:notice] = 'Error saving your submission'
71 elsif Task.create(:submission_id => @submission.id,
75 elsif Task.create(:submission_id => @submission.id,
72 :status => Task::STATUS_INQUEUE) == false
76 :status => Task::STATUS_INQUEUE) == false
73 flash[:notice] = 'Error adding your submission to task queue'
77 flash[:notice] = 'Error adding your submission to task queue'
74 end
78 end
75 else
79 else
76 prepare_list_information
80 prepare_list_information
77 render :action => 'list' and return
81 render :action => 'list' and return
78 end
82 end
79 redirect_to :action => 'list'
83 redirect_to :action => 'list'
80 end
84 end
81
85
82 def source
86 def source
83 submission = Submission.find(params[:id])
87 submission = Submission.find(params[:id])
84 if submission.user_id == session[:user_id]
88 if submission.user_id == session[:user_id]
85 send_data(submission.source,
89 send_data(submission.source,
86 {:filename => submission.download_filename,
90 {:filename => submission.download_filename,
87 :type => 'text/plain'})
91 :type => 'text/plain'})
88 else
92 else
89 flash[:notice] = 'Error viewing source'
93 flash[:notice] = 'Error viewing source'
90 redirect_to :action => 'list'
94 redirect_to :action => 'list'
91 end
95 end
92 end
96 end
93
97
94 def compiler_msg
98 def compiler_msg
95 @submission = Submission.find(params[:id])
99 @submission = Submission.find(params[:id])
96 if @submission.user_id == session[:user_id]
100 if @submission.user_id == session[:user_id]
97 render :action => 'compiler_msg', :layout => 'empty'
101 render :action => 'compiler_msg', :layout => 'empty'
98 else
102 else
99 flash[:notice] = 'Error viewing source'
103 flash[:notice] = 'Error viewing source'
100 redirect_to :action => 'list'
104 redirect_to :action => 'list'
101 end
105 end
102 end
106 end
103
107
@@ -233,98 +237,104
233 i+1) ]
237 i+1) ]
234 end
238 end
235 else
239 else
236 grading_info['testruns'].keys.sort.each do |num|
240 grading_info['testruns'].keys.sort.each do |num|
237 run = []
241 run = []
238 testrun = grading_info['testruns'][num]
242 testrun = grading_info['testruns'][num]
239 testrun.each do |c|
243 testrun.each do |c|
240 run << read_grading_result(@user.login,
244 run << read_grading_result(@user.login,
241 submission.problem.name,
245 submission.problem.name,
242 submission.id,
246 submission.id,
243 c)
247 c)
244 end
248 end
245 @test_runs << run
249 @test_runs << run
246 end
250 end
247 end
251 end
248 end
252 end
249
253
250 def grading_result_dir(user_name, problem_name, submission_id, case_num)
254 def grading_result_dir(user_name, problem_name, submission_id, case_num)
251 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
255 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
252 end
256 end
253
257
254 def output_filename(user_name, problem_name, submission_id, case_num)
258 def output_filename(user_name, problem_name, submission_id, case_num)
255 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
259 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
256 return "#{dir}/output.txt"
260 return "#{dir}/output.txt"
257 end
261 end
258
262
259 def read_grading_result(user_name, problem_name, submission_id, case_num)
263 def read_grading_result(user_name, problem_name, submission_id, case_num)
260 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
264 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
261 result_file_name = "#{dir}/result"
265 result_file_name = "#{dir}/result"
262 if !FileTest.exists?(result_file_name)
266 if !FileTest.exists?(result_file_name)
263 return {:num => case_num, :msg => 'program did not run'}
267 return {:num => case_num, :msg => 'program did not run'}
264 else
268 else
265 results = File.open(result_file_name).readlines
269 results = File.open(result_file_name).readlines
266 run_stat = extract_running_stat(results)
270 run_stat = extract_running_stat(results)
267 output_filename = "#{dir}/output.txt"
271 output_filename = "#{dir}/output.txt"
268 if FileTest.exists?(output_filename)
272 if FileTest.exists?(output_filename)
269 output_file = true
273 output_file = true
270 output_size = File.size(output_filename)
274 output_size = File.size(output_filename)
271 else
275 else
272 output_file = false
276 output_file = false
273 output_size = 0
277 output_size = 0
274 end
278 end
275
279
276 return {
280 return {
277 :num => case_num,
281 :num => case_num,
278 :msg => results[0],
282 :msg => results[0],
279 :run_stat => run_stat,
283 :run_stat => run_stat,
280 :output => output_file,
284 :output => output_file,
281 :output_size => output_size
285 :output_size => output_size
282 }
286 }
283 end
287 end
284 end
288 end
285
289
286 # copied from grader/script/lib/test_request_helper.rb
290 # copied from grader/script/lib/test_request_helper.rb
287 def extract_running_stat(results)
291 def extract_running_stat(results)
288 running_stat_line = results[-1]
292 running_stat_line = results[-1]
289
293
290 # extract exit status line
294 # extract exit status line
291 run_stat = ""
295 run_stat = ""
292 if !(/[Cc]orrect/.match(results[0]))
296 if !(/[Cc]orrect/.match(results[0]))
293 run_stat = results[0].chomp
297 run_stat = results[0].chomp
294 else
298 else
295 run_stat = 'Program exited normally'
299 run_stat = 'Program exited normally'
296 end
300 end
297
301
298 logger.info "Stat line: #{running_stat_line}"
302 logger.info "Stat line: #{running_stat_line}"
299
303
300 # extract running time
304 # extract running time
301 if res = /r(.*)u(.*)s/.match(running_stat_line)
305 if res = /r(.*)u(.*)s/.match(running_stat_line)
302 seconds = (res[1].to_f + res[2].to_f)
306 seconds = (res[1].to_f + res[2].to_f)
303 time_stat = "Time used: #{seconds} sec."
307 time_stat = "Time used: #{seconds} sec."
304 else
308 else
305 seconds = nil
309 seconds = nil
306 time_stat = "Time used: n/a sec."
310 time_stat = "Time used: n/a sec."
307 end
311 end
308
312
309 # extract memory usage
313 # extract memory usage
310 if res = /s(.*)m/.match(running_stat_line)
314 if res = /s(.*)m/.match(running_stat_line)
311 memory_used = res[1].to_i
315 memory_used = res[1].to_i
312 else
316 else
313 memory_used = -1
317 memory_used = -1
314 end
318 end
315
319
316 return {
320 return {
317 :msg => "#{run_stat}\n#{time_stat}",
321 :msg => "#{run_stat}\n#{time_stat}",
318 :running_time => seconds,
322 :running_time => seconds,
319 :exit_status => run_stat,
323 :exit_status => run_stat,
320 :memory_usage => memory_used
324 :memory_usage => memory_used
321 }
325 }
322 end
326 end
323
327
324 def update_user_start_time
328 def update_user_start_time
325 user = User.find(session[:user_id])
329 user = User.find(session[:user_id])
326 UserContestStat.update_user_start_time(user)
330 UserContestStat.update_user_start_time(user)
327 end
331 end
328
332
333 + def reject_announcement_refresh_when_logged_out
334 + if not session[:user_id]
335 + render :text => 'Access forbidden', :status => 403
336 + end
329 end
337 end
330
338
339 + end
340 +
You need to be logged in to leave comments. Login now