Description:
[web] no site admin login box when not in contest mode git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@252 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r124:44e64c191944 - - 2 files changed: 5 inserted, 4 deleted

@@ -1,77 +1,78
1 1 class MainController < ApplicationController
2 2
3 3 SYSTEM_MODE_CONF_KEY = 'system.mode'
4 4
5 5 before_filter :authenticate, :except => [:index, :login]
6 6 before_filter :check_viewability, :except => [:index, :login]
7 7
8 8 #
9 9 # COMMENT OUT: filter in each action instead
10 10 #
11 11 # before_filter :verify_time_limit, :only => [:submit]
12 12
13 13 verify :method => :post, :only => [:submit],
14 14 :redirect_to => { :action => :index }
15 15
16 + caches_action :index, :login
16 17
17 18 def index
18 19 redirect_to :action => 'login'
19 20 end
20 21
21 22 def login
22 23 saved_notice = flash[:notice]
23 24 reset_session
24 25 flash[:notice] = saved_notice
25 26
26 27 #
27 28 # These are for site administrator login
28 29 #
29 - @countries = Country.find(:all)
30 + @countries = Country.find(:all, :include => :sites)
30 31 @country_select = @countries.collect { |c| [c.name, c.id] }
31 32
32 33 @country_select_with_all = [['Any',0]]
33 34 @countries.each do |country|
34 35 @country_select_with_all << [country.name, country.id]
35 36 end
36 37
37 38 @site_select = []
38 39 @countries.each do |country|
39 40 country.sites.each do |site|
40 41 @site_select << ["#{site.name}, #{country.name}", site.id]
41 42 end
42 43 end
43 44
44 45 render :action => 'login', :layout => 'empty'
45 46 end
46 47
47 48 def list
48 49 prepare_list_information
49 50 end
50 51
51 52 def help
52 53 @user = User.find(session[:user_id])
53 54 end
54 55
55 56 def submit
56 57 user = User.find(session[:user_id])
57 58
58 59 @submission = Submission.new(params[:submission])
59 60 @submission.user = user
60 61 @submission.language_id = 0
61 62 if params['file']!=''
62 63 @submission.source = params['file'].read
63 64 @submission.source_filename = params['file'].original_filename
64 65 end
65 66 @submission.submitted_at = Time.new.gmtime
66 67
67 68 if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and
68 69 user.site!=nil and user.site.finished?
69 70 @submission.errors.add_to_base "The contest is over."
70 71 prepare_list_information
71 72 render :action => 'list' and return
72 73 end
73 74
74 75 if @submission.valid?
75 76 if @submission.save == false
76 77 flash[:notice] = 'Error saving your submission'
77 78 elsif Task.create(:submission_id => @submission.id,
@@ -103,57 +104,57
103 104 end
104 105
105 106 def compiler_msg
106 107 @submission = Submission.find(params[:id])
107 108 if @submission.user_id == session[:user_id]
108 109 render :action => 'compiler_msg', :layout => 'empty'
109 110 else
110 111 flash[:notice] = 'Error viewing source'
111 112 redirect_to :action => 'list'
112 113 end
113 114 end
114 115
115 116 def submission
116 117 @user = User.find(session[:user_id])
117 118 @problems = Problem.find_available_problems
118 119 if params[:id]==nil
119 120 @problem = nil
120 121 @submissions = nil
121 122 else
122 123 @problem = Problem.find_by_name(params[:id])
123 124 @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id)
124 125 end
125 126 end
126 127
127 128 def error
128 129 @user = User.find(session[:user_id])
129 130 end
130 131
131 132 protected
132 133 def prepare_list_information
133 134 @problems = Problem.find_available_problems
134 135 @prob_submissions = Array.new
135 136 @user = User.find(session[:user_id])
136 137 @problems.each do |p|
137 138 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
138 139 if sub!=nil
139 140 @prob_submissions << { :count => sub.number, :submission => sub }
140 141 else
141 142 @prob_submissions << { :count => 0, :submission => nil }
142 143 end
143 144 end
144 145
145 146 @announcements = Announcement.find(:all,
146 147 :conditions => "published = 1",
147 148 :order => "created_at DESC")
148 149 end
149 150
150 151 def check_viewability
151 - user = User.find(session[:user_id])
152 - if (!Configuration.show_tasks_to?(user)) and
152 + @user = User.find(session[:user_id])
153 + if (!Configuration.show_tasks_to?(@user)) and
153 154 ((action_name=='submission') or (action_name=='submit'))
154 155 redirect_to :action => 'list' and return
155 156 end
156 157 end
157 158
158 159 end
159 160
@@ -1,56 +1,56
1 1 %h1= Configuration['ui.front.title']
2 2
3 3 %b= Configuration['ui.front.welcome_message']
4 4 %br/
5 5 Please login to see the problem list.
6 6 %br/
7 7 %br/
8 8
9 9 - if flash[:notice]
10 10 %hr/
11 11 %b= flash[:notice]
12 12 %hr/
13 13
14 14 %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"}
15 15 - form_tag :controller => 'login', :action => 'login' do
16 16 %table
17 17 %tr
18 18 %td{:align => "right"} Login:
19 19 %td= text_field_tag 'login'
20 20 %tr
21 21 %td{:align => "right"} Password:
22 22 %td= password_field_tag
23 23 = submit_tag 'Login'
24 24
25 25 %br/
26 26
27 + - if Configuration['system.mode']=='contest'
27 28 %script{:type => 'text/javascript'}
28 29 var siteList = new Array();
29 30 - @countries.each do |country|
30 31 = "siteList[#{country.id}] = new Array();"
31 32 - country.sites.each do |site|
32 33 = "siteList[#{country.id}][#{site.id}] = \"#{site.name}\";"
33 34
34 35 var allSiteList = new Array();
35 36 - @site_select.each do |sel|
36 37 = "allSiteList[#{sel[1]}]=\"#{sel[0]}\";"
37 38
38 39 %script{:type => 'text/javascript', :src => '/javascripts/site_update.js'}
39 40
40 41 %div{ :style => "border: solid 1px gray; padding: 2px; background: #f0f0f0;"}
41 42 %b For Site Administrator.
42 43 %br/
43 44 Please select your country and site and login.
44 - .login-box
45 45 - form_for :login, nil, :url => {:controller => 'login', :action => 'site_login'} do |f|
46 46 Country:
47 47 = select :site_country, :id, @country_select_with_all, {}, {:onchange => "updateSiteList();", :onclick => "updateSiteList();" }
48 48 Site:
49 49 = select :login, :site_id, @site_select
50 50 %br/
51 51 Password:
52 52 = f.password_field :password
53 53 = submit_tag "Site Administrator Login"
54 54
55 55 %script{:type => 'text/javascript'}
56 56 updateSiteList();
You need to be logged in to leave comments. Login now