Description:
- fix ssl, we no longer check SSL for the API call to chula
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r585:0d6ca27c4e8d - - 4 files changed: 8 inserted, 7 deleted

@@ -66,105 +66,106
66 66 def self.authenticate(login, password)
67 67 user = find_by_login(login)
68 68 if user
69 69 return user if user.authenticated?(password)
70 70 if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password)
71 71 user.password = password
72 72 user.save
73 73 return user
74 74 end
75 75 end
76 76 end
77 77
78 78 def authenticated?(password)
79 79 if self.activated
80 80 hashed_password == User.encrypt(password,self.salt)
81 81 else
82 82 false
83 83 end
84 84 end
85 85
86 86 def authenticated_by_pop3?(password)
87 87 Net::POP3.enable_ssl
88 88 pop = Net::POP3.new('pops.it.chula.ac.th')
89 89 authen = true
90 90 begin
91 91 pop.start(login, password)
92 92 pop.finish
93 93 return true
94 94 rescue
95 95 return false
96 96 end
97 97 end
98 98
99 99 def authenticated_by_cucas?(password)
100 100 url = URI.parse('https://www.cas.chula.ac.th/cas/api/?q=studentAuthenticate')
101 101 appid = '41508763e340d5858c00f8c1a0f5a2bb'
102 102 appsecret ='d9cbb5863091dbe186fded85722a1e31'
103 103 post_args = {
104 104 'appid' => appid,
105 105 'appsecret' => appsecret,
106 106 'username' => login,
107 107 'password' => password
108 108 }
109 109
110 110 #simple call
111 111 begin
112 112 http = Net::HTTP.new('www.cas.chula.ac.th', 443)
113 113 http.use_ssl = true
114 + http.verify_mode = OpenSSL::SSL::VERIFY_NONE
114 115 result = [ ]
115 116 http.start do |http|
116 117 req = Net::HTTP::Post.new('/cas/api/?q=studentAuthenticate')
117 118 param = "appid=#{appid}&appsecret=#{appsecret}&username=#{login}&password=#{password}"
118 119 resp = http.request(req,param)
119 120 result = JSON.parse resp.body
120 121 end
121 122 return true if result["type"] == "beanStudent"
122 - rescue
123 + rescue => e
123 124 return false
124 125 end
125 126 return false
126 127 end
127 128
128 129 def admin?
129 130 self.roles.detect {|r| r.name == 'admin' }
130 131 end
131 132
132 133 def email_for_editing
133 134 if self.email==nil
134 135 "(unknown)"
135 136 elsif self.email==''
136 137 "(blank)"
137 138 else
138 139 self.email
139 140 end
140 141 end
141 142
142 143 def email_for_editing=(e)
143 144 self.email=e
144 145 end
145 146
146 147 def alias_for_editing
147 148 if self.alias==nil
148 149 "(unknown)"
149 150 elsif self.alias==''
150 151 "(blank)"
151 152 else
152 153 self.alias
153 154 end
154 155 end
155 156
156 157 def alias_for_editing=(e)
157 158 self.alias=e
158 159 end
159 160
160 161 def activation_key
161 162 if self.hashed_password==nil
162 163 encrypt_new_password
163 164 end
164 165 Digest::SHA1.hexdigest(self.hashed_password)[0..7]
165 166 end
166 167
167 168 def verify_activation_key(key)
168 169 key == activation_key
169 170 end
170 171
@@ -194,97 +195,97
194 195 return site.time_left
195 196 elsif GraderConfiguration.indv_contest_mode?
196 197 time_limit = GraderConfiguration.contest_time_limit
197 198 if time_limit == nil
198 199 return nil
199 200 end
200 201 if contest_stat==nil or contest_stat.started_at==nil
201 202 return (Time.now.gmtime + time_limit) - Time.now.gmtime
202 203 else
203 204 finish_time = contest_stat.started_at + time_limit
204 205 current_time = Time.now.gmtime
205 206 if current_time > finish_time
206 207 return 0
207 208 else
208 209 return finish_time - current_time
209 210 end
210 211 end
211 212 else
212 213 return nil
213 214 end
214 215 end
215 216
216 217 def contest_finished?
217 218 if GraderConfiguration.contest_mode?
218 219 return false if site==nil
219 220 return site.finished?
220 221 elsif GraderConfiguration.indv_contest_mode?
221 222 return false if self.contest_stat(true)==nil
222 223 return contest_time_left == 0
223 224 else
224 225 return false
225 226 end
226 227 end
227 228
228 229 def contest_started?
229 230 if GraderConfiguration.indv_contest_mode?
230 231 stat = self.contest_stat
231 232 return ((stat != nil) and (stat.started_at != nil))
232 233 elsif GraderConfiguration.contest_mode?
233 234 return true if site==nil
234 235 return site.started
235 236 else
236 237 return true
237 238 end
238 239 end
239 240
240 241 def update_start_time
241 242 stat = self.contest_stat
242 - if (stat.nil?) or (stat.started_at.nil?)
243 + if stat.nil? or stat.started_at.nil?
243 244 stat ||= UserContestStat.new(:user => self)
244 245 stat.started_at = Time.now.gmtime
245 246 stat.save
246 247 end
247 248 end
248 249
249 250 def problem_in_user_contests?(problem)
250 251 problem_contests = problem.contests.all
251 252
252 253 if problem_contests.length == 0 # this is public contest
253 254 return true
254 255 end
255 256
256 257 contests.each do |contest|
257 258 if problem_contests.find {|c| c.id == contest.id }
258 259 return true
259 260 end
260 261 end
261 262 return false
262 263 end
263 264
264 265 def available_problems_group_by_contests
265 266 contest_problems = []
266 267 pin = {}
267 268 contests.enabled.each do |contest|
268 269 available_problems = contest.problems.available
269 270 contest_problems << {
270 271 :contest => contest,
271 272 :problems => available_problems
272 273 }
273 274 available_problems.each {|p| pin[p.id] = true}
274 275 end
275 276 other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0}
276 277 contest_problems << {
277 278 :contest => nil,
278 279 :problems => other_avaiable_problems
279 280 }
280 281 return contest_problems
281 282 end
282 283
283 284 def available_problems
284 285 if not GraderConfiguration.multicontests?
285 286 return Problem.find_available_problems
286 287 else
287 288 contest_problems = []
288 289 pin = {}
289 290 contests.enabled.each do |contest|
290 291 contest.problems.available.each do |problem|
@@ -1,11 +1,11
1 1
2 2 %td= grader.host
3 3 %td= grader.pid
4 4 %td= grader.mode
5 - %td= grader.updated_at.strftime("%H:%M:%S") unless grader.updated_at.nil?
5 + %td= grader.updated_at.strftime("%H:%M:%S") if grader.updated_at
6 6 %td= grader.task_type
7 7 %td
8 - - if grader.task_id.nil?
8 + - unless grader.task_id
9 9 idle
10 10 - else
11 11 = link_to "#{grader.task_id}", :action => 'view', :id => grader.task_id, :type => grader.task_type
@@ -1,26 +1,26
1 1
2 2 - if submission.nil?
3 3 = "-"
4 4 - else
5 5 - if submission.graded_at.nil?
6 6 =t 'main.submitted_at'
7 7 = format_short_time(submission.submitted_at.localtime)
8 8 - else
9 9 = t 'main.graded_at'
10 10 = "#{format_short_time(submission.graded_at.localtime)}, "
11 11 - if GraderConfiguration['ui.show_score']
12 12 = t 'main.score'
13 13 = "#{(submission.points*100/submission.problem.full_score).to_i} "
14 14 = " ["
15 15 %tt
16 16 = submission.grader_comment
17 17 = "]"
18 18 - if GraderConfiguration.show_grading_result
19 19 = " | "
20 20 = link_to '[detailed result]', :action => 'result', :id => submission.id
21 21 = " | "
22 22 = link_to("[#{t 'main.cmp_msg'}]", {:action => 'compiler_msg', :id => submission.id}, {:popup => true})
23 23 = " | "
24 24 = link_to("[#{t 'main.src_link'}]",{:action => 'source', :id => submission.id})
25 - //= " | "
26 - //= link_to "[#{t 'main.submissions_link'}]", main_submission_path(submission.problem.id)
25 + = " | "
26 + = link_to "[#{t 'main.submissions_link'}]", :action => 'submission', :id => problem_name
@@ -3,59 +3,59
3 3 / = stylesheet_link_tag 'tablesorter-theme.cafe'
4 4
5 5 %script{:type=>"text/javascript"}
6 6 $(function () {
7 7 $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 8 $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
9 9 /$('#my_table').tablesorter({widgets: ['zebra']});
10 10 });
11 11
12 12 %h1 User grading results
13 13 %h2= params[:action] == 'user_stat' ? "Show scores from latest submission" : "Show max scores in submission range"
14 14
15 15
16 16 - if @problem and @problem.errors
17 17 =error_messages_for 'problem'
18 18
19 19 = render partial: 'submission_range'
20 20
21 21 - if params[:action] == 'user_stat'
22 22 %h3 Latest score
23 23 = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat, commit: 'download csv'
24 24 - else
25 25 %h3 Max score
26 26 = link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat
27 27 = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat_max, commit: 'download csv'
28 28
29 29 %table.table.sortable.table-striped.table-bordered
30 30 %thead
31 31 %tr
32 32 %th Login
33 33 %th Name
34 34 %th Activated?
35 35 %th Logged_in
36 36 %th Contest(s)
37 37 %th Remark
38 38 - @problems.each do |p|
39 39 %th.text-right= p.name
40 40 %th.text-right Total
41 41 %th.text-right Passed
42 42 %tbody
43 43 - @scorearray.each do |sc|
44 44 %tr
45 45 - total,num_passed = 0,0
46 46 - sc.each_index do |i|
47 47 - if i == 0
48 48 %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i]
49 49 %td= sc[i].full_name
50 50 %td= sc[i].activated
51 - %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no'
51 + %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
52 52 %td= sc[i].contests.collect {|c| c.name}.join(', ')
53 53 %td= sc[i].remark
54 54 - else
55 55 %td.text-right= sc[i][0]
56 56 - total += sc[i][0]
57 57 - num_passed += 1 if sc[i][1]
58 58 %td.text-right= total
59 59 %td.text-right= num_passed
60 60 :javascript
61 61 $.bootstrapSortable(true,'reversed')
You need to be logged in to leave comments. Login now