Description:
fix wrong merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r846:4279bf26f98b - - 1 file changed: 78 inserted, 5 deleted
@@ -160,53 +160,48 | |||
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def alias_for_editing=(e) |
|
163 | 163 | self.alias=e |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def activation_key |
|
167 | 167 | if self.hashed_password==nil |
|
168 | 168 | encrypt_new_password |
|
169 | 169 | end |
|
170 | 170 | Digest::SHA1.hexdigest(self.hashed_password)[0..7] |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def verify_activation_key(key) |
|
174 | 174 | key == activation_key |
|
175 | 175 | end |
|
176 | 176 | |
|
177 | 177 | def self.random_password(length=5) |
|
178 | 178 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
179 | 179 | password = '' |
|
180 | 180 | length.times { password << chars[rand(chars.length - 1)] } |
|
181 | 181 | password |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | - def self.find_non_admin_with_prefix(prefix='') | |
|
185 | - users = User.all | |
|
186 | - return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } | |
|
187 | - end | |
|
188 | - | |
|
189 | 184 | # Contest information |
|
190 | 185 | |
|
191 | 186 | def self.find_users_with_no_contest() |
|
192 | 187 | users = User.all |
|
193 | 188 | return users.find_all { |u| u.contests.length == 0 } |
|
194 | 189 | end |
|
195 | 190 | |
|
196 | 191 | |
|
197 | 192 | def contest_time_left |
|
198 | 193 | if GraderConfiguration.contest_mode? |
|
199 | 194 | return nil if site==nil |
|
200 | 195 | return site.time_left |
|
201 | 196 | elsif GraderConfiguration.indv_contest_mode? |
|
202 | 197 | time_limit = GraderConfiguration.contest_time_limit |
|
203 | 198 | if time_limit == nil |
|
204 | 199 | return nil |
|
205 | 200 | end |
|
206 | 201 | if contest_stat==nil or contest_stat.started_at==nil |
|
207 | 202 | return (Time.now.gmtime + time_limit) - Time.now.gmtime |
|
208 | 203 | else |
|
209 | 204 | finish_time = contest_stat.started_at + time_limit |
|
210 | 205 | current_time = Time.now.gmtime |
|
211 | 206 | if current_time > finish_time |
|
212 | 207 | return 0 |
@@ -338,48 +333,126 | |||
|
338 | 333 | 1 |
|
339 | 334 | when a.date_added > b.date_added |
|
340 | 335 | -1 |
|
341 | 336 | else |
|
342 | 337 | a.name <=> b.name |
|
343 | 338 | end |
|
344 | 339 | end |
|
345 | 340 | return problem |
|
346 | 341 | else |
|
347 | 342 | return [] |
|
348 | 343 | end |
|
349 | 344 | end |
|
350 | 345 | |
|
351 | 346 | #check if the user has the right to view that problem |
|
352 | 347 | #this also consider group based problem policy |
|
353 | 348 | def can_view_problem?(problem) |
|
354 | 349 | return true if admin? |
|
355 | 350 | return available_problems.include? problem |
|
356 | 351 | end |
|
357 | 352 | |
|
358 | 353 | def self.clear_last_login |
|
359 | 354 | User.update_all(:last_ip => nil) |
|
360 | 355 | end |
|
361 | 356 | |
|
357 | + #create multiple user, one per lines of input | |
|
358 | + def self.create_from_list(lines) | |
|
359 | + error_logins = [] | |
|
360 | + first_error = nil | |
|
361 | + created_users = [] | |
|
362 | + | |
|
363 | + lines.split("\n").each do |line| | |
|
364 | + #split with large limit, this will cause consecutive ',' to be result in a blank | |
|
365 | + items = line.chomp.split(',',1000) | |
|
366 | + if items.length>=2 | |
|
367 | + login = items[0] | |
|
368 | + full_name = items[1] | |
|
369 | + remark ='' | |
|
370 | + user_alias = '' | |
|
371 | + | |
|
372 | + added_random_password = false | |
|
373 | + added_password = false | |
|
374 | + | |
|
375 | + #given password? | |
|
376 | + if items.length >= 3 | |
|
377 | + if items[2].chomp(" ").length > 0 | |
|
378 | + password = items[2].chomp(" ") | |
|
379 | + added_password = true | |
|
380 | + end | |
|
381 | + else | |
|
382 | + password = random_password | |
|
383 | + added_random_password=true; | |
|
384 | + end | |
|
385 | + | |
|
386 | + #given alias? | |
|
387 | + if items.length>= 4 and items[3].chomp(" ").length > 0; | |
|
388 | + user_alias = items[3].chomp(" ") | |
|
389 | + else | |
|
390 | + user_alias = login | |
|
391 | + end | |
|
392 | + | |
|
393 | + #given remark? | |
|
394 | + has_remark = false | |
|
395 | + if items.length>=5 | |
|
396 | + remark = items[4].strip; | |
|
397 | + has_remark = true | |
|
398 | + end | |
|
399 | + | |
|
400 | + user = User.find_by_login(login) | |
|
401 | + if (user) | |
|
402 | + user.full_name = full_name | |
|
403 | + user.remark = remark if has_remark | |
|
404 | + user.password = password if added_password || added_random_password | |
|
405 | + else | |
|
406 | + #create a random password if none are given | |
|
407 | + password = random_password unless password | |
|
408 | + user = User.new({:login => login, | |
|
409 | + :full_name => full_name, | |
|
410 | + :password => password, | |
|
411 | + :password_confirmation => password, | |
|
412 | + :alias => user_alias, | |
|
413 | + :remark => remark}) | |
|
414 | + end | |
|
415 | + user.activated = true | |
|
416 | + | |
|
417 | + if user.save | |
|
418 | + created_users << user | |
|
419 | + else | |
|
420 | + error_logins << "'#{login}'" | |
|
421 | + first_error = user.errors.full_messages.to_sentence unless first_error | |
|
422 | + end | |
|
423 | + end | |
|
424 | + end | |
|
425 | + | |
|
426 | + return {error_logins: error_logins, first_error: first_error, created_users: created_users} | |
|
427 | + | |
|
428 | + end | |
|
429 | + | |
|
430 | + def self.find_non_admin_with_prefix(prefix='') | |
|
431 | + users = User.all | |
|
432 | + return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } | |
|
433 | + end | |
|
434 | + | |
|
362 | 435 | protected |
|
363 | 436 | def encrypt_new_password |
|
364 | 437 | return if password.blank? |
|
365 | 438 | self.salt = (10+rand(90)).to_s |
|
366 | 439 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
367 | 440 | end |
|
368 | 441 | |
|
369 | 442 | def assign_default_site |
|
370 | 443 | # have to catch error when migrating (because self.site is not available). |
|
371 | 444 | begin |
|
372 | 445 | if self.site==nil |
|
373 | 446 | self.site = Site.find_by_name('default') |
|
374 | 447 | if self.site==nil |
|
375 | 448 | self.site = Site.find(1) # when 'default has be renamed' |
|
376 | 449 | end |
|
377 | 450 | end |
|
378 | 451 | rescue |
|
379 | 452 | end |
|
380 | 453 | end |
|
381 | 454 | |
|
382 | 455 | def assign_default_contest |
|
383 | 456 | # have to catch error when migrating (because self.site is not available). |
|
384 | 457 | begin |
|
385 | 458 | if self.contests.length == 0 |
You need to be logged in to leave comments.
Login now