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,31 +1,35
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 #
@@ -305,26 +309,32
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
337 + end
338 +
329 end
339 end
330
340
You need to be logged in to leave comments. Login now