# HG changeset patch # User Nattee Niparnan # Date 2017-09-11 08:12:20 # Node ID f90ec3934e15e6451fc3478a1d20b6784e852e25 # Parent cdc8e11720ed4ea6c12d8ffed43c1cce5b342e8a add enabled option for user diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -39,13 +39,10 @@ def testcase_authorization #admin always has privileged - puts "haha" if @current_user.admin? return true end - puts "hehe" - puts GraderConfiguration["right.view_testcase"] unauthorized_redirect unless GraderConfiguration["right.view_testcase"] end @@ -61,27 +58,28 @@ return false end + # check if run in single user mode if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] - user = User.find_by_id(session[:user_id]) - if user==nil or (not user.admin?) + if @current_user==nil or (not @current_user.admin?) flash[:notice] = 'You cannot log in at this time' redirect_to :controller => 'main', :action => 'login' return false end - unless user.enabled? - flash[:notice] = 'Your account is disabled' - redirect_to :controller => 'main', :action => 'login' - return false - end return true end + # check if the user is enabled + unless @current_user.enabled? or @current_user.admin? + flash[:notice] = 'Your account is disabled' + redirect_to :controller => 'main', :action => 'login' + return false + end + if GraderConfiguration.multicontests? - user = User.find(session[:user_id]) - return true if user.admin? + return true if @current_user.admin? begin - if user.contest_stat(true).forced_logout + if @current_user.contest_stat(true).forced_logout flash[:notice] = 'You have been automatically logged out.' redirect_to :controller => 'main', :action => 'index' end