Show More
Commit Description:
MERGE changeset 306:307 from branch ytopc08-2 that fixes migration bug...
Commit Description:
MERGE changeset 306:307 from branch ytopc08-2 that fixes migration bug git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@308 6386c4cd-e34a-4fa8-8920-d93eb39b512e
File last commit:
Show/Diff file:
Action:
app/controllers/application.rb | 76 lines | 2.3 KiB | text/x-ruby | RubyLexer |
pramook
initial commit...
r0 # Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
# Pick a unique cookie name to distinguish our session data from others'
session :session_key => '_grader_session_id'
jittat
[web] added configurations...
r76 SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
jittat
[web] improved log-in & roles efficiency...
r104 def admin_authorization
return false unless authenticate
user = User.find(session[:user_id], :include => ['roles'])
redirect_to :controller => 'main', :action => 'login' unless user.admin?
end
jittat
[web] added configurations...
r76 def authorization_by_roles(allowed_roles)
return false unless authenticate
user = User.find(session[:user_id])
unless user.roles.detect { |role| allowed_roles.member?(role.name) }
flash[:notice] = 'You are not authorized to view the page you requested'
redirect_to :controller => 'main', :action => 'login'
return false
end
end
pramook
initial commit...
r0 protected
jittat
[web] improved log-in & roles efficiency...
r104
pramook
initial commit...
r0 def authenticate
unless session[:user_id]
redirect_to :controller => 'main', :action => 'login'
return false
end
jittat
[web] added single user mode...
r67
jittat
[web] improved log-in & roles efficiency...
r104 #Configuration.reload
jittat
[web] added single user mode...
r67 # check if run in single user mode
jittat
[web] added configurations...
r76 if (Configuration[SINGLE_USER_MODE_CONF_KEY])
jittat
[web] added main_controller_spec...
r71 user = User.find(session[:user_id])
if user==nil or user.login != 'root'
redirect_to :controller => 'main', :action => 'login'
return false
end
jittat
[web] added single user mode...
r67 end
pramook
initial commit...
r0 return true
end
def authorization
return false unless authenticate
user = User.find(session[:user_id])
unless user.roles.detect { |role|
role.rights.detect{ |right|
right.controller == self.class.controller_name and
jittat
[web] added configurations...
r76 (right.action == 'all' or right.action == action_name)
pramook
initial commit...
r0 }
}
flash[:notice] = 'You are not authorized to view the page you requested'
#request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
jittat
[web] added graders_right_to_admin_role, added a few functional tests: main, user_admin, graders, login...
r58 redirect_to :controller => 'main', :action => 'login'
pramook
initial commit...
r0 return false
end
end
jittat
[web] added site and time out basic functionality...
r85 def verify_time_limit
return true if session[:user_id]==nil
user = User.find(session[:user_id], :include => :site)
return true if user==nil or user.site == nil
if user.site.finished?
flash[:notice] = 'Error: the contest on your site is over.'
redirect_to :back
return false
end
return true
end
pramook
initial commit...
r0 end