diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -163,7 +163,7 @@ @submissions.find_each do |sub| d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 @histogram[:data][d.to_i] += 1 if d < range - user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max + user[sub.user_id] = [user[sub.user_id], (sub.try(:points) >= @problem.full_score) ? 1 : 0].max end @histogram[:summary][:max] = [@histogram[:data].max,1].max diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -216,14 +216,37 @@ def multiple_login + #user with multiple IP raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login) last,count = 0,0 - @multiple = [] + first = 0 + @users = [] raw.each do |r| if last != r.user.login count = 1 + last = r.user.login + first = r else - @multiple << r + @users << first if count == 1 + @users << r + count += 1 + end + end + + #IP with multiple user + raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address) + last,count = 0,0 + first = 0 + @ip = [] + raw.each do |r| + if last != r.ip_address + count = 1 + last = r.ip_address + first = r + else + @ip << first if count == 1 + @ip << r + count += 1 end end end diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -84,11 +84,16 @@ added_random_password = true end - user = User.new({:login => login, - :full_name => full_name, - :password => password, - :password_confirmation => password, - :alias => user_alias}) + user = User.find_by_login(login) + if user + user.password = password + else + user = User.new({:login => login, + :full_name => full_name, + :password => password, + :password_confirmation => password, + :alias => user_alias}) + end user.activated = true user.save diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -13,7 +13,7 @@ append_to menu_items, '[Problems]', 'problems', 'index' append_to menu_items, '[Users]', 'user_admin', 'index' append_to menu_items, '[Results]', 'user_admin', 'user_stat' - append_to menu_items, '[Report]', 'report', 'login_stat' + append_to menu_items, '[Report]', 'report', 'multiple_login' append_to menu_items, '[Graders]', 'graders', 'list' append_to menu_items, '[Contests]', 'contest_management', 'index' append_to menu_items, '[Sites]', 'sites', 'index' diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -67,11 +67,11 @@ user = find_by_login(login) if user return user if user.authenticated?(password) - if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password) - user.password = password - user.save - return user - end +# if user.authenticated_by_cucas?(password) or user.authenticated_by_pop3?(password) +# user.password = password +# user.save +# return user +# end end end diff --git a/app/views/problems/stat.html.haml b/app/views/problems/stat.html.haml --- a/app/views/problems/stat.html.haml +++ b/app/views/problems/stat.html.haml @@ -34,6 +34,7 @@ %th Submitted_at %th Points %th comment + %th IP %tbody - row_odd,curr = true,'' - @submissions.each do |sub| @@ -46,6 +47,7 @@ %td= time_ago_in_words(sub.submitted_at) + " ago" %td= sub.points %td.fix-width= sub.grader_comment + %td= sub.ip_address - else No submission diff --git a/app/views/report/multiple_login.html.haml b/app/views/report/multiple_login.html.haml --- a/app/views/report/multiple_login.html.haml +++ b/app/views/report/multiple_login.html.haml @@ -6,6 +6,9 @@ =render partial: 'report_menu' +Checking for all submissions with the currently available problem + +%h2 Users with Multiple IP %table.tablesorter-cafe#my_table %thead %tr @@ -13,8 +16,22 @@ %th full name %th IP %tbody - - @multiple.each do |l| + - @users.each do |l| %tr{class: cycle('info-even','info-odd')} - %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id] - %td= l[:full_name] + %td= link_to l.user.login, controller: 'users', action: 'profile', id: l[:id] + %td= l.user.full_name %td= l[:ip_address] + +%h2 IP with multiple users +%table.tablesorter-cafe#my_table + %thead + %tr + %th IP + %th login + %th full name + %tbody + - @ip.each do |l| + %tr{class: cycle('info-even','info-odd')} + %td= l[:ip_address] + %td= link_to l.user.login, controller: 'users', action: 'profile', id: l[:id] + %td= l.user.full_name