Description:
Merge branch 'master' into codejom (bug fixed)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r250:6820e08d6a38 - - 1 file changed: 10 inserted, 0 deleted
@@ -1,55 +1,59 | |||||
|
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, :download_input, :submit_solution], |
|
15 | verify :method => :post, :only => [:submit, :download_input, :submit_solution], |
|
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 |
@@ -417,50 +421,56 | |||||
|
417 | :output_size => output_size |
|
421 | :output_size => output_size |
|
418 | } |
|
422 | } |
|
419 | end |
|
423 | end |
|
420 | end |
|
424 | end |
|
421 |
|
425 | ||
|
422 | # copied from grader/script/lib/test_request_helper.rb |
|
426 | # copied from grader/script/lib/test_request_helper.rb |
|
423 | def extract_running_stat(results) |
|
427 | def extract_running_stat(results) |
|
424 | running_stat_line = results[-1] |
|
428 | running_stat_line = results[-1] |
|
425 |
|
429 | ||
|
426 | # extract exit status line |
|
430 | # extract exit status line |
|
427 | run_stat = "" |
|
431 | run_stat = "" |
|
428 | if !(/[Cc]orrect/.match(results[0])) |
|
432 | if !(/[Cc]orrect/.match(results[0])) |
|
429 | run_stat = results[0].chomp |
|
433 | run_stat = results[0].chomp |
|
430 | else |
|
434 | else |
|
431 | run_stat = 'Program exited normally' |
|
435 | run_stat = 'Program exited normally' |
|
432 | end |
|
436 | end |
|
433 |
|
437 | ||
|
434 | logger.info "Stat line: #{running_stat_line}" |
|
438 | logger.info "Stat line: #{running_stat_line}" |
|
435 |
|
439 | ||
|
436 | # extract running time |
|
440 | # extract running time |
|
437 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
441 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
438 | seconds = (res[1].to_f + res[2].to_f) |
|
442 | seconds = (res[1].to_f + res[2].to_f) |
|
439 | time_stat = "Time used: #{seconds} sec." |
|
443 | time_stat = "Time used: #{seconds} sec." |
|
440 | else |
|
444 | else |
|
441 | seconds = nil |
|
445 | seconds = nil |
|
442 | time_stat = "Time used: n/a sec." |
|
446 | time_stat = "Time used: n/a sec." |
|
443 | end |
|
447 | end |
|
444 |
|
448 | ||
|
445 | # extract memory usage |
|
449 | # extract memory usage |
|
446 | if res = /s(.*)m/.match(running_stat_line) |
|
450 | if res = /s(.*)m/.match(running_stat_line) |
|
447 | memory_used = res[1].to_i |
|
451 | memory_used = res[1].to_i |
|
448 | else |
|
452 | else |
|
449 | memory_used = -1 |
|
453 | memory_used = -1 |
|
450 | end |
|
454 | end |
|
451 |
|
455 | ||
|
452 | return { |
|
456 | return { |
|
453 | :msg => "#{run_stat}\n#{time_stat}", |
|
457 | :msg => "#{run_stat}\n#{time_stat}", |
|
454 | :running_time => seconds, |
|
458 | :running_time => seconds, |
|
455 | :exit_status => run_stat, |
|
459 | :exit_status => run_stat, |
|
456 | :memory_usage => memory_used |
|
460 | :memory_usage => memory_used |
|
457 | } |
|
461 | } |
|
458 | end |
|
462 | end |
|
459 |
|
463 | ||
|
460 | def update_user_start_time |
|
464 | def update_user_start_time |
|
461 | user = User.find(session[:user_id]) |
|
465 | user = User.find(session[:user_id]) |
|
462 | UserContestStat.update_user_start_time(user) |
|
466 | UserContestStat.update_user_start_time(user) |
|
463 | end |
|
467 | end |
|
464 |
|
468 | ||
|
|
469 | + def reject_announcement_refresh_when_logged_out | ||
|
|
470 | + if not session[:user_id] | ||
|
|
471 | + render :text => 'Access forbidden', :status => 403 | ||
|
|
472 | + end | ||
|
465 | end |
|
473 | end |
|
466 |
|
474 | ||
|
|
475 | + end | ||
|
|
476 | + |
You need to be logged in to leave comments.
Login now