Show More
Commit Description:
[web] added main_controller_spec...
Commit Description:
[web] added main_controller_spec
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@148 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
app/controllers/application.rb
| 44 lines
| 1.3 KiB
| text/x-ruby
| RubyLexer
|
|
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' | ||||
protected | ||||
def authenticate | ||||
unless session[:user_id] | ||||
redirect_to :controller => 'main', :action => 'login' | ||||
return false | ||||
end | ||||
|
r67 | |||
# check if run in single user mode | ||||
|
r71 | if defined?(SINGLE_USER_MODE) and (SINGLE_USER_MODE) | ||
user = User.find(session[:user_id]) | ||||
if user==nil or user.login != 'root' | ||||
redirect_to :controller => 'main', :action => 'login' | ||||
return false | ||||
end | ||||
|
r67 | end | ||
|
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 | ||||
(right.action == 'all' or right.action == action_name) | ||||
} | ||||
} | ||||
flash[:notice] = 'You are not authorized to view the page you requested' | ||||
#request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') | ||||
|
r58 | redirect_to :controller => 'main', :action => 'login' | ||
|
r0 | return false | ||
end | ||||
end | ||||
end | ||||