Show More
Commit Description:
add enabled option for user
Commit Description:
add enabled option for user
References:
File last commit:
Show/Diff file:
Action:
app/controllers/site_controller.rb
| 67 lines
| 1.6 KiB
| text/x-ruby
| RubyLexer
|
|
r123 | class SiteController < ApplicationController | ||
|
r162 | before_filter :site_admin_authorization, :except => 'login' | ||
def login | ||||
# Site administrator login | ||||
r619 | @countries = Country.includes(:sites).all | |||
|
r162 | @country_select = @countries.collect { |c| [c.name, c.id] } | ||
@country_select_with_all = [['Any',0]] | ||||
@countries.each do |country| | ||||
@country_select_with_all << [country.name, country.id] | ||||
end | ||||
@site_select = [] | ||||
@countries.each do |country| | ||||
country.sites.each do |site| | ||||
@site_select << ["#{site.name}, #{country.name}", site.id] | ||||
end | ||||
end | ||||
|
r320 | @default_site = Site.first if !GraderConfiguration['contest.multisites'] | ||
|
r162 | |||
render :action => 'login', :layout => 'empty' | ||||
end | ||||
|
r123 | |||
def index | ||||
if @site.started | ||||
render :action => 'started', :layout => 'empty' | ||||
else | ||||
render :action => 'prompt', :layout => 'empty' | ||||
end | ||||
end | ||||
def start | ||||
@site.started = true | ||||
@site.start_time = Time.new.gmtime | ||||
@site.save | ||||
redirect_to :action => 'index' | ||||
end | ||||
|
r133 | def logout | ||
reset_session | ||||
redirect_to :controller => 'main', :action => 'login' | ||||
end | ||||
|
r123 | protected | ||
def site_admin_authorization | ||||
if session[:site_id]==nil | ||||
|
r162 | redirect_to :controller => 'site', :action => 'login' and return | ||
|
r123 | end | ||
begin | ||||
@site = Site.find(session[:site_id], :include => :country) | ||||
rescue ActiveRecord::RecordNotFound | ||||
@site = nil | ||||
end | ||||
if @site==nil | ||||
|
r162 | redirect_to :controller => 'site', :action => 'login' and return | ||
|
r123 | end | ||
end | ||||
r617 | private | |||
def site_params | ||||
params.require(:site).permit() | ||||
end | ||||
|
r123 | end | ||